![]() |
TAPs 0.7.7.3
|
00001 /****************************************************************************** 00002 TAPsOpenGLXPolygonalModel.cpp 00003 00004 (X <==> Extra) 00005 Class OpenGLXPolygonalModel is for creating an Extra OpenGL Polygonal Model. 00006 00007 SUKITTI PUNAK (11/01/2004) 00008 UPDATE (11/01/2004) 00009 ******************************************************************************/ 00010 #include "TAPsOpenGLXPolygonalModel.hpp" 00011 // Using Inclusion Model (i.e. definitions are included in declarations) 00012 // (this name.cpp is included in name.hpp) 00013 // Each friend is defined directly inside its declaration. 00014 00015 BEGIN_NAMESPACE_TAPs__OpenGL 00016 //============================================================================= 00017 //----------------------------------------------------------------------------- 00018 // default constructor 00019 template <typename T> 00020 OpenGLXPolygonalModel<T>::OpenGLXPolygonalModel() 00021 : XPolygonalModel<T>(), bIsDisplayVertexNormals( false ) 00022 { 00023 #ifdef TAPs_DEBUG_MODE 00024 std::cout << "OpenGLXPolygonalModel<" << typeid(T).name() << "> constructor\n"; 00025 #endif//TAPs_DEBUG_MODE 00026 } 00027 //----------------------------------------------------------------------------- 00028 // destructor 00029 template <typename T> 00030 OpenGLXPolygonalModel<T>::~OpenGLXPolygonalModel() 00031 { 00032 #ifdef TAPs_DEBUG_MODE 00033 std::cout << "OpenGLXPolygonalModel<" << typeid(T).name() << "> destructor\n"; 00034 #endif//TAPs_DEBUG_MODE 00035 } 00036 00037 //* 00038 //============================================================================= 00039 //----------------------------------------------------------------------------- 00040 template <typename T> 00041 void OpenGLXPolygonalModel<T>::DisplayGLFaceRange ( 00042 int startFace, int endFace, 00043 OpenGL::Enum::DrawMode DM ) 00044 { 00045 //--------------------------------------- 00046 assert( 0 <= startFace ); 00047 assert( endFace < m_iNoFaces ); 00048 //--------------------------------------- 00049 //glPushAttrib( GL_ALL_ATTRIB_BITS ); 00050 glPushAttrib( GL_LIGHTING_BIT ); // Since ApplyMaterial() uses these bits 00051 ApplyMaterial(); 00052 //-------------------------------------------------------------------- 00053 // Do Transformation Here 00054 glPushMatrix(); 00055 //-------------------------------------------------------------------- 00056 GetTransform().TransformByOpenGLForDrawing(); 00057 switch ( DM ) { 00058 case OpenGL::Enum::POLYGON: 00059 DrawGLFaceRange( startFace, endFace, GL_POLYGON ); 00060 break; 00061 case OpenGL::Enum::WIRE_FRAME: 00062 DrawGLFaceRange( startFace, endFace, GL_LINE_LOOP ); 00063 break; 00064 case OpenGL::Enum::POINT: 00065 DrawGLFaceRange( startFace, endFace, GL_POINTS ); 00066 break; 00067 case OpenGL::Enum:: POLYGON_WITH_WIRE_FRAME: 00068 // Draw the object with GL_POLYGON_OFFSET enabled 00069 glEnable( GL_POLYGON_OFFSET_FILL ); 00070 glPolygonOffset( 1.0, 1.0 ); 00071 DrawGLFaceRange( startFace, endFace, GL_POLYGON ); 00072 glDisable( GL_POLYGON_OFFSET_FILL ); 00073 // Draw the wire frame of the object 00074 glDisable( GL_LIGHTING ); 00075 //glDisable( GL_DEPTH_TEST ); 00076 glColor3ub( 255, 200, 0 ); 00077 DrawGLFaceRange( startFace, endFace, GL_LINE_LOOP ); 00078 glEnable( GL_LIGHTING ); 00079 //glEnable( GL_DEPTH_TEST ); 00080 break; 00081 } 00082 //-------------------------------------------------------------------- 00083 glPopMatrix(); 00084 //-------------------------------------------------------------------- 00085 glPopAttrib(); 00086 } 00087 //----------------------------------------------------------------------------- 00088 template <typename T> 00089 void OpenGLXPolygonalModel<T>::DrawGLFaceRange ( 00090 int startFace, int endFace, 00091 GLenum drawMode ) 00092 { 00093 if ( isFacetShading ) { 00094 // Draw the object 00095 //glEnable( GL_TEXTURE_2D ); 00096 //--------------------------------------- 00097 for ( int i = startFace; i <= endFace; i++ ) 00098 { 00099 glBegin( drawMode ); 00100 for ( int j = 0; j < m_prFace[i].GetNoVertices(); ++j ) 00101 { 00102 // Draw texture 00103 if ( m_prFace[i].GetNoTexCoords() > 0 ) { 00104 glTexCoord2f( static_cast<float>( m_prFace[i].GetTexCoordHalfNo( j*2 ) ), 00105 static_cast<float>( m_prFace[i].GetTexCoordHalfNo( j*2+1 ) ) ); 00106 } 00107 // Normal of the face 00108 glNormal3f ( static_cast<float>( m_prFace[i].GetNormal()[0] ), 00109 static_cast<float>( m_prFace[i].GetNormal()[1] ), 00110 static_cast<float>( m_prFace[i].GetNormal()[2] ) ); 00111 // Draw the vertex 00112 glVertex3f ( 00113 static_cast<float>( m_prXVertex[ m_prFace[i].GetVertexNo( j ) ][0] ), 00114 static_cast<float>( m_prXVertex[ m_prFace[i].GetVertexNo( j ) ][1] ), 00115 static_cast<float>( m_prXVertex[ m_prFace[i].GetVertexNo( j ) ][2] ) ); 00116 } 00117 glEnd(); 00118 } 00119 //glDisable( GL_TEXTURE_2D ); 00120 } 00121 else { 00122 // Draw the object 00123 //glEnable( GL_TEXTURE_2D ); 00124 for ( int i = startFace; i <= endFace; i++ ) 00125 { 00126 glBegin( drawMode ); 00127 for ( int j = 0; j < m_prFace[i].GetNoVertices(); ++j ) 00128 { 00129 // Draw texture 00130 if ( m_prFace[i].GetNoTexCoords() > 0 ) { 00131 glTexCoord2f( static_cast<float>( m_prFace[i].GetTexCoordHalfNo( j*2 ) ), 00132 static_cast<float>( m_prFace[i].GetTexCoordHalfNo( j*2+1 ) ) ); 00133 } 00134 // Normal of the vertex 00135 glNormal3f ( static_cast<float>( m_prXVertex[ m_prFace[i].GetVertexNo( j ) ].GetNormal()[0] ), 00136 static_cast<float>( m_prXVertex[ m_prFace[i].GetVertexNo( j ) ].GetNormal()[1] ), 00137 static_cast<float>( m_prXVertex[ m_prFace[i].GetVertexNo( j ) ].GetNormal()[2] ) ); 00138 // Draw the vertex 00139 glVertex3f ( 00140 static_cast<float>( m_prXVertex[ m_prFace[i].GetVertexNo( j ) ][0] ), 00141 static_cast<float>( m_prXVertex[ m_prFace[i].GetVertexNo( j ) ][1] ), 00142 static_cast<float>( m_prXVertex[ m_prFace[i].GetVertexNo( j ) ][2] ) ); 00143 } 00144 glEnd(); 00145 } 00146 //glDisable( GL_TEXTURE_2D ); 00147 } 00148 00149 // Draw Vertex Normals 00150 if ( bIsDisplayVertexNormals ) { 00151 glPushAttrib( GL_LIGHTING_BIT | GL_CURRENT_BIT ); 00152 glDisable( GL_LIGHTING ); 00153 glColor3ub( 220, 0, 100 ); 00154 for ( int i = 0; i < GetNoVertices(); ++i ) { 00155 Fn::Draw3DLine( m_prXVertex[i].GetPosition(), m_prXVertex[i].GetPosition() + m_prXVertex[i].GetNormal() ); 00156 } 00157 glPopAttrib(); 00158 } 00159 00160 // Draw AABB Bounding Box 00161 //DrawBoundingAABB(); 00162 //DrawBoundingEllipsoid(); 00163 //DrawBoundingSphere(); 00164 } 00165 //----------------------------------------------------------------------------- 00166 //============================================================================= 00167 //*/ 00168 00169 00170 //----------------------------------------------------------------------------- 00171 // Helper Fn 00172 // void DrawGL() 00173 template <typename T> 00174 void OpenGLXPolygonalModel<T>::DrawGL ( GLenum drawMode ) 00175 { 00176 if ( isFacetShading ) { 00177 // Draw the object 00178 //glEnable( GL_TEXTURE_2D ); 00179 for ( int i = 0; i < m_iNoFaces; i++ ) 00180 { 00181 // Submaterial supported by .ASE 00182 #ifdef TAPs_SUPPORT_ASE_FORMAT 00183 int matID = m_prFace[i].GetMaterialID(); 00184 if ( matID < static_cast<int>( this->submaterials.size() ) ) { 00185 this->submaterials[ matID ]->ApplyMaterial(); 00186 } 00187 #endif//TAPs_SUPPORT_ASE_FORMAT 00188 00189 glBegin( drawMode ); 00190 for ( int j = 0; j < m_prFace[i].GetNoVertices(); ++j ) 00191 { 00192 // Draw texture 00193 if ( m_prFace[i].GetNoTexCoords() > 0 ) { 00194 glTexCoord2f( static_cast<float>( m_prFace[i].GetTexCoordHalfNo( j*2 ) ), 00195 static_cast<float>( m_prFace[i].GetTexCoordHalfNo( j*2+1 ) ) ); 00196 } 00197 // Normal of the face 00198 glNormal3f ( static_cast<float>( m_prFace[i].GetNormal()[0] ), 00199 static_cast<float>( m_prFace[i].GetNormal()[1] ), 00200 static_cast<float>( m_prFace[i].GetNormal()[2] ) ); 00201 // Draw the vertex 00202 glVertex3f ( 00203 static_cast<float>( m_prXVertex[ m_prFace[i].GetVertexNo( j ) ][0] ), 00204 static_cast<float>( m_prXVertex[ m_prFace[i].GetVertexNo( j ) ][1] ), 00205 static_cast<float>( m_prXVertex[ m_prFace[i].GetVertexNo( j ) ][2] ) ); 00206 } 00207 glEnd(); 00208 } 00209 //glDisable( GL_TEXTURE_2D ); 00210 } 00211 else { 00212 // Draw the object 00213 //glEnable( GL_TEXTURE_2D ); 00214 for ( int i = 0; i < m_iNoFaces; i++ ) 00215 { 00216 // Submaterial supported by .ASE 00217 #ifdef TAPs_SUPPORT_ASE_FORMAT 00218 int matID = m_prFace[i].GetMaterialID(); 00219 if ( matID < static_cast<int>( this->submaterials.size() ) ) { 00220 this->submaterials[ matID ]->ApplyMaterial(); 00221 } 00222 #endif//TAPs_SUPPORT_ASE_FORMAT 00223 00224 glBegin( drawMode ); 00225 for ( int j = 0; j < m_prFace[i].GetNoVertices(); ++j ) 00226 { 00227 // Draw texture 00228 if ( m_prFace[i].GetNoTexCoords() > 0 ) { 00229 glTexCoord2f( static_cast<float>( m_prFace[i].GetTexCoordHalfNo( j*2 ) ), 00230 static_cast<float>( m_prFace[i].GetTexCoordHalfNo( j*2+1 ) ) ); 00231 } 00232 // Normal of the vertex 00233 glNormal3f ( static_cast<float>( m_prXVertex[ m_prFace[i].GetVertexNo( j ) ].GetNormal()[0] ), 00234 static_cast<float>( m_prXVertex[ m_prFace[i].GetVertexNo( j ) ].GetNormal()[1] ), 00235 static_cast<float>( m_prXVertex[ m_prFace[i].GetVertexNo( j ) ].GetNormal()[2] ) ); 00236 // Draw the vertex 00237 glVertex3f ( 00238 static_cast<float>( m_prXVertex[ m_prFace[i].GetVertexNo( j ) ][0] ), 00239 static_cast<float>( m_prXVertex[ m_prFace[i].GetVertexNo( j ) ][1] ), 00240 static_cast<float>( m_prXVertex[ m_prFace[i].GetVertexNo( j ) ][2] ) ); 00241 } 00242 glEnd(); 00243 } 00244 //glDisable( GL_TEXTURE_2D ); 00245 } 00246 00247 // Draw Vertex Normals 00248 if ( bIsDisplayVertexNormals ) { 00249 glPushAttrib( GL_LIGHTING_BIT | GL_CURRENT_BIT ); 00250 glDisable( GL_LIGHTING ); 00251 glColor3ub( 220, 0, 100 ); 00252 for ( int i = 0; i < GetNoVertices(); ++i ) { 00253 Fn::Draw3DLine( m_prXVertex[i].GetPosition(), m_prXVertex[i].GetPosition() + m_prXVertex[i].GetNormal() ); 00254 } 00255 glPopAttrib(); 00256 } 00257 00258 // Draw AABB Bounding Box 00259 //DrawBoundingAABB(); 00260 //DrawBoundingEllipsoid(); 00261 //DrawBoundingSphere(); 00262 } 00263 //----------------------------------------------------------------------------- 00264 00265 //============================================================================= 00266 #ifdef TAPs_ENABLE_FACE_VERTEX_COLOR 00267 //----------------------------------------------------------------------------- 00268 template <typename T> 00269 void OpenGLXPolygonalModel<T>::DrawGLWithFaceVertexColor_RGB ( GLenum drawMode ) 00270 { 00271 //static bool isFirst = true; 00272 00273 glPushAttrib( GL_ENABLE_BIT | GL_ENABLE_BIT ); 00274 glEnable( GL_COLOR_MATERIAL ); 00275 00276 if ( isFacetShading ) { 00277 // Draw the object 00278 //glEnable( GL_TEXTURE_2D ); 00279 for ( int i = 0; i < m_iNoFaces; i++ ) 00280 { 00281 /* 00282 // Submaterial supported by .ASE 00283 #ifdef TAPs_SUPPORT_ASE_FORMAT 00284 int matID = m_prFace[i].GetMaterialID(); 00285 if ( matID < static_cast<int>( this->submaterials.size() ) ) { 00286 this->submaterials[ matID ]->ApplyMaterial(); 00287 } 00288 #endif//TAPs_SUPPORT_ASE_FORMAT 00289 //*/ 00290 00291 glBegin( drawMode ); 00292 for ( int j = 0; j < m_prFace[i].GetNoVertices(); ++j ) 00293 { 00294 // Draw texture 00295 if ( m_prFace[i].GetNoTexCoords() > 0 ) { 00296 glTexCoord2f( static_cast<float>( m_prFace[i].GetTexCoordHalfNo( j*2 ) ), 00297 static_cast<float>( m_prFace[i].GetTexCoordHalfNo( j*2+1 ) ) ); 00298 } 00299 // Normal of the face 00300 glNormal3f ( static_cast<float>( m_prFace[i].GetNormal()[0] ), 00301 static_cast<float>( m_prFace[i].GetNormal()[1] ), 00302 static_cast<float>( m_prFace[i].GetNormal()[2] ) ); 00303 00304 // Vertex color of the face 00305 float VC[3]; 00306 GetVertexColor( m_prFace[i].GetVertexColorNo( j ), &VC[0], &VC[1], &VC[2] ); 00307 glColor3f ( VC[0], VC[1], VC[2] ); 00308 00309 // Draw the vertex 00310 glVertex3f ( 00311 static_cast<float>( m_prXVertex[ m_prFace[i].GetVertexNo( j ) ][0] ), 00312 static_cast<float>( m_prXVertex[ m_prFace[i].GetVertexNo( j ) ][1] ), 00313 static_cast<float>( m_prXVertex[ m_prFace[i].GetVertexNo( j ) ][2] ) ); 00314 } 00315 glEnd(); 00316 } 00317 //glDisable( GL_TEXTURE_2D ); 00318 } 00319 else { 00320 // Draw the object 00321 //glEnable( GL_TEXTURE_2D ); 00322 for ( int i = 0; i < m_iNoFaces; i++ ) 00323 { 00324 /* 00325 // Submaterial supported by .ASE 00326 #ifdef TAPs_SUPPORT_ASE_FORMAT 00327 int matID = m_prFace[i].GetMaterialID(); 00328 if ( matID < static_cast<int>( this->submaterials.size() ) ) { 00329 this->submaterials[ matID ]->ApplyMaterial(); 00330 } 00331 #endif//TAPs_SUPPORT_ASE_FORMAT 00332 //*/ 00333 00334 glBegin( drawMode ); 00335 for ( int j = 0; j < m_prFace[i].GetNoVertices(); ++j ) 00336 { 00337 // Draw texture 00338 if ( m_prFace[i].GetNoTexCoords() > 0 ) { 00339 glTexCoord2f( static_cast<float>( m_prFace[i].GetTexCoordHalfNo( j*2 ) ), 00340 static_cast<float>( m_prFace[i].GetTexCoordHalfNo( j*2+1 ) ) ); 00341 } 00342 // Normal of the vertex 00343 glNormal3f ( static_cast<float>( m_prXVertex[ m_prFace[i].GetVertexNo( j ) ].GetNormal()[0] ), 00344 static_cast<float>( m_prXVertex[ m_prFace[i].GetVertexNo( j ) ].GetNormal()[1] ), 00345 static_cast<float>( m_prXVertex[ m_prFace[i].GetVertexNo( j ) ].GetNormal()[2] ) ); 00346 00347 //if ( isFirst ) { 00348 // std::cout << "Face# " << i << " V# " << j << ":\t" << m_prXVertex[ m_prFace[i].GetVertexNo( j ) ].GetNormal() << "\n"; 00349 //} 00350 00351 // Vertex color of the face 00352 float VC[3]; 00353 GetVertexColor( m_prFace[i].GetVertexColorNo( j ), &VC[0], &VC[1], &VC[2] ); 00354 glColor3f ( VC[0], VC[1], VC[2] ); 00355 00356 // Draw the vertex 00357 glVertex3f ( 00358 static_cast<float>( m_prXVertex[ m_prFace[i].GetVertexNo( j ) ][0] ), 00359 static_cast<float>( m_prXVertex[ m_prFace[i].GetVertexNo( j ) ][1] ), 00360 static_cast<float>( m_prXVertex[ m_prFace[i].GetVertexNo( j ) ][2] ) ); 00361 } 00362 glEnd(); 00363 } 00364 //glDisable( GL_TEXTURE_2D ); 00365 } 00366 00367 glPopAttrib(); 00368 00369 // Draw Vertex Normals 00370 if ( bIsDisplayVertexNormals ) { 00371 glPushAttrib( GL_LIGHTING_BIT | GL_CURRENT_BIT ); 00372 glDisable( GL_LIGHTING ); 00373 glColor3ub( 220, 0, 100 ); 00374 for ( int i = 0; i < GetNoVertices(); ++i ) { 00375 Fn::Draw3DLine( m_prXVertex[i].GetPosition(), m_prXVertex[i].GetPosition() + m_prXVertex[i].GetNormal() ); 00376 } 00377 glPopAttrib(); 00378 } 00379 00380 //isFirst = false; 00381 00382 // Draw AABB Bounding Box 00383 //DrawBoundingAABB(); 00384 //DrawBoundingEllipsoid(); 00385 //DrawBoundingSphere(); 00386 } 00387 //----------------------------------------------------------------------------- 00388 template <typename T> 00389 void OpenGLXPolygonalModel<T>::DrawGLWithFaceVertexColor_RGBA ( GLenum drawMode ) 00390 { 00391 //static bool isFirst = true; 00392 00393 glPushAttrib( GL_ENABLE_BIT | GL_ENABLE_BIT ); 00394 glEnable( GL_COLOR_MATERIAL ); 00395 00396 if ( isFacetShading ) { 00397 // Draw the object 00398 //glEnable( GL_TEXTURE_2D ); 00399 for ( int i = 0; i < m_iNoFaces; i++ ) 00400 { 00401 /* 00402 // Submaterial supported by .ASE 00403 #ifdef TAPs_SUPPORT_ASE_FORMAT 00404 int matID = m_prFace[i].GetMaterialID(); 00405 if ( matID < static_cast<int>( this->submaterials.size() ) ) { 00406 this->submaterials[ matID ]->ApplyMaterial(); 00407 } 00408 #endif//TAPs_SUPPORT_ASE_FORMAT 00409 //*/ 00410 00411 glBegin( drawMode ); 00412 for ( int j = 0; j < m_prFace[i].GetNoVertices(); ++j ) 00413 { 00414 // Draw texture 00415 if ( m_prFace[i].GetNoTexCoords() > 0 ) { 00416 glTexCoord2f( static_cast<float>( m_prFace[i].GetTexCoordHalfNo( j*2 ) ), 00417 static_cast<float>( m_prFace[i].GetTexCoordHalfNo( j*2+1 ) ) ); 00418 } 00419 // Normal of the face 00420 glNormal3f ( static_cast<float>( m_prFace[i].GetNormal()[0] ), 00421 static_cast<float>( m_prFace[i].GetNormal()[1] ), 00422 static_cast<float>( m_prFace[i].GetNormal()[2] ) ); 00423 00424 // Vertex color of the face 00425 float VC[4]; 00426 GetVertexColor( m_prFace[i].GetVertexColorNo( j ), &VC[0], &VC[1], &VC[2], &VC[3] ); 00427 glColor4f ( VC[0], VC[1], VC[2], VC[3] ); 00428 00429 // Draw the vertex 00430 glVertex3f ( 00431 static_cast<float>( m_prXVertex[ m_prFace[i].GetVertexNo( j ) ][0] ), 00432 static_cast<float>( m_prXVertex[ m_prFace[i].GetVertexNo( j ) ][1] ), 00433 static_cast<float>( m_prXVertex[ m_prFace[i].GetVertexNo( j ) ][2] ) ); 00434 } 00435 glEnd(); 00436 } 00437 //glDisable( GL_TEXTURE_2D ); 00438 } 00439 else { 00440 // Draw the object 00441 //glEnable( GL_TEXTURE_2D ); 00442 for ( int i = 0; i < m_iNoFaces; i++ ) 00443 { 00444 /* 00445 // Submaterial supported by .ASE 00446 #ifdef TAPs_SUPPORT_ASE_FORMAT 00447 int matID = m_prFace[i].GetMaterialID(); 00448 if ( matID < static_cast<int>( this->submaterials.size() ) ) { 00449 this->submaterials[ matID ]->ApplyMaterial(); 00450 } 00451 #endif//TAPs_SUPPORT_ASE_FORMAT 00452 //*/ 00453 00454 glBegin( drawMode ); 00455 for ( int j = 0; j < m_prFace[i].GetNoVertices(); ++j ) 00456 { 00457 // Draw texture 00458 if ( m_prFace[i].GetNoTexCoords() > 0 ) { 00459 glTexCoord2f( static_cast<float>( m_prFace[i].GetTexCoordHalfNo( j*2 ) ), 00460 static_cast<float>( m_prFace[i].GetTexCoordHalfNo( j*2+1 ) ) ); 00461 } 00462 // Normal of the vertex 00463 glNormal3f ( static_cast<float>( m_prXVertex[ m_prFace[i].GetVertexNo( j ) ].GetNormal()[0] ), 00464 static_cast<float>( m_prXVertex[ m_prFace[i].GetVertexNo( j ) ].GetNormal()[1] ), 00465 static_cast<float>( m_prXVertex[ m_prFace[i].GetVertexNo( j ) ].GetNormal()[2] ) ); 00466 00467 //if ( isFirst ) { 00468 // std::cout << "Face# " << i << " V# " << j << ":\t" << m_prXVertex[ m_prFace[i].GetVertexNo( j ) ].GetNormal() << "\n"; 00469 //} 00470 00471 // Vertex color of the face 00472 float VC[4]; 00473 GetVertexColor( m_prFace[i].GetVertexColorNo( j ), &VC[0], &VC[1], &VC[2], &VC[3] ); 00474 glColor4f ( VC[0], VC[1], VC[2], VC[3] ); 00475 00476 // Draw the vertex 00477 glVertex3f ( 00478 static_cast<float>( m_prXVertex[ m_prFace[i].GetVertexNo( j ) ][0] ), 00479 static_cast<float>( m_prXVertex[ m_prFace[i].GetVertexNo( j ) ][1] ), 00480 static_cast<float>( m_prXVertex[ m_prFace[i].GetVertexNo( j ) ][2] ) ); 00481 } 00482 glEnd(); 00483 } 00484 //glDisable( GL_TEXTURE_2D ); 00485 } 00486 00487 glPopAttrib(); 00488 00489 // Draw Vertex Normals 00490 if ( bIsDisplayVertexNormals ) { 00491 glPushAttrib( GL_LIGHTING_BIT | GL_CURRENT_BIT ); 00492 glDisable( GL_LIGHTING ); 00493 glColor3ub( 220, 0, 100 ); 00494 for ( int i = 0; i < GetNoVertices(); ++i ) { 00495 Fn::Draw3DLine( m_prXVertex[i].GetPosition(), m_prXVertex[i].GetPosition() + m_prXVertex[i].GetNormal() ); 00496 } 00497 glPopAttrib(); 00498 } 00499 00500 //isFirst = false; 00501 00502 // Draw AABB Bounding Box 00503 //DrawBoundingAABB(); 00504 //DrawBoundingEllipsoid(); 00505 //DrawBoundingSphere(); 00506 } 00507 //----------------------------------------------------------------------------- 00508 template <typename T> 00509 bool OpenGLXPolygonalModel<T>::EnableVertexColors ( bool b ) 00510 { 00511 if ( m_svVertexColors.size() == 0 ) m_bEnableVertexColor = false; 00512 else m_bEnableVertexColor = b; 00513 return m_bEnableVertexColor; 00514 } 00515 //----------------------------------------------------------------------------- 00516 #endif//TAPs_ENABLE_FACE_VERTEX_COLOR 00517 //============================================================================= 00518 00519 00520 00521 00522 00523 00524 00525 00526 //============================================================================= 00527 #ifdef TAPs_RENDER_BY_GLSL_DS_FACE_VERTEX 00528 //----------------------------------------------------------------------------- 00529 template <typename T> 00530 void OpenGLXPolygonalModel<T>::DrawGLSLWithDSFaceVertex_RGB ( GLenum drawMode ) 00531 { 00532 //static bool isFirst = true; 00533 00534 //assert( ShaderProgram ); 00535 GlobalGLSLShaderPool::GetShaderProgram( ShaderName )->BeginGLSL(); 00536 GlobalGLSLShaderPool::SetShaderParameters( ShaderName ); 00537 00538 glPushAttrib( GL_ENABLE_BIT | GL_ENABLE_BIT ); 00539 glEnable( GL_COLOR_MATERIAL ); 00540 00541 if ( isFacetShading ) { 00542 // Draw the object 00543 //glEnable( GL_TEXTURE_2D ); 00544 for ( int i = 0; i < m_iNoFaces; i++ ) 00545 { 00546 /* 00547 // Submaterial supported by .ASE 00548 #ifdef TAPs_SUPPORT_ASE_FORMAT 00549 int matID = m_prFace[i].GetMaterialID(); 00550 if ( matID < static_cast<int>( this->submaterials.size() ) ) { 00551 this->submaterials[ matID ]->ApplyMaterial(); 00552 } 00553 #endif//TAPs_SUPPORT_ASE_FORMAT 00554 //*/ 00555 00556 glBegin( drawMode ); 00557 for ( int j = 0; j < m_prFace[i].GetNoVertices(); ++j ) 00558 { 00559 // Draw texture 00560 if ( m_prFace[i].GetNoTexCoords() > 0 ) { 00561 glTexCoord2f( static_cast<float>( m_prFace[i].GetTexCoordHalfNo( j*2 ) ), 00562 static_cast<float>( m_prFace[i].GetTexCoordHalfNo( j*2+1 ) ) ); 00563 } 00564 // Normal of the face 00565 glNormal3f ( static_cast<float>( m_prFace[i].GetNormal()[0] ), 00566 static_cast<float>( m_prFace[i].GetNormal()[1] ), 00567 static_cast<float>( m_prFace[i].GetNormal()[2] ) ); 00568 00569 /* 00570 // Vertex color of the face 00571 float VC[3]; 00572 GetVertexColor( m_prFace[i].GetVertexColorNo( j ), &VC[0], &VC[1], &VC[2] ); 00573 glColor3f ( VC[0], VC[1], VC[2] ); 00574 //*/ 00575 00576 // Draw the vertex 00577 glVertex3f ( 00578 static_cast<float>( m_prXVertex[ m_prFace[i].GetVertexNo( j ) ][0] ), 00579 static_cast<float>( m_prXVertex[ m_prFace[i].GetVertexNo( j ) ][1] ), 00580 static_cast<float>( m_prXVertex[ m_prFace[i].GetVertexNo( j ) ][2] ) ); 00581 } 00582 glEnd(); 00583 } 00584 //glDisable( GL_TEXTURE_2D ); 00585 } 00586 else { 00587 // Draw the object 00588 //glEnable( GL_TEXTURE_2D ); 00589 for ( int i = 0; i < m_iNoFaces; i++ ) 00590 { 00591 /* 00592 // Submaterial supported by .ASE 00593 #ifdef TAPs_SUPPORT_ASE_FORMAT 00594 int matID = m_prFace[i].GetMaterialID(); 00595 if ( matID < static_cast<int>( this->submaterials.size() ) ) { 00596 this->submaterials[ matID ]->ApplyMaterial(); 00597 } 00598 #endif//TAPs_SUPPORT_ASE_FORMAT 00599 //*/ 00600 00601 glBegin( drawMode ); 00602 for ( int j = 0; j < m_prFace[i].GetNoVertices(); ++j ) 00603 { 00604 // Draw texture 00605 if ( m_prFace[i].GetNoTexCoords() > 0 ) { 00606 glTexCoord2f( static_cast<float>( m_prFace[i].GetTexCoordHalfNo( j*2 ) ), 00607 static_cast<float>( m_prFace[i].GetTexCoordHalfNo( j*2+1 ) ) ); 00608 } 00609 // Normal of the vertex 00610 glNormal3f ( static_cast<float>( m_prXVertex[ m_prFace[i].GetVertexNo( j ) ].GetNormal()[0] ), 00611 static_cast<float>( m_prXVertex[ m_prFace[i].GetVertexNo( j ) ].GetNormal()[1] ), 00612 static_cast<float>( m_prXVertex[ m_prFace[i].GetVertexNo( j ) ].GetNormal()[2] ) ); 00613 00614 //if ( isFirst ) { 00615 // std::cout << "Face# " << i << " V# " << j << ":\t" << m_prXVertex[ m_prFace[i].GetVertexNo( j ) ].GetNormal() << "\n"; 00616 //} 00617 00618 /* 00619 // Vertex color of the face 00620 float VC[3]; 00621 GetVertexColor( m_prFace[i].GetVertexColorNo( j ), &VC[0], &VC[1], &VC[2] ); 00622 glColor3f ( VC[0], VC[1], VC[2] ); 00623 //*/ 00624 00625 // Draw the vertex 00626 glVertex3f ( 00627 static_cast<float>( m_prXVertex[ m_prFace[i].GetVertexNo( j ) ][0] ), 00628 static_cast<float>( m_prXVertex[ m_prFace[i].GetVertexNo( j ) ][1] ), 00629 static_cast<float>( m_prXVertex[ m_prFace[i].GetVertexNo( j ) ][2] ) ); 00630 } 00631 glEnd(); 00632 } 00633 //glDisable( GL_TEXTURE_2D ); 00634 } 00635 00636 glPopAttrib(); 00637 00638 // Draw Vertex Normals 00639 if ( bIsDisplayVertexNormals ) { 00640 glPushAttrib( GL_LIGHTING_BIT | GL_CURRENT_BIT ); 00641 glDisable( GL_LIGHTING ); 00642 glColor3ub( 220, 0, 100 ); 00643 for ( int i = 0; i < GetNoVertices(); ++i ) { 00644 Fn::Draw3DLine( m_prXVertex[i].GetPosition(), m_prXVertex[i].GetPosition() + m_prXVertex[i].GetNormal() ); 00645 } 00646 glPopAttrib(); 00647 } 00648 00649 //isFirst = false; 00650 00651 // Draw AABB Bounding Box 00652 //DrawBoundingAABB(); 00653 //DrawBoundingEllipsoid(); 00654 //DrawBoundingSphere(); 00655 00656 GlobalGLSLShaderPool::GetShaderProgram( ShaderName )->EndGLSL(); 00657 } 00658 //----------------------------------------------------------------------------- 00659 template <typename T> 00660 void OpenGLXPolygonalModel<T>::DrawGLSLWithDSFaceVertex_RGBA ( GLenum drawMode ) 00661 { 00662 //static bool isFirst = true; 00663 00664 //assert( ShaderProgram ); 00665 GlobalGLSLShaderPool::GetShaderProgram( ShaderName )->BeginGLSL(); 00666 GlobalGLSLShaderPool::SetShaderParameters( ShaderName ); 00667 00668 glPushAttrib( GL_ENABLE_BIT | GL_ENABLE_BIT ); 00669 glEnable( GL_COLOR_MATERIAL ); 00670 00671 if ( isFacetShading ) { 00672 // Draw the object 00673 //glEnable( GL_TEXTURE_2D ); 00674 for ( int i = 0; i < m_iNoFaces; i++ ) 00675 { 00676 /* 00677 // Submaterial supported by .ASE 00678 #ifdef TAPs_SUPPORT_ASE_FORMAT 00679 int matID = m_prFace[i].GetMaterialID(); 00680 if ( matID < static_cast<int>( this->submaterials.size() ) ) { 00681 this->submaterials[ matID ]->ApplyMaterial(); 00682 } 00683 #endif//TAPs_SUPPORT_ASE_FORMAT 00684 //*/ 00685 00686 glBegin( drawMode ); 00687 for ( int j = 0; j < m_prFace[i].GetNoVertices(); ++j ) 00688 { 00689 // Draw texture 00690 if ( m_prFace[i].GetNoTexCoords() > 0 ) { 00691 glTexCoord2f( static_cast<float>( m_prFace[i].GetTexCoordHalfNo( j*2 ) ), 00692 static_cast<float>( m_prFace[i].GetTexCoordHalfNo( j*2+1 ) ) ); 00693 } 00694 // Normal of the face 00695 glNormal3f ( static_cast<float>( m_prFace[i].GetNormal()[0] ), 00696 static_cast<float>( m_prFace[i].GetNormal()[1] ), 00697 static_cast<float>( m_prFace[i].GetNormal()[2] ) ); 00698 00699 /* 00700 // Vertex color of the face 00701 float VC[4]; 00702 GetVertexColor( m_prFace[i].GetVertexColorNo( j ), &VC[0], &VC[1], &VC[2], &VC[3] ); 00703 glColor4f ( VC[0], VC[1], VC[2], VC[3] ); 00704 //*/ 00705 00706 // Draw the vertex 00707 glVertex3f ( 00708 static_cast<float>( m_prXVertex[ m_prFace[i].GetVertexNo( j ) ][0] ), 00709 static_cast<float>( m_prXVertex[ m_prFace[i].GetVertexNo( j ) ][1] ), 00710 static_cast<float>( m_prXVertex[ m_prFace[i].GetVertexNo( j ) ][2] ) ); 00711 } 00712 glEnd(); 00713 } 00714 //glDisable( GL_TEXTURE_2D ); 00715 } 00716 else { 00717 // Draw the object 00718 //glEnable( GL_TEXTURE_2D ); 00719 for ( int i = 0; i < m_iNoFaces; i++ ) 00720 { 00721 /* 00722 // Submaterial supported by .ASE 00723 #ifdef TAPs_SUPPORT_ASE_FORMAT 00724 int matID = m_prFace[i].GetMaterialID(); 00725 if ( matID < static_cast<int>( this->submaterials.size() ) ) { 00726 this->submaterials[ matID ]->ApplyMaterial(); 00727 } 00728 #endif//TAPs_SUPPORT_ASE_FORMAT 00729 //*/ 00730 00731 glBegin( drawMode ); 00732 for ( int j = 0; j < m_prFace[i].GetNoVertices(); ++j ) 00733 { 00734 // Draw texture 00735 if ( m_prFace[i].GetNoTexCoords() > 0 ) { 00736 glTexCoord2f( static_cast<float>( m_prFace[i].GetTexCoordHalfNo( j*2 ) ), 00737 static_cast<float>( m_prFace[i].GetTexCoordHalfNo( j*2+1 ) ) ); 00738 } 00739 // Normal of the vertex 00740 glNormal3f ( static_cast<float>( m_prXVertex[ m_prFace[i].GetVertexNo( j ) ].GetNormal()[0] ), 00741 static_cast<float>( m_prXVertex[ m_prFace[i].GetVertexNo( j ) ].GetNormal()[1] ), 00742 static_cast<float>( m_prXVertex[ m_prFace[i].GetVertexNo( j ) ].GetNormal()[2] ) ); 00743 00744 //if ( isFirst ) { 00745 // std::cout << "Face# " << i << " V# " << j << ":\t" << m_prXVertex[ m_prFace[i].GetVertexNo( j ) ].GetNormal() << "\n"; 00746 //} 00747 00748 /* 00749 // Vertex color of the face 00750 float VC[4]; 00751 GetVertexColor( m_prFace[i].GetVertexColorNo( j ), &VC[0], &VC[1], &VC[2], &VC[3] ); 00752 glColor4f ( VC[0], VC[1], VC[2], VC[3] ); 00753 //*/ 00754 00755 // Draw the vertex 00756 glVertex3f ( 00757 static_cast<float>( m_prXVertex[ m_prFace[i].GetVertexNo( j ) ][0] ), 00758 static_cast<float>( m_prXVertex[ m_prFace[i].GetVertexNo( j ) ][1] ), 00759 static_cast<float>( m_prXVertex[ m_prFace[i].GetVertexNo( j ) ][2] ) ); 00760 } 00761 glEnd(); 00762 } 00763 //glDisable( GL_TEXTURE_2D ); 00764 } 00765 00766 glPopAttrib(); 00767 00768 // Draw Vertex Normals 00769 if ( bIsDisplayVertexNormals ) { 00770 glPushAttrib( GL_LIGHTING_BIT | GL_CURRENT_BIT ); 00771 glDisable( GL_LIGHTING ); 00772 glColor3ub( 220, 0, 100 ); 00773 for ( int i = 0; i < GetNoVertices(); ++i ) { 00774 Fn::Draw3DLine( m_prXVertex[i].GetPosition(), m_prXVertex[i].GetPosition() + m_prXVertex[i].GetNormal() ); 00775 } 00776 glPopAttrib(); 00777 } 00778 00779 //isFirst = false; 00780 00781 // Draw AABB Bounding Box 00782 //DrawBoundingAABB(); 00783 //DrawBoundingEllipsoid(); 00784 //DrawBoundingSphere(); 00785 00786 GlobalGLSLShaderPool::GetShaderProgram( ShaderName )->EndGLSL(); 00787 } 00788 //----------------------------------------------------------------------------- 00789 #endif//TAPs_RENDER_BY_GLSL_DS_FACE_VERTEX 00790 //============================================================================= 00791 00792 00793 00794 00795 00796 00797 00798 //============================================================================= 00799 END_NAMESPACE_TAPs__OpenGL 00800 //----------------------------------------------------------------------------- 00801 //345678901234567890123456789012345678901234567890123456789012345678901234567890 00802 //--+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8