Changeset 2827 for GTP/trunk/App
- Timestamp:
- 07/10/08 00:12:58 (16 years ago)
- Location:
- GTP/trunk/App/Demos/Vis/FriendlyCulling
- Files:
-
- 2 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/FriendlyCulling/FriendlyCulling.vcproj
r2826 r2827 252 252 </File> 253 253 <File 254 RelativePath=".\src\PerformanceGraph.cpp" 255 > 256 </File> 257 <File 258 RelativePath=".\src\PerformanceGraph.h" 259 > 260 </File> 261 <File 254 262 RelativePath=".\src\Plane3.cpp" 255 263 > -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp
r2826 r2827 27 27 #include <Cg/cgGL.h> 28 28 #include "glfont2.h" 29 29 #include "PerformanceGraph.h" 30 30 31 31 … … 157 157 int renderType = RenderState::FIXED; 158 158 159 PerformanceGraph *perfGraph = NULL; 160 159 161 160 162 #define NUM_SAMPLES 8 … … 318 320 MiddleMotion(0, 0); 319 321 322 perfGraph = new PerformanceGraph(500); 320 323 321 324 loader = new ResourceManager(); … … 653 656 654 657 655 bool Initfont(void) 656 { 657 //Initialize OpenGL 658 //Texture mapping and blending must be enabled for glFont to work 659 glClearColor(0.0, 0.0, 0.0, 1.0); 658 bool InitFont(void) 659 { 660 660 glEnable(GL_TEXTURE_2D); 661 glEnable(GL_BLEND);662 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);663 661 664 662 glGenTextures(1, &fontTex); 665 663 glBindTexture(GL_TEXTURE_2D, fontTex); 666 if (!myfont.Create(" myfont.glf", fontTex))664 if (!myfont.Create("data/fonts/myfont.glf", fontTex)) 667 665 return false; 668 666 669 667 glDisable(GL_TEXTURE_2D); 670 //Return successfully668 671 669 return true; 672 670 } … … 711 709 glDepthFunc(GL_LESS); 712 710 713 if (!Init font())711 if (!InitFont()) 714 712 cerr << "font creation failed" << endl; 715 713 else … … 718 716 719 717 720 void DrawFont() 721 { 722 float top_color[3] = {1.0F, 1.0F, 1.0F}; 723 float bottom_color[3] = {0.0F, 0.0F, 1.0F}; 724 725 glEnable(GL_TEXTURE_2D); 726 glEnable(GL_BLEND); 727 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 728 729 730 //Clear back buffer 731 glClear(GL_DEPTH_BUFFER_BIT); 732 733 //Draw some stuff 734 glMatrixMode(GL_MODELVIEW); 735 glPushMatrix(); 736 glLoadIdentity(); 737 738 //Draw a string 739 glColor3f(1.0F, 1.0F, 1.0F); 740 myfont.Begin(); 741 myfont.DrawString("Hello World!", 1.0F, 0.0F, 480.0F); 742 /*myfont.DrawString(L"Hello World!", 2.0F, 0.0F, 743 400.0F, top_color, bottom_color); 744 myfont.DrawString(std::string("Hello World!"), 0.0F, 320.0F); 745 myfont.DrawString(std::wstring(L"Hello World!"), 0.0F, 280.F, 746 top_color, bottom_color); 747 glTranslatef(0.0F, 200.F, 0.0F); 748 glRotatef(15.0F, 0.0F, 0.0F, 1.0F); 749 myfont.DrawString("Hello World!", 2.0F, 0.0F, 0.F, 750 top_color, bottom_color); 751 */ 752 glPopMatrix(); 753 754 glDisable(GL_BLEND); 755 glDisable(GL_TEXTURE_2D); 756 } 757 758 759 void DrawHelpMessage(void) 718 void DrawHelpMessage() 760 719 { 761 720 const char *message[] = … … 766 725 "'F2' - shows/hides bird eye view", 767 726 "'F3' - shows/hides bounds (boxes or tight bounds)", 768 "'F4' - shows/hides statistics",769 "'F5' , - shows/hides parameters",770 "'F6', - toggles between fly /walkmode",727 "'F4', - shows/hides parameters", 728 "'F5' - shows/hides statistics", 729 "'F6', - toggles between fly/walkmode", 771 730 "'F7', - cycles throw render modes", 772 731 "'F8', - enables/disables ambient occlusion (only deferred)", … … 774 733 "'SPACE' - cycles through occlusion culling algorithms", 775 734 "", 776 "'MOUSE-LEFT' - turn left/right, move forward/backward", 777 "'MOUSE-RIGHT' - turn left/right, move forward/backward", 778 "'MOUSE-MIDDLE' - move up/down, left/right", 779 "'CURSOR UP' - move forward", 780 "'CURSOR BACK' - move backward", 781 "'CURSOR RIGHT' - turn right", 782 "'CURSOR LEFT' - turn left", 735 "'MOUSE LEFT' - turn left/right, move forward/backward", 736 "'MOUSE RIGHT' - turn left/right, move forward/backward", 737 "'MOUSE MIDDLE' - move up/down, left/right", 738 "'CURSOR UP/DOWN' - move forward/backward", 739 "'CURSOR LEFT/RIGHT' - turn left/right", 783 740 "", 784 "'-' - decreases max batch size", 785 "'+' - increases max batch size", 786 "'4' - decrease triangles per virtual leaf (sets depth of bvh)", 787 "'5' - increase triangles per virtual leaf (sets depth of bvh)", 788 "'6' - decrease assumed visible frames", 789 "'7' - increase assumed visible frames", 790 "'8' - downward motion", 791 "'9' - upward motion", 741 "'-'/'+' - decreases/increases max batch size", 742 "'4'/'5' - decreases/increases triangles per virtual bvh leaf (sets bvh depth)", 743 "'6'/'7' - decreases/increases assumed visible frames", 744 "'8'/'9' - downward/upward motion", 792 745 "", 793 746 "'R' - use render queue", … … 799 752 800 753 801 int x = 40, y = 60; 802 803 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 804 glEnable(GL_BLEND); 805 glColor4f(0.0f, 1.0f , 0.0f, 0.2f); // 20% green. 806 807 // Drawn clockwise because the flipped Y axis flips CCW and CW. 808 glRecti(winWidth - 30, 30, 30, winHeight - 30); 809 810 glDisable(GL_BLEND); 811 754 glColor4f(0.0f, 1.0f , 0.0f, 0.2f); // 20% green. 755 756 glRecti(30, 30, winWidth - 30, winHeight - 30); 757 758 glEnd(); 759 812 760 glColor3f(1.0f, 1.0f, 1.0f); 813 761 814 for(int i = 0; message[i] != 0; i++) 762 myfont.Begin(); 763 764 int x = 40, y = 30; 765 766 for(int i = 0; message[i] != 0; ++ i) 815 767 { 816 768 if(message[i][0] == '\0') … … 820 772 else 821 773 { 822 Output(x, y, message[i]);823 y += 2 0;774 myfont.DrawString(message[i], x, winHeight - y); 775 y += 25; 824 776 } 825 777 } … … 874 826 glEnable(GL_LIGHT1); 875 827 876 //GLfloat ambient[] = {0.5, 0.5, 0.5, 1.0};877 828 GLfloat ambient[] = {0.2, 0.2, 0.2, 1.0}; 878 829 GLfloat diffuse[] = {1.0, 1.0, 1.0, 1.0}; 879 830 GLfloat specular[] = {1.0, 1.0, 1.0, 1.0}; 880 831 881 //GLfloat lmodel_ambient[] = {0.5f, 0.5f, 0.5f, 1.0f};882 832 GLfloat lmodel_ambient[] = {0.3f, 0.3f, 0.3f, 1.0f}; 883 833 … … 1103 1053 } 1104 1054 1055 1056 /////////// 1057 1058 state.SetRenderType(RenderState::FIXED); 1059 1105 1060 if (showAlgorithmTime) 1106 1061 { 1107 1062 glFinish(); 1063 1108 1064 algTime = algTimer.Elapsedms(); 1109 }1110 1111 ///////////1112 1113 state.SetRenderType(RenderState::FIXED);1114 1115 if (visMode) DisplayVisualization();1065 perfGraph->AddData(algTime); 1066 perfGraph->Draw(); 1067 } 1068 else 1069 { 1070 if (visMode) DisplayVisualization(); 1071 } 1116 1072 1117 1073 DisplayStats(); … … 1293 1249 break; 1294 1250 case GLUT_KEY_F4: 1251 showOptions = !showOptions; 1252 break; 1253 case GLUT_KEY_F5: 1295 1254 showStatistics = !showStatistics; 1296 break;1297 case GLUT_KEY_F5:1298 showOptions = !showOptions;1299 1255 break; 1300 1256 case GLUT_KEY_F6: … … 1491 1447 gluOrtho2D(0, winWidth, 0, winHeight); 1492 1448 1449 int w = winWidth / 2; 1450 int h = winHeight / 2; 1451 1452 //glOrtho(-w, w, -h, h, 0, 10); 1453 1493 1454 glMatrixMode(GL_MODELVIEW); 1494 1455 glPushMatrix(); … … 1508 1469 1509 1470 1510 void Output(int x, int y, const char *string)1511 {1512 if (string != 0)1513 {1514 size_t len, i;1515 glRasterPos2f(x, y);1516 len = strlen(string);1517 1518 for (i = 0; i < len; ++ i)1519 {1520 glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18, string[i]);1521 }1522 }1523 }1524 1525 1526 1471 // displays the visualisation of culling algorithm 1527 1472 void DisplayVisualization() … … 1532 1477 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 1533 1478 glEnable(GL_BLEND); 1534 glColor4f(0.0 ,0.0,0.0,0.5);1535 1536 glRecti(winWidth , 0, winWidth - winWidth / 3, winHeight / 3);1479 glColor4f(0.0f ,0.0f, 0.0f, 0.5f); 1480 1481 glRecti(winWidth - winWidth / 3, winHeight - winHeight / 3, winWidth, winHeight); 1537 1482 glDisable(GL_BLEND); 1538 1483 End2D(); … … 1599 1544 DEL_PTR(loader); 1600 1545 DEL_PTR(renderQueue); 1546 DEL_PTR(perfGraph); 1601 1547 1602 1548 if (sCgMrtVertexProgram) 1603 1549 cgDestroyProgram(sCgMrtVertexProgram); 1550 if (RenderState::sCgMrtFragmentProgram) 1551 cgDestroyProgram(RenderState::sCgMrtFragmentProgram); 1552 if (RenderState::sCgMrtFragmentTexProgram) 1553 cgDestroyProgram(RenderState::sCgMrtFragmentTexProgram); 1604 1554 if (sCgSsaoProgram) 1605 1555 cgDestroyProgram(sCgSsaoProgram); … … 1619 1569 glDeleteTextures(1, &positionsTex); 1620 1570 glDeleteTextures(1, &noiseTex); 1571 glDeleteTextures(1, &fontTex); 1621 1572 } 1622 1573 … … 1625 1576 void CalcDecimalPoint(string &str, int d) 1626 1577 { 1627 vector<int> numbers; 1578 static vector<int> numbers; 1579 numbers.clear(); 1580 1628 1581 char hstr[100]; 1629 1582 … … 1700 1653 1701 1654 1702 1703 glClear(GL_DEPTH_BUFFER_BIT);1704 //Draw a string1705 glColor3f(1.0f, 1.0f, 1.0f);1706 myfont.Begin();1707 1708 1655 //DrawFont(); 1709 1656 if (showHelp) … … 1713 1660 else 1714 1661 { 1715 glColor3f(1.0f, 0.5f, 0.5f); 1662 myfont.Begin(); 1663 1664 glColor3f(0.0f, 1.0f, 0.0f); 1716 1665 1717 1666 if (showOptions) … … 1732 1681 1733 1682 for (int j = 0; j < 4; ++ j) 1734 myfont.DrawString(msg[j], 1.0F,20.0f, 760 - j * 30);1683 myfont.DrawString(msg[j], 20.0f, 760 - j * 30); 1735 1684 } 1736 1685 1737 glColor3f(0. 5f, 1.0f, 0.5f);1686 glColor3f(0.0f, 1.0f, 1.0f); 1738 1687 1739 1688 if (showStatistics) … … 1757 1706 1758 1707 for (int j = 4; j < 7; ++ j) 1759 myfont.DrawString(msg[j], 1.0F,20.0f, 760 - j * 30);1708 myfont.DrawString(msg[j], 20.0f, 760 - j * 30); 1760 1709 } 1761 1762 //glTranslatef(200, 200, 0);1763 //glScalef(1, -1, 1);1764 1710 1765 1711 glColor3f(1.0f, 1.0f, 1.0f); 1766 1712 static char *alg_str[] = {"Frustum Cull", "Stop and Wait", "CHC", "CHC ++"}; 1767 sprintf(msg[7], "%s: %6.1f fps", alg_str[renderMode], fps); 1768 1769 myfont.DrawString(msg[7], 1.0F, 720.0F, 760.0F);//, top_color, bottom_color); 1770 1771 //glDisable(GL_CULL_FACE); 1772 //Output(780, 30, msg[7]); 1773 1774 if (showAlgorithmTime) 1775 { 1776 //sprintf(msg[8], "algorithm time: %6.1f ms", rTime); 1777 //Output(780, 60, msg[8]); 1778 } 1713 1714 if (!showAlgorithmTime) 1715 { 1716 sprintf(msg[7], "%s: %6.1f fps", alg_str[renderMode], fps); 1717 } 1718 else 1719 { 1720 sprintf(msg[7], "%s: %6.1f ms", alg_str[renderMode], rTime); 1721 } 1722 1723 myfont.DrawString(msg[7], 720.0f, 760.0f);//, top_color, bottom_color); 1724 1725 //sprintf(msg[8], "algorithm time: %6.1f ms", rTime); 1726 //myfont.DrawString(msg[8], 720.0f, 730.0f); 1779 1727 } 1780 1728
Note: See TracChangeset
for help on using the changeset viewer.