Changeset 2769 for GTP


Ignore:
Timestamp:
06/18/08 04:08:41 (16 years ago)
Author:
mattausch
Message:
 
Location:
GTP/trunk/App/Demos/Vis/CHC_revisited
Files:
2 added
10 edited

Legend:

Unmodified
Added
Removed
  • GTP/trunk/App/Demos/Vis/CHC_revisited/BinaryLoader.cpp

    r2764 r2769  
    107107                mat->SetTexture(mTextureTable[texId]); 
    108108         
     109        str.read(reinterpret_cast<char *>(&mat->mAlphaTestEnabled), sizeof(bool)); 
    109110 
    110111        // material 
    111         /*char hasMaterial; 
    112         str.read(&hasMaterial, sizeof(char)); 
     112        bool hasMaterial; 
     113        str.read(reinterpret_cast<char *>(&hasMaterial), sizeof(bool)); 
    113114         
    114115        if (hasMaterial) 
    115116        { 
    116                 Color3f amb(0.0f, 0.0f, 0.0f); 
    117                 Color3f dif(0.5f, 0.5f, 0.5f); 
    118                 Color3f spec(0.0f, 0.0f, 0.0f); 
    119                 Color3f emi(0.0f, 0.0f, 0.0f); 
    120  
    121                 float shine = 0; 
    122  
    123                 //str.read(reinterpret_cast<char *>(&amb), sizeof(Color3f)); 
    124                 str.read(reinterpret_cast<char *>(&dif), sizeof(Color3f)); 
    125                 //str.read(reinterpret_cast<char *>(&emi), sizeof(Color3f)); 
    126                 //str.read(reinterpret_cast<char *>(&spec), sizeof(Color3f)); 
    127                 //str.read(reinterpret_cast<char *>(&shine), sizeof(float)); 
    128  
    129                 mat->setAmbientColor(amb); 
    130                 mat->setDiffuseColor(dif); 
    131                 mat->setEmissiveColor(emi); 
    132                 mat->setSpecularColor(spec); 
    133                 mat->setShininess(shine); 
    134  
    135                 app->setMaterial(mat); 
    136         } 
    137  
    138         return app;*/ 
     117                // only write rgb part of the material 
     118                str.read(reinterpret_cast<char *>(&mat->mAmbientColor), sizeof(Vector3)); 
     119                str.read(reinterpret_cast<char *>(&mat->mDiffuseColor), sizeof(Vector3)); 
     120                str.read(reinterpret_cast<char *>(&mat->mSpecularColor), sizeof(Vector3)); 
     121                 
     122                /*RgbColor dum; 
     123                str.read(reinterpret_cast<char *>(&dum), sizeof(RgbColor)); 
     124                str.read(reinterpret_cast<char *>(&dum), sizeof(RgbColor)); 
     125                str.read(reinterpret_cast<char *>(&dum), sizeof(RgbColor)); 
     126                */ 
     127        } 
     128 
    139129        return mat; 
    140130} 
  • GTP/trunk/App/Demos/Vis/CHC_revisited/Material.cpp

    r2767 r2769  
    33#include "Texture.h" 
    44#include "glInterface.h" 
     5#include "RenderState.h" 
    56 
    67 
     
    89{ 
    910 
    10 RgbColor RandomColor(float a, float b) 
     11RgbaColor RandomColor(float a, float b) 
    1112{ 
    12         return RgbColor(a + Random(b), a + Random(b), a + Random(b)); 
     13        return RgbaColor(a + Random(b), a + Random(b), a + Random(b), 1); 
    1314} 
    1415 
     
    1718{ 
    1819        mTexture = NULL; 
     20        mAlphaTestEnabled = false; 
    1921 
    20         mAmbientColor = RgbColor(.2f, .2f, .2f); 
    21         mDiffuseColor = RgbColor(1.0f, 1.0f, 1.0f); 
    22         mSpecularColor = RgbColor(0.0f, 0.0f, 0.0f); 
    23         mSpecularColor = RgbColor(1.0f, 1.0f, 1.0f); 
     22        mAmbientColor = RgbaColor(.2f, .2f, .2f, 1.0f); 
     23        mDiffuseColor = RgbaColor(1.0f, 1.0f, 1.0f, 1.0f); 
     24        //mSpecularColor = RgbaColor(0.0f, 0.0f, 0.0f, 1.0f); 
     25        mSpecularColor = RgbaColor(0.5f, 0.5f, 0.5f, 1.0f); 
    2426} 
    2527 
     
    3840 
    3941 
    40 Material::Material(const RgbColor &color): 
     42Material::Material(const RgbaColor &color): 
    4143mDiffuseColor(color), 
    4244mAmbientColor(color), 
    43 mSpecularColor(0, 0, 0),  
     45mSpecularColor(0, 0, 0, 1),  
    4446mId(0), 
    4547mTexture(NULL) 
     
    6668 
    6769 
    68 void Material::Render() 
     70//void Material::Render(RenderState *state) 
     71void Material::Render(RenderState *state) 
    6972{ 
     73        state->SetState(mTexture != NULL, mAlphaTestEnabled); 
     74 
    7075        if (mTexture) 
    7176                mTexture->Bind(); 
     
    7378                glBindTexture(GL_TEXTURE_2D, 0); 
    7479 
    75 /*      float amb[] = {0.2f, 0.2f, 0.2f, 1.0f}; 
    76         float dif[] = {1.0f, 1.0f, 1.0f, 1.0f}; 
    77         float spec[] = {1.0f, 1.0f, 1.0f, 1.0f}; 
    78  
    79         glMaterialfv(GL_FRONT, GL_AMBIENT, (float *)&amb); 
    80         glMaterialfv(GL_FRONT, GL_DIFFUSE, (float *)&dif); 
    81         glMaterialfv(GL_FRONT, GL_SPECULAR, (float *)&spec); 
    82 */ 
    8380        glMaterialfv(GL_FRONT, GL_AMBIENT, (float *)&mAmbientColor.r); 
    8481        glMaterialfv(GL_FRONT, GL_DIFFUSE, (float *)&mDiffuseColor.r); 
  • GTP/trunk/App/Demos/Vis/CHC_revisited/Material.h

    r2768 r2769  
    77 
    88class Texture; 
     9class RenderState; 
    910 
    10 class RgbColor  
     11 
     12class RgbaColor  
    1113{ 
    1214 
    1315public: 
    1416 
    15   float r, g, b; 
     17        float r, g, b, a; 
    1618 
    17   RgbColor(): r(0.5f), g(0.5f), b(0.5f) 
    18   { 
    19   } 
     19        RgbaColor(): r(1), g(1), b(1), a(1) 
     20        {} 
    2021 
    21   RgbColor(float _r, float _g, float _b): r(_r), g(_g), b(_b) 
    22   { 
    23   } 
     22        RgbaColor(float _r, float _g, float _b, float _a): r(_r), g(_g), b(_b), a(_a) 
     23        {} 
    2424 
    25   friend RgbColor 
    26   RandomColor(float a = 0.0f, float b = 1.0f); 
    27  
    28   // Mapping from interval 0.0-1.0 to RGB using "rainbow" color map 
    29   // (range of hue from 0-240) 
    30  
    31   friend RgbColor RainbowColorMapping(float value); 
    32    
     25        friend RgbaColor RandomColor(float a = 0.0f, float b = 1.0f); 
    3326}; 
    3427 
    3528 
    3629// Forward declarations 
    37 RgbColor RandomColor(const float a, const float b); 
     30RgbaColor RandomColor(float a, float b); 
    3831 
    39 // Mapping from interval 0.0-1.0 to RGB using "rainbow" color map 
    40 // (range of hue from 0-240) 
    41 RgbColor RainbowColorMapping(const float value); 
    4232 
    43    
    4433 
    4534class Material  
     
    4736public: 
    4837 
    49   RgbColor mDiffuseColor; 
    50   RgbColor mSpecularColor; 
    51   RgbColor mAmbientColor; 
    52    
    53   Material(); 
    54    
    55   Material(int id); 
     38        Material(); 
    5639 
    57   Material(const RgbColor &color); 
    58   /** Returns unique material id. 
    59   */ 
    60   int GetId() const; 
     40        Material(int id); 
    6141 
    62   friend Material RandomMaterial(); 
     42        Material(const RgbaColor &color); 
     43        /** Returns unique material id. 
     44        */ 
     45        int GetId() const; 
    6346 
    64   inline Texture *GetTexture() const { return mTexture; } 
     47        friend Material RandomMaterial(); 
    6548 
    66   void SetTexture(Texture *texture) { mTexture = texture; } 
    67   /** Renders this material. 
    68   */ 
    69   void Render(); 
     49        inline Texture *GetTexture() const { return mTexture; } 
     50 
     51        void SetTexture(Texture *texture) { mTexture = texture; } 
     52        /** Renders this material. 
     53        */ 
     54        void Render(RenderState *state); 
     55 
     56 
     57        /////////// 
     58 
     59        RgbaColor mDiffuseColor; 
     60        RgbaColor mSpecularColor; 
     61        RgbaColor mAmbientColor; 
     62 
     63        bool mAlphaTestEnabled; 
    7064 
    7165protected: 
     
    7468        */ 
    7569        void InitMaterial(); 
     70 
     71        //////////////// 
    7672 
    7773        /// unique material id 
  • GTP/trunk/App/Demos/Vis/CHC_revisited/RenderTraverser.cpp

    r2768 r2769  
    44#include "Camera.h" 
    55#include "SceneEntity.h" 
     6#include "RenderState.h" 
    67 
    78 
     
    9798 
    9899 
    99 void RenderTraverser::Switch2GLRenderState() 
    100 { 
    101         // boolean used to avoid unnecessary state changes 
    102         if (mIsQueryMode) 
    103         { 
    104                 // switch back to rendermode             
    105                 glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); 
    106                 glDepthMask(GL_TRUE); 
    107                 glEnable(GL_LIGHTING); 
    108                 mIsQueryMode = false; 
    109         } 
    110 } 
    111  
    112  
    113100OcclusionQuery *RenderTraverser::IssueOcclusionQuery(BvhNode *node, bool wasVisible) 
    114101{ 
     
    130117        {*/ 
    131118 
    132         // change state so the bounding box gets not actually rendered on the screen 
    133         Switch2GLQueryState(); 
     119        // change to query mode 
     120        mRenderState->SetState(RenderState::QUERY); 
    134121        mBvh->RenderBoundingBox(node); 
    135         Switch2GLRenderState(); 
     122        mRenderState->SetState(RenderState::RENDER); 
    136123 
    137124        query->EndQuery(); 
    138125 
    139126        return query; 
    140 } 
    141  
    142  
    143 void RenderTraverser::Switch2GLQueryState() 
    144 {        
    145         // boolean used to avoid unnecessary state changes 
    146         if (!mIsQueryMode) 
    147         { 
    148                 glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); 
    149                 glDepthMask(GL_FALSE); 
    150                 glDisable(GL_LIGHTING); 
    151                 mIsQueryMode = true; 
    152         } 
    153127} 
    154128 
     
    189163        mStats.Reset(); 
    190164        mQueryHandler.ResetQueries(); 
    191         mRenderState->mTexturesEnabled = false; 
     165         
    192166        EnqueueNode(mBvh->GetRoot()); 
    193167 
     
    201175        glDisableClientState(GL_NORMAL_ARRAY); 
    202176 
    203         glDisable(GL_TEXTURE_2D); 
    204         glDisableClientState(GL_TEXTURE_COORD_ARRAY); 
    205          
     177        mRenderState->Reset(); 
     178 
    206179        t2 = GetTime(); 
    207180        mStats.mRenderTime = TimeDiff(t1, t2); 
  • GTP/trunk/App/Demos/Vis/CHC_revisited/RenderTraverser.h

    r2767 r2769  
    9696        */ 
    9797        OcclusionQuery *IssueOcclusionQuery(BvhNode *node, bool wasVisible); 
    98         /** switches to normal render mode 
    99         */ 
    100         void Switch2GLRenderState(); 
    101         /** switches to occlusion query mode (geometry not rendered on the screen) 
    102         */ 
    103         void Switch2GLQueryState(); 
    10498        /** Retunrs true if the current bvh node intersects the near plane. 
    10599        */ 
  • GTP/trunk/App/Demos/Vis/CHC_revisited/SceneEntity.cpp

    r2766 r2769  
    33#include "Geometry.h" 
    44#include "Material.h" 
     5#include "RenderState.h" 
    56 
    67 
     
    1920void SceneEntity::Render(RenderState *state) 
    2021{ 
    21         if (!state->mTexturesEnabled && mGeometry->HasTexture()) 
    22         { 
    23                 glEnable(GL_TEXTURE_2D); 
    24                 glEnableClientState(GL_TEXTURE_COORD_ARRAY); 
    25                 state->mTexturesEnabled = true; 
    26         } 
    27         else if (state->mTexturesEnabled && !mGeometry->HasTexture()) 
    28         { 
    29                 glDisable(GL_TEXTURE_2D); 
    30                 glDisableClientState(GL_TEXTURE_COORD_ARRAY); 
    31                 state->mTexturesEnabled = false; 
    32         } 
    33  
    34         if (mMaterial) mMaterial->Render(); 
     22        if (mMaterial) mMaterial->Render(state); 
    3523 
    3624        if (mTransform) 
  • GTP/trunk/App/Demos/Vis/CHC_revisited/SceneEntity.h

    r2768 r2769  
    1313class Geometry; 
    1414class RenderState; 
    15  
    16 /** The current render state. 
    17 */ 
    18 class RenderState 
    19 { 
    20 public: 
    21         bool mTexturesEnabled; 
    22 }; 
    2315 
    2416 
  • GTP/trunk/App/Demos/Vis/CHC_revisited/Texture.cpp

    r2768 r2769  
    3333{ 
    3434        startil(); 
    35         string dummy=filename; 
    36           
    37         string::size_type posOfSpace = filename.find("bmp"); 
    38  
    39   if (posOfSpace < filename.size())  
    40                 dummy=string("../textures/trees/bark8.png"); 
    41  
    42         if (!ilLoadImage(ILstring(dummy.c_str()))) 
     35         
     36        if (!ilLoadImage(ILstring(filename.c_str()))) 
    4337        { 
    44                 cerr << "Image load error " << ilGetError() << ": " << dummy << endl; 
     38                cerr << "Image load error " << ilGetError() << ": " << filename << endl; 
    4539        } 
    4640        else 
     
    7569         
    7670        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 
    77         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_LINEAR); 
     71        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); 
    7872 
    7973        //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 
     
    8377        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); 
    8478 
    85         gluBuild2DMipmaps(GL_TEXTURE_2D, 3, mWidth, mHeight, GL_RGBA, GL_UNSIGNED_BYTE, mImage); 
    86         //glTexImage2D(GL_TEXTURE_2D, 0, 3, mWidth, mHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, mImage); 
     79        gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGBA, mWidth, mHeight, GL_RGBA, GL_UNSIGNED_BYTE, mImage); 
     80        //glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, mWidth, mHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, mImage); 
    8781} 
    8882 
  • GTP/trunk/App/Demos/Vis/CHC_revisited/chc_revisited.vcproj

    r2768 r2769  
    354354                                </File> 
    355355                                <File 
     356                                        RelativePath=".\RenderState.h" 
     357                                        > 
     358                                </File> 
     359                                <File 
    356360                                        RelativePath=".\SceneEntity.h" 
    357361                                        > 
     
    400404                                </File> 
    401405                                <File 
     406                                        RelativePath=".\RenderState.cpp" 
     407                                        > 
     408                                </File> 
     409                                <File 
    402410                                        RelativePath=".\SceneEntity.cpp" 
    403411                                        > 
  • GTP/trunk/App/Demos/Vis/CHC_revisited/chcdemo.cpp

    r2768 r2769  
    1919#include "CHCPlusPlusTraverser.h" 
    2020#include "Visualization.h" 
    21  
     21#include "RenderState.h" 
    2222 
    2323 
     
    8080void SetupLighting(); 
    8181void DisplayStats(); 
     82void Output(int x, int y, const char *string); 
    8283 
    8384void begin2D(); 
    8485void end2D(); 
    85 void output(int x, int y, const char *string); 
    8686void keyboard(unsigned char c, int x, int y); 
    8787void drawHelpMessage(); 
     
    180180                 
    181181        //glEnable(GL_ALPHA_TEST); 
    182         //glAlphaFunc(GL_GEQUAL, 0.01); 
    183  
    184182        glDisable(GL_ALPHA_TEST); 
     183        glAlphaFunc(GL_GEQUAL, 0.1f); 
    185184 
    186185        glFrontFace(GL_CCW); 
     
    263262                else  
    264263                { 
    265                         output(x, y, message[i]); 
     264                        Output(x, y, message[i]); 
    266265                        y += 14; 
    267266                } 
     
    734733 
    735734 
    736 void output(const int x, const int y, const char *string)  
     735void Output(int x, int y, const char *string)  
    737736{ 
    738737        if (string != 0)  
     
    744743                for (i = 0; i < len; ++ i)  
    745744                { 
    746                         glutBitmapCharacter(GLUT_BITMAP_8_BY_13, string[i]); 
     745                        glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18, string[i]); 
    747746                } 
    748747        } 
     
    841840        char msg3[200]; 
    842841        char msg4[200]; 
     842        char msg5[200]; 
    843843 
    844844 
     
    856856        renderTime = traverser->GetStats().mRenderTime * expFactor + (1.0f - expFactor) * renderTime; 
    857857 
    858         if (renderTime) fps /= (float)renderTime; 
    859  
    860         sprintf_s(msg3, "Threshold: %4d, render time: %ld ms (%3.3f fps), issued queries: %d%s",  
    861                 traverser->GetVisibilityThreshold(), renderTime, fps, traverser->GetStats().mNumIssuedQueries, optstr[useOptimization]); 
     858        if (renderTime) fps = 1e3f / (float)renderTime; 
     859 
     860        sprintf_s(msg2, "threshold: %4d%s",  
     861                traverser->GetVisibilityThreshold(), optstr[useOptimization]); 
    862862 
    863863        string str; 
     
    868868        CalcDecimalPoint(str2, traverser->GetStats().mNumRenderedTriangles); 
    869869 
    870         sprintf_s(msg4, "rendered objects %5d (of %5d), rendered triangles: %s (of %s)",  
     870        sprintf_s(msg3, "rendered objects: %6d (of %6d), rendered triangles: %s (of %s)",  
    871871                          traverser->GetStats().mNumRenderedGeometry, sceneEntities.size(), str.c_str(), str2.c_str());  
     872 
     873        sprintf_s(msg4, "issued queries: %5d", traverser->GetStats().mNumIssuedQueries); 
     874 
     875        sprintf_s(msg5, "fps: %6.1f", fps); 
    872876 
    873877 
     
    880884        else 
    881885        { 
    882                 glColor3f(1.0f, 1.0f , 1.0f); 
    883                 output(10, winHeight - 10, msg[renderMode]); 
     886                glColor3f(1.0f, 1.0f, 1.0f); 
     887                 
     888                Output(800, 30, msg[renderMode]); 
    884889 
    885890                if(showStatistics) 
    886891                { 
    887                         output(20, winHeight - 70, msg3); 
    888                         output(20, winHeight - 50, msg4); 
    889                         output(20, winHeight - 30, msg2); 
     892                        Output(20, 30, msg2); 
     893                        Output(20, 60, msg3); 
     894                        Output(20, 90, msg4); 
     895                        Output(20, 120, msg5); 
    890896                } 
    891897        } 
Note: See TracChangeset for help on using the changeset viewer.