Changeset 2827


Ignore:
Timestamp:
07/10/08 00:12:58 (16 years ago)
Author:
mattausch
Message:
 
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  
    252252                        </File> 
    253253                        <File 
     254                                RelativePath=".\src\PerformanceGraph.cpp" 
     255                                > 
     256                        </File> 
     257                        <File 
     258                                RelativePath=".\src\PerformanceGraph.h" 
     259                                > 
     260                        </File> 
     261                        <File 
    254262                                RelativePath=".\src\Plane3.cpp" 
    255263                                > 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp

    r2826 r2827  
    2727#include <Cg/cgGL.h> 
    2828#include "glfont2.h" 
    29  
     29#include "PerformanceGraph.h" 
    3030 
    3131 
     
    157157int renderType = RenderState::FIXED; 
    158158 
     159PerformanceGraph *perfGraph = NULL; 
     160 
    159161 
    160162#define NUM_SAMPLES 8 
     
    318320        MiddleMotion(0, 0); 
    319321 
     322        perfGraph = new PerformanceGraph(500); 
    320323 
    321324        loader = new ResourceManager(); 
     
    653656 
    654657 
    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);        
     658bool InitFont(void) 
     659{ 
    660660        glEnable(GL_TEXTURE_2D); 
    661         glEnable(GL_BLEND); 
    662         glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 
    663661 
    664662        glGenTextures(1, &fontTex); 
    665663        glBindTexture(GL_TEXTURE_2D, fontTex); 
    666         if (!myfont.Create("myfont.glf", fontTex)) 
     664        if (!myfont.Create("data/fonts/myfont.glf", fontTex)) 
    667665                return false; 
    668666 
    669667        glDisable(GL_TEXTURE_2D); 
    670         //Return successfully 
     668         
    671669        return true; 
    672670} 
     
    711709        glDepthFunc(GL_LESS); 
    712710 
    713         if (!Initfont()) 
     711        if (!InitFont()) 
    714712                cerr << "font creation failed" << endl; 
    715713        else 
     
    718716 
    719717 
    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)  
     718void DrawHelpMessage()  
    760719{ 
    761720        const char *message[] =  
     
    766725                "'F2'           - shows/hides bird eye view", 
    767726                "'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", 
    771730                "'F7',          - cycles throw render modes", 
    772731                "'F8',          - enables/disables ambient occlusion (only deferred)", 
     
    774733                "'SPACE'        - cycles through occlusion culling algorithms", 
    775734                "", 
    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", 
    783740                "", 
    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", 
    792745                "", 
    793746                "'R'            - use render queue", 
     
    799752         
    800753         
    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 
    812760        glColor3f(1.0f, 1.0f, 1.0f); 
    813761         
    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)  
    815767        { 
    816768                if(message[i][0] == '\0')  
     
    820772                else  
    821773                { 
    822                         Output(x, y, message[i]); 
    823                         y += 20; 
     774                        myfont.DrawString(message[i], x, winHeight - y); 
     775                        y += 25; 
    824776                } 
    825777        } 
     
    874826        glEnable(GL_LIGHT1); 
    875827         
    876         //GLfloat ambient[] = {0.5, 0.5, 0.5, 1.0}; 
    877828        GLfloat ambient[] = {0.2, 0.2, 0.2, 1.0}; 
    878829        GLfloat diffuse[] = {1.0, 1.0, 1.0, 1.0}; 
    879830        GLfloat specular[] = {1.0, 1.0, 1.0, 1.0}; 
    880831             
    881         //GLfloat lmodel_ambient[] = {0.5f, 0.5f, 0.5f, 1.0f}; 
    882832        GLfloat lmodel_ambient[] = {0.3f, 0.3f, 0.3f, 1.0f}; 
    883833 
     
    11031053        } 
    11041054 
     1055         
     1056        /////////// 
     1057 
     1058        state.SetRenderType(RenderState::FIXED); 
     1059 
    11051060        if (showAlgorithmTime) 
    11061061        { 
    11071062                glFinish(); 
     1063 
    11081064                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        } 
    11161072 
    11171073        DisplayStats(); 
     
    12931249                break; 
    12941250        case GLUT_KEY_F4: 
     1251                showOptions = !showOptions; 
     1252                break; 
     1253        case GLUT_KEY_F5: 
    12951254                showStatistics = !showStatistics; 
    1296                 break; 
    1297         case GLUT_KEY_F5: 
    1298                 showOptions = !showOptions; 
    12991255                break; 
    13001256        case GLUT_KEY_F6: 
     
    14911447        gluOrtho2D(0, winWidth, 0, winHeight); 
    14921448 
     1449        int w = winWidth / 2; 
     1450        int h = winHeight / 2; 
     1451         
     1452        //glOrtho(-w, w, -h, h, 0, 10); 
     1453 
    14931454        glMatrixMode(GL_MODELVIEW); 
    14941455        glPushMatrix(); 
     
    15081469 
    15091470 
    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  
    15261471// displays the visualisation of culling algorithm 
    15271472void DisplayVisualization() 
     
    15321477        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 
    15331478        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); 
    15371482        glDisable(GL_BLEND); 
    15381483        End2D(); 
     
    15991544        DEL_PTR(loader); 
    16001545        DEL_PTR(renderQueue); 
     1546        DEL_PTR(perfGraph); 
    16011547 
    16021548        if (sCgMrtVertexProgram) 
    16031549                cgDestroyProgram(sCgMrtVertexProgram); 
     1550        if (RenderState::sCgMrtFragmentProgram) 
     1551                cgDestroyProgram(RenderState::sCgMrtFragmentProgram); 
     1552        if (RenderState::sCgMrtFragmentTexProgram) 
     1553                cgDestroyProgram(RenderState::sCgMrtFragmentTexProgram); 
    16041554        if (sCgSsaoProgram) 
    16051555                cgDestroyProgram(sCgSsaoProgram); 
     
    16191569        glDeleteTextures(1, &positionsTex); 
    16201570        glDeleteTextures(1, &noiseTex); 
     1571        glDeleteTextures(1, &fontTex); 
    16211572} 
    16221573 
     
    16251576void CalcDecimalPoint(string &str, int d) 
    16261577{ 
    1627         vector<int> numbers; 
     1578        static vector<int> numbers; 
     1579        numbers.clear(); 
     1580 
    16281581        char hstr[100]; 
    16291582 
     
    17001653 
    17011654 
    1702  
    1703         glClear(GL_DEPTH_BUFFER_BIT); 
    1704         //Draw a string 
    1705         glColor3f(1.0f, 1.0f, 1.0f); 
    1706         myfont.Begin(); 
    1707  
    17081655        //DrawFont(); 
    17091656        if (showHelp) 
     
    17131660        else 
    17141661        { 
    1715                 glColor3f(1.0f, 0.5f, 0.5f); 
     1662                myfont.Begin(); 
     1663 
     1664                glColor3f(0.0f, 1.0f, 0.0f); 
    17161665 
    17171666                if (showOptions) 
     
    17321681 
    17331682                        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); 
    17351684                } 
    17361685 
    1737                 glColor3f(0.5f, 1.0f, 0.5f); 
     1686                glColor3f(0.0f, 1.0f, 1.0f); 
    17381687 
    17391688                if (showStatistics) 
     
    17571706 
    17581707                        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); 
    17601709                } 
    1761  
    1762                 //glTranslatef(200, 200, 0); 
    1763                 //glScalef(1, -1, 1); 
    17641710 
    17651711                glColor3f(1.0f, 1.0f, 1.0f); 
    17661712                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);             
    17791727        } 
    17801728 
Note: See TracChangeset for help on using the changeset viewer.