Changeset 2769 for GTP/trunk/App/Demos
- Timestamp:
- 06/18/08 04:08:41 (17 years ago)
- 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 107 107 mat->SetTexture(mTextureTable[texId]); 108 108 109 str.read(reinterpret_cast<char *>(&mat->mAlphaTestEnabled), sizeof(bool)); 109 110 110 111 // material 111 /*charhasMaterial;112 str.read( &hasMaterial, sizeof(char));112 bool hasMaterial; 113 str.read(reinterpret_cast<char *>(&hasMaterial), sizeof(bool)); 113 114 114 115 if (hasMaterial) 115 116 { 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 139 129 return mat; 140 130 } -
GTP/trunk/App/Demos/Vis/CHC_revisited/Material.cpp
r2767 r2769 3 3 #include "Texture.h" 4 4 #include "glInterface.h" 5 #include "RenderState.h" 5 6 6 7 … … 8 9 { 9 10 10 Rgb Color RandomColor(float a, float b)11 RgbaColor RandomColor(float a, float b) 11 12 { 12 return Rgb Color(a + Random(b), a + Random(b), a + Random(b));13 return RgbaColor(a + Random(b), a + Random(b), a + Random(b), 1); 13 14 } 14 15 … … 17 18 { 18 19 mTexture = NULL; 20 mAlphaTestEnabled = false; 19 21 20 mAmbientColor = Rgb Color(.2f, .2f, .2f);21 mDiffuseColor = Rgb Color(1.0f, 1.0f, 1.0f);22 mSpecularColor = RgbColor(0.0f, 0.0f, 0.0f);23 mSpecularColor = Rgb Color(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); 24 26 } 25 27 … … 38 40 39 41 40 Material::Material(const Rgb Color &color):42 Material::Material(const RgbaColor &color): 41 43 mDiffuseColor(color), 42 44 mAmbientColor(color), 43 mSpecularColor(0, 0, 0 ),45 mSpecularColor(0, 0, 0, 1), 44 46 mId(0), 45 47 mTexture(NULL) … … 66 68 67 69 68 void Material::Render() 70 //void Material::Render(RenderState *state) 71 void Material::Render(RenderState *state) 69 72 { 73 state->SetState(mTexture != NULL, mAlphaTestEnabled); 74 70 75 if (mTexture) 71 76 mTexture->Bind(); … … 73 78 glBindTexture(GL_TEXTURE_2D, 0); 74 79 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 */83 80 glMaterialfv(GL_FRONT, GL_AMBIENT, (float *)&mAmbientColor.r); 84 81 glMaterialfv(GL_FRONT, GL_DIFFUSE, (float *)&mDiffuseColor.r); -
GTP/trunk/App/Demos/Vis/CHC_revisited/Material.h
r2768 r2769 7 7 8 8 class Texture; 9 class RenderState; 9 10 10 class RgbColor 11 12 class RgbaColor 11 13 { 12 14 13 15 public: 14 16 15 float r, g, b;17 float r, g, b, a; 16 18 17 RgbColor(): r(0.5f), g(0.5f), b(0.5f) 18 { 19 } 19 RgbaColor(): r(1), g(1), b(1), a(1) 20 {} 20 21 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 {} 24 24 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); 33 26 }; 34 27 35 28 36 29 // Forward declarations 37 Rgb Color RandomColor(const float a, constfloat b);30 RgbaColor RandomColor(float a, float b); 38 31 39 // Mapping from interval 0.0-1.0 to RGB using "rainbow" color map40 // (range of hue from 0-240)41 RgbColor RainbowColorMapping(const float value);42 32 43 44 33 45 34 class Material … … 47 36 public: 48 37 49 RgbColor mDiffuseColor; 50 RgbColor mSpecularColor; 51 RgbColor mAmbientColor; 52 53 Material(); 54 55 Material(int id); 38 Material(); 56 39 57 Material(const RgbColor &color); 58 /** Returns unique material id. 59 */ 60 int GetId() const; 40 Material(int id); 61 41 62 friend Material RandomMaterial(); 42 Material(const RgbaColor &color); 43 /** Returns unique material id. 44 */ 45 int GetId() const; 63 46 64 inline Texture *GetTexture() const { return mTexture; } 47 friend Material RandomMaterial(); 65 48 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; 70 64 71 65 protected: … … 74 68 */ 75 69 void InitMaterial(); 70 71 //////////////// 76 72 77 73 /// unique material id -
GTP/trunk/App/Demos/Vis/CHC_revisited/RenderTraverser.cpp
r2768 r2769 4 4 #include "Camera.h" 5 5 #include "SceneEntity.h" 6 #include "RenderState.h" 6 7 7 8 … … 97 98 98 99 99 void RenderTraverser::Switch2GLRenderState()100 {101 // boolean used to avoid unnecessary state changes102 if (mIsQueryMode)103 {104 // switch back to rendermode105 glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);106 glDepthMask(GL_TRUE);107 glEnable(GL_LIGHTING);108 mIsQueryMode = false;109 }110 }111 112 113 100 OcclusionQuery *RenderTraverser::IssueOcclusionQuery(BvhNode *node, bool wasVisible) 114 101 { … … 130 117 {*/ 131 118 132 // change state so the bounding box gets not actually rendered on the screen133 Switch2GLQueryState();119 // change to query mode 120 mRenderState->SetState(RenderState::QUERY); 134 121 mBvh->RenderBoundingBox(node); 135 Switch2GLRenderState();122 mRenderState->SetState(RenderState::RENDER); 136 123 137 124 query->EndQuery(); 138 125 139 126 return query; 140 }141 142 143 void RenderTraverser::Switch2GLQueryState()144 {145 // boolean used to avoid unnecessary state changes146 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 }153 127 } 154 128 … … 189 163 mStats.Reset(); 190 164 mQueryHandler.ResetQueries(); 191 mRenderState->mTexturesEnabled = false;165 192 166 EnqueueNode(mBvh->GetRoot()); 193 167 … … 201 175 glDisableClientState(GL_NORMAL_ARRAY); 202 176 203 glDisable(GL_TEXTURE_2D); 204 glDisableClientState(GL_TEXTURE_COORD_ARRAY); 205 177 mRenderState->Reset(); 178 206 179 t2 = GetTime(); 207 180 mStats.mRenderTime = TimeDiff(t1, t2); -
GTP/trunk/App/Demos/Vis/CHC_revisited/RenderTraverser.h
r2767 r2769 96 96 */ 97 97 OcclusionQuery *IssueOcclusionQuery(BvhNode *node, bool wasVisible); 98 /** switches to normal render mode99 */100 void Switch2GLRenderState();101 /** switches to occlusion query mode (geometry not rendered on the screen)102 */103 void Switch2GLQueryState();104 98 /** Retunrs true if the current bvh node intersects the near plane. 105 99 */ -
GTP/trunk/App/Demos/Vis/CHC_revisited/SceneEntity.cpp
r2766 r2769 3 3 #include "Geometry.h" 4 4 #include "Material.h" 5 #include "RenderState.h" 5 6 6 7 … … 19 20 void SceneEntity::Render(RenderState *state) 20 21 { 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); 35 23 36 24 if (mTransform) -
GTP/trunk/App/Demos/Vis/CHC_revisited/SceneEntity.h
r2768 r2769 13 13 class Geometry; 14 14 class RenderState; 15 16 /** The current render state.17 */18 class RenderState19 {20 public:21 bool mTexturesEnabled;22 };23 15 24 16 -
GTP/trunk/App/Demos/Vis/CHC_revisited/Texture.cpp
r2768 r2769 33 33 { 34 34 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()))) 43 37 { 44 cerr << "Image load error " << ilGetError() << ": " << dummy<< endl;38 cerr << "Image load error " << ilGetError() << ": " << filename << endl; 45 39 } 46 40 else … … 75 69 76 70 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); 78 72 79 73 //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); … … 83 77 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); 84 78 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); 87 81 } 88 82 -
GTP/trunk/App/Demos/Vis/CHC_revisited/chc_revisited.vcproj
r2768 r2769 354 354 </File> 355 355 <File 356 RelativePath=".\RenderState.h" 357 > 358 </File> 359 <File 356 360 RelativePath=".\SceneEntity.h" 357 361 > … … 400 404 </File> 401 405 <File 406 RelativePath=".\RenderState.cpp" 407 > 408 </File> 409 <File 402 410 RelativePath=".\SceneEntity.cpp" 403 411 > -
GTP/trunk/App/Demos/Vis/CHC_revisited/chcdemo.cpp
r2768 r2769 19 19 #include "CHCPlusPlusTraverser.h" 20 20 #include "Visualization.h" 21 21 #include "RenderState.h" 22 22 23 23 … … 80 80 void SetupLighting(); 81 81 void DisplayStats(); 82 void Output(int x, int y, const char *string); 82 83 83 84 void begin2D(); 84 85 void end2D(); 85 void output(int x, int y, const char *string);86 86 void keyboard(unsigned char c, int x, int y); 87 87 void drawHelpMessage(); … … 180 180 181 181 //glEnable(GL_ALPHA_TEST); 182 //glAlphaFunc(GL_GEQUAL, 0.01);183 184 182 glDisable(GL_ALPHA_TEST); 183 glAlphaFunc(GL_GEQUAL, 0.1f); 185 184 186 185 glFrontFace(GL_CCW); … … 263 262 else 264 263 { 265 output(x, y, message[i]);264 Output(x, y, message[i]); 266 265 y += 14; 267 266 } … … 734 733 735 734 736 void output(const int x, constint y, const char *string)735 void Output(int x, int y, const char *string) 737 736 { 738 737 if (string != 0) … … 744 743 for (i = 0; i < len; ++ i) 745 744 { 746 glutBitmapCharacter(GLUT_BITMAP_ 8_BY_13, string[i]);745 glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18, string[i]); 747 746 } 748 747 } … … 841 840 char msg3[200]; 842 841 char msg4[200]; 842 char msg5[200]; 843 843 844 844 … … 856 856 renderTime = traverser->GetStats().mRenderTime * expFactor + (1.0f - expFactor) * renderTime; 857 857 858 if (renderTime) fps /=(float)renderTime;859 860 sprintf_s(msg 3, "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]); 862 862 863 863 string str; … … 868 868 CalcDecimalPoint(str2, traverser->GetStats().mNumRenderedTriangles); 869 869 870 sprintf_s(msg 4, "rendered objects %5d (of %5d), rendered triangles: %s (of %s)",870 sprintf_s(msg3, "rendered objects: %6d (of %6d), rendered triangles: %s (of %s)", 871 871 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); 872 876 873 877 … … 880 884 else 881 885 { 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]); 884 889 885 890 if(showStatistics) 886 891 { 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); 890 896 } 891 897 }
Note: See TracChangeset
for help on using the changeset viewer.