![]() |
TAPs 0.7.7.3
|
00001 /****************************************************************************** 00002 TAPsOpenGLFns.cpp 00003 00004 OpenGL Global Functions. 00005 00006 SUKITTI PUNAK (10/04/2004) 00007 UPDATE (10/27/2004) 00008 ******************************************************************************/ 00009 #include "TAPsOpenGLFns.hpp" 00010 // Using Inclusion Model (i.e. definitions are included in declarations) 00011 // (this name.cpp is included in name.hpp) 00012 // Each friend is defined directly inside its declaration. 00013 00014 BEGIN_NAMESPACE_TAPs__OpenGL__Fn 00015 //============================================================================= 00016 // START: GLOBAL VARIABLE(S) 00017 //----------------------------------------------------------------------------- 00018 // GLenum 00019 //GLenum g_eCullFace = GL_BACK; 00020 //GLenum g_eDrawFace = GL_FRONT_AND_BACK; 00021 //GLenum g_eDrawMode = GL_FILL; 00022 //----------------------------------------------------------------------------- 00023 //----------------------------------------------------------------------------- 00024 // END: GLOBAL VARIABLE(S) 00025 //============================================================================= 00026 GLuint g_uiGLFontDisplayList = 0; 00027 GLuint GetGLFontDisplayList () { return g_uiGLFontDisplayList; } 00028 //============================================================================= 00029 // START: OPENGL DEBUG/ERROR 00030 //----------------------------------------------------------------------------- 00031 // Check OpenGL Error 00040 #ifdef TAPs_DEBUG_MODE 00041 void GFnCheckGLError ( char * file, int line, int * glErrCode ) 00042 { 00043 GLenum glErr = glGetError(); 00044 int errCode = 0; 00045 while ( glErr != GL_NO_ERROR ) { 00046 #ifdef TAPs_USE_WXWIDGETS 00047 wxLogError( wxT( "GL Error #%d (%s) in file %s at line#%d" ), 00048 glErr, gluErrorString(glErr), file, line ); 00049 #else 00050 std::cout 00051 << "GL Error #" << glErr << " (" << gluErrorString(glErr) << ") " 00052 << "in file " << file << " at line#" << line << std::endl; 00053 #endif 00054 errCode = 1; 00055 glErr = glGetError(); 00056 } 00057 if ( glErrCode ) *glErrCode = errCode; 00058 } 00059 #else 00060 void GFnCheckGLError ( char *file, int line, int * glErrCode ) {} 00061 #endif 00062 #define CHECK_GL_ERROR() GFnCheckGLError( __FILE__, __LINE__ ) 00063 //----------------------------------------------------------------------------- 00064 // Check OpenGL Error with Custom Message 00076 #ifdef TAPs_DEBUG_MODE 00077 void GFnCheckGLError ( char * customMessage, int * glErrCode ) 00078 { 00079 GLenum glErr = glGetError(); 00080 int errCode = 0; 00081 while ( glErr != GL_NO_ERROR ) { 00082 #ifdef TAPs_USE_WXWIDGETS 00083 wxLogError( wxT( "%s --> GL Error #%d (%s)!" ), 00084 customMessage, glErr, gluErrorString(glErr) ); 00085 #else 00086 std::cerr 00087 << customMessage << " --> GL Error #" << glErr 00088 << " (" << gluErrorString(glErr) << ")!" << std::endl; 00089 #endif 00090 errCode = 1; 00091 glErr = glGetError(); 00092 } 00093 if ( glErrCode ) *glErrCode = errCode; 00094 } 00095 #else 00096 void GFnCheckGLError ( char * customMessage, int * glErrCode ) {} 00097 #endif 00098 #define CHECK_GL_ERROR_MESSAGE( s ) GFnCheckGLError( s ) 00099 //----------------------------------------------------------------------------- 00100 // Check OpenGL Frame Buffer Status 00109 #ifdef TAPs_DEBUG_MODE 00110 #ifdef TAPs_USE_GLSL 00111 void GFnCheckFrameBufferStatus () 00112 { 00113 //--------------------------------------------------------------- 00114 switch ( glCheckFramebufferStatusEXT( GL_FRAMEBUFFER_EXT ) ) { 00115 case GL_FRAMEBUFFER_COMPLETE_EXT: 00116 break; 00117 case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT: 00118 #ifdef TAPs_USE_WXWIDGETS 00119 wxLogError( wxT( "ERROR (GLEXTFrameBufferObject): GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT" ) ); 00120 #else 00121 std::cout << "ERROR (GLEXTFrameBufferObject): GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT" << std::endl; 00122 #endif 00123 break; 00124 case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT: 00125 #ifdef TAPs_USE_WXWIDGETS 00126 wxLogError( wxT( "ERROR (GLEXTFrameBufferObject): GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT" ) ); 00127 #else 00128 std::cout << "ERROR (GLEXTFrameBufferObject): GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT" << std::endl; 00129 #endif 00130 break; 00131 case GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT: 00132 #ifdef TAPs_USE_WXWIDGETS 00133 wxLogError( wxT( "ERROR (GLEXTFrameBufferObject): GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT" ) ); 00134 #else 00135 std::cout << "ERROR (GLEXTFrameBufferObject): GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT" << std::endl; 00136 #endif 00137 break; 00138 case GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT: 00139 #ifdef TAPs_USE_WXWIDGETS 00140 wxLogError( wxT( "ERROR (GLEXTFrameBufferObject): GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT" ) ); 00141 #else 00142 std::cout << "ERROR (GLEXTFrameBufferObject): GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT" << std::endl; 00143 #endif 00144 break; 00145 case GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT: 00146 #ifdef TAPs_USE_WXWIDGETS 00147 wxLogError( wxT( "ERROR (GLEXTFrameBufferObject): GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT" ) ); 00148 #else 00149 std::cout << "ERROR (GLEXTFrameBufferObject): GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT" << std::endl; 00150 #endif 00151 break; 00152 case GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT: 00153 #ifdef TAPs_USE_WXWIDGETS 00154 wxLogError( wxT( "ERROR (GLEXTFrameBufferObject): GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT" ) ); 00155 #else 00156 std::cout << "ERROR (GLEXTFrameBufferObject): GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT" << std::endl; 00157 #endif 00158 break; 00159 case GL_FRAMEBUFFER_UNSUPPORTED_EXT: 00160 #ifdef TAPs_USE_WXWIDGETS 00161 wxLogError( wxT( "ERROR (GLEXTFrameBufferObject): GL_FRAMEBUFFER_UNSUPPORTED_EXT" ) ); 00162 #else 00163 std::cout << "ERROR (GLEXTFrameBufferObject): GL_FRAMEBUFFER_UNSUPPORTED_EXT" << std::endl; 00164 #endif 00165 break; 00166 default: 00167 #ifdef TAPs_USE_WXWIDGETS 00168 wxLogError( wxT( "ERROR (GLEXTFrameBufferObject): UNKNOWN ERROR!" ) ); 00169 #else 00170 std::cout << "ERROR (GLEXTFrameBufferObject): UNKNOWN ERROR!" << std::endl; 00171 #endif 00172 break; 00173 } 00174 } 00175 #else 00176 void GFnCheckFrameBufferStatus () {} 00177 #endif 00178 #else 00179 void GFnCheckFrameBufferStatus () {} 00180 #endif 00181 #define CHECK_FRAMEBUFFER_STATUS() GFnCheckFrameBufferStatus() 00182 //----------------------------------------------------------------------------- 00183 // END: OPENGL DEBUG/ERROR 00184 //============================================================================= 00185 00186 //============================================================================= 00187 // START: OPENGL LIGHTING 00188 //----------------------------------------------------------------------------- 00189 // Initialize and Enable the Light (with the Default Values) 00190 // The light is a GLenum, which can be (at least 8 lights) from 00191 // GL_LIGHT0, GL_LIGHT1,..., or GL_LIGHT7. 00192 void InitializeLight( GLenum light, 00193 GLfloat a0, GLfloat a1, GLfloat a2, GLfloat a3, 00194 GLfloat d0, GLfloat d1, GLfloat d2, GLfloat d3, 00195 GLfloat s0, GLfloat s1, GLfloat s2, GLfloat s3, 00196 GLfloat p0, GLfloat p1, GLfloat p2, GLfloat p3 00197 ) 00198 { 00199 // Light Attributes 00200 GLfloat light_ambient[] = { a0, a1, a2, a3 }; 00201 GLfloat light_diffuse[] = { d0, d1, d2, d3 }; 00202 GLfloat light_specular[] = { s0, s1, s2, s3 }; 00203 GLfloat light_position[] = { p0, p1, p2, p3 }; 00204 00205 // Setup Light 00206 glLightfv( light, GL_AMBIENT, light_ambient ); 00207 glLightfv( light, GL_DIFFUSE, light_diffuse ); 00208 glLightfv( light, GL_SPECULAR, light_specular ); 00209 glLightfv( light, GL_POSITION, light_position ); 00210 00211 // Enable Light 00212 glEnable( light ); 00213 } 00214 //----------------------------------------------------------------------------- 00215 // Set the Light Ambient Property 00216 inline void SetLightAmbient( GLenum light, GLfloat r, GLfloat g, GLfloat b, GLfloat a ) 00217 { 00218 GLfloat v[] = { r, g, b, a }; 00219 glLightfv( light, GL_AMBIENT, v ); 00220 } 00221 //----------------------------------------------------------------------------- 00222 // Set the Light Diffuse Property 00223 inline void SetLightDiffuse( GLenum light, GLfloat r, GLfloat g, GLfloat b, GLfloat a ) 00224 { 00225 GLfloat v[] = { r, g, b, a }; 00226 glLightfv( light, GL_DIFFUSE, v ); 00227 } 00228 //----------------------------------------------------------------------------- 00229 // Set the Light Specular Property 00230 inline void SetLightSpecular( GLenum light, GLfloat r, GLfloat g, GLfloat b, GLfloat a ) 00231 { 00232 GLfloat v[] = { r, g, b, a }; 00233 glLightfv( light, GL_SPECULAR, v ); 00234 } 00235 //----------------------------------------------------------------------------- 00236 // Set the Light Position Property 00237 inline void SetLightPosition( GLenum light, GLfloat x, GLfloat y, GLfloat z, GLfloat w ) 00238 { 00239 GLfloat v[] = { x, y, z, w }; 00240 glLightfv( light, GL_POSITION, v ); 00241 } 00242 //----------------------------------------------------------------------------- 00243 // Set the Light Attenuation Property 00244 inline void SetLightAttenuation( GLenum light, 00245 GLfloat constant, GLfloat linear, GLfloat quadratic ) 00246 { 00247 glLightf( light, GL_CONSTANT_ATTENUATION, constant ); 00248 glLightf( light, GL_LINEAR_ATTENUATION, linear ); 00249 glLightf( light, GL_QUADRATIC_ATTENUATION, quadratic ); 00250 } 00251 //----------------------------------------------------------------------------- 00252 // Set the Light Spot Cutoff Property - spotlight cutoff angle 00253 // halfAngle is restricted to the range [0.0-90.0] in angles 00254 // OpenGL Default: 180.0 - i.e. the angle at the cone's apex is 360 degrees 00255 // means a light that radiates in all directions. 00256 inline void SetLightSpotCutoff( GLenum light, GLfloat halfAngle ) 00257 { 00258 glLightf( light, GL_SPOT_CUTOFF, halfAngle ); 00259 } 00260 //----------------------------------------------------------------------------- 00261 // Set the Light Spot Direction Property - direction of spotlight 00262 // OpenGL Default: (0,0,-1) 00263 inline void SetLightSpotDirection( GLenum light, GLfloat x, GLfloat y, GLfloat z ) 00264 { 00265 GLfloat v[] = { x, y, z }; 00266 glLightfv( light, GL_SPOT_DIRECTION, v ); 00267 } 00268 //----------------------------------------------------------------------------- 00269 // Set the Light Spot (Exponent) Attenuation Property - attenuated towards the egde 00270 // OpenGL Default: 0 00271 inline void SetLightSpotExponent( GLenum light, GLfloat exp ) 00272 { 00273 glLightf( light, GL_SPOT_EXPONENT, exp ); 00274 } 00275 //----------------------------------------------------------------------------- 00276 // Enable An OpenGL Light 00277 inline void EnableLight( GLenum light ) 00278 { 00279 glEnable( light ); 00280 } 00281 //----------------------------------------------------------------------------- 00282 // Disable An OpenGL Light 00283 inline void DisableLight( GLenum light ) 00284 { 00285 glDisable( light ); 00286 } 00287 //----------------------------------------------------------------------------- 00288 // Enable OpenGL Lighting with GL_SMOOTH Shading and GL_DEPTH_TEST 00289 // with GL_LIGHT_MODEL_TWO_SIDE option 00290 void EnableLightingWithTwoSide( bool twoSide ) 00291 { 00292 // Set lighting for one side or two sides. 00293 if ( twoSide ) glLightModeli( GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE ); 00294 else glLightModeli( GL_LIGHT_MODEL_TWO_SIDE, GL_FALSE ); 00295 // Start Using GL Light(s) 00296 glShadeModel( GL_SMOOTH ); 00297 glEnable( GL_LIGHTING ); 00298 glEnable( GL_DEPTH_TEST ); 00299 } 00300 //----------------------------------------------------------------------------- 00301 // Enable OpenGL Lighting with GL_SMOOTH Shading and GL_DEPTH_TEST 00302 // with GL_LIGHT_MODEL_TWO_SIDE option 00303 inline void EnableLightingWithOneSide( bool oneSide ) 00304 { 00305 EnableLightingWithTwoSide( !oneSide ); 00306 } 00307 //----------------------------------------------------------------------------- 00308 // Enable OpenGL Lighting 00309 inline void EnableLighting() { glEnable( GL_LIGHTING ); } 00310 //----------------------------------------------------------------------------- 00311 // Disable OpenGL Lighting 00312 inline void DisableLighting() { glDisable( GL_LIGHTING ); } 00313 //----------------------------------------------------------------------------- 00314 // Toggle OpenGL Lighting 00315 inline void ToggleLighting() 00316 { 00317 if ( glIsEnabled( GL_LIGHTING ) ) glDisable( GL_LIGHTING ); 00318 else glEnable ( GL_LIGHTING ); 00319 } 00320 //----------------------------------------------------------------------------- 00321 // Enable OpenGL Depth Test 00322 inline void EnableDepthTest() { glEnable( GL_DEPTH_TEST ); } 00323 //----------------------------------------------------------------------------- 00324 // Disable OpenGL Depth Test 00325 inline void DisableDepthTest() { glDisable( GL_DEPTH_TEST ); } 00326 //----------------------------------------------------------------------------- 00327 // Toggle OpenGL Depth Test 00328 inline void ToggleDepthTest() 00329 { 00330 if ( glIsEnabled( GL_DEPTH_TEST ) ) glDisable( GL_DEPTH_TEST ); 00331 else glEnable ( GL_DEPTH_TEST ); 00332 } 00333 //----------------------------------------------------------------------------- 00334 // END: OPENGL LIGHTING 00335 //============================================================================= 00336 00337 00338 //============================================================================= 00339 // START: OPENGL DRAWING 00340 //----------------------------------------------------------------------------- 00341 // Set Polygon Face Oriantation 00342 inline void SetFrontFaceCCW( bool b ) 00343 { 00344 if ( b ) glFrontFace( GL_CCW ); 00345 else glFrontFace( GL_CW ); 00346 } 00347 //----------------------------------------------------------------------------- 00348 // Set Polygon Face Oriantation 00349 inline void SetFrontFaceCW( bool b ) 00350 { 00351 SetFrontFaceCCW( !b ); 00352 } 00353 //----------------------------------------------------------------------------- 00354 // Toggle Polygon Face Oriantation: CCW <--> CW 00355 inline void ToggleFrontFaceOriantation() 00356 { 00357 GLint value; 00358 glGetIntegerv( GL_FRONT_FACE, &value ); 00359 if ( GL_CCW == value ) 00360 glEnable( GL_CW ); 00361 else 00362 glEnable( GL_CCW ); 00363 } 00364 //----------------------------------------------------------------------------- 00365 // Enable OpenGL Cull Face 00366 inline void EnableCullFace() { glEnable( GL_CULL_FACE ); } 00367 //----------------------------------------------------------------------------- 00368 // Disable OpenGL Cull Face 00369 inline void DisableCullFace() { glDisable( GL_CULL_FACE ); } 00370 //----------------------------------------------------------------------------- 00371 // Toggle OpenGL Cull Face 00372 inline void ToggleCullFace() 00373 { 00374 if ( glIsEnabled( GL_CULL_FACE ) ) glDisable( GL_CULL_FACE ); 00375 else glEnable ( GL_CULL_FACE ); 00376 } 00377 //----------------------------------------------------------------------------- 00378 // Set Drawing Mode 00379 // face (GLenum) can be 00380 // GL_FRONT_AND_BACK = 1032 00381 // GL_FRONT = 1028 00382 // GL_BACK = 1029 00383 // mode (GLenum) can be 00384 // GL_POINT = 6912 00385 // GL_LINE = 6913 00386 // GL_FILL = 6914 00387 inline void SetDrawingMode( GLenum face, GLenum mode ) 00388 { 00389 glPolygonMode( face, mode ); 00390 glCullFace( face ); 00391 glEnable( GL_CULL_FACE ); 00392 } 00393 //----------------------------------------------------------------------------- 00394 // Switch Drawing Mode 00395 // the drawing mode is switched circlely from 00396 // GL_POINT, GL_LINE, and GL_FILL 00397 void SwitchDrawingMode() 00398 { 00399 GLint DrawFaceAndMode[2]; 00400 glGetIntegerv( GL_POLYGON_MODE, DrawFaceAndMode ); 00401 switch ( DrawFaceAndMode[1] ) { 00402 case GL_POINT: 00403 DrawFaceAndMode[1] = GL_LINE; 00404 break; 00405 case GL_LINE: 00406 DrawFaceAndMode[1] = GL_FILL; 00407 break; 00408 case GL_FILL: 00409 DrawFaceAndMode[1] = GL_POINT; 00410 break; 00411 } 00412 glPolygonMode( DrawFaceAndMode[0], DrawFaceAndMode[1] ); 00413 00414 //++g_eDrawMode; 00415 //if ( g_eDrawMode > GL_FILL ) g_eDrawMode = GL_POINT; 00416 //glPolygonMode( g_eDrawFace, g_eDrawMode ); 00417 } 00418 //----------------------------------------------------------------------------- 00419 // Switch Draw Face Mode 00420 // the draw face mode is switched circlely from 00421 // GL_FRONT, GL_BACK, and GL_FRONT_AND_BACK 00422 void SwitchDrawFaceMode() 00423 { 00424 GLint DrawFaceAndMode[2]; 00425 glGetIntegerv( GL_POLYGON_MODE, DrawFaceAndMode ); 00426 switch ( DrawFaceAndMode[0] ) { 00427 case GL_FRONT: 00428 DrawFaceAndMode[0] = GL_BACK; 00429 break; 00430 case GL_BACK: 00431 DrawFaceAndMode[0] = GL_FRONT_AND_BACK; 00432 break; 00433 case GL_FRONT_AND_BACK: 00434 DrawFaceAndMode[0] = GL_FRONT; 00435 break; 00436 } 00437 glPolygonMode( DrawFaceAndMode[0], DrawFaceAndMode[1] ); 00438 00439 // if ( GL_FRONT == g_eCullFace ) g_eCullFace = GL_BACK; 00440 // else if ( GL_BACK == g_eCullFace ) g_eCullFace = GL_FRONT_AND_BACK; 00441 // else g_eCullFace = GL_FRONT; 00442 // glPolygonMode( g_eDrawFace, g_eDrawMode ); 00443 } 00444 //----------------------------------------------------------------------------- 00445 // Switch Cull Face Mode 00446 // the cull face mode is switched circlely from 00447 // GL_BACK, GL_FRONT, and GL_FRONT_AND_BACK 00448 void SwitchCullFaceMode() 00449 { 00450 GLint cullFace; 00451 glGetIntegerv( GL_CULL_FACE_MODE, &cullFace ); 00452 switch ( cullFace ) { 00453 case GL_FRONT: 00454 cullFace = GL_BACK; 00455 break; 00456 case GL_BACK: 00457 cullFace = GL_FRONT_AND_BACK; 00458 break; 00459 case GL_FRONT_AND_BACK: 00460 cullFace = GL_FRONT; 00461 break; 00462 } 00463 glCullFace( cullFace ); 00464 00465 // if ( GL_BACK == g_eCullFace ) g_eCullFace = GL_FRONT; 00466 // else if ( GL_FRONT == g_eCullFace ) g_eCullFace = GL_FRONT_AND_BACK; 00467 // else g_eCullFace = GL_BACK; 00468 // glCullFace( g_eCullFace ); 00469 } 00470 //----------------------------------------------------------------------------- 00471 // END: OPENGL DRAWING 00472 //============================================================================= 00473 00474 00475 //============================================================================= 00476 // STRART: OPENGL VIEWING 00477 //----------------------------------------------------------------------------- 00478 //----------------------------------------------------------------------------- 00479 // END: OPENGL VIEWING 00480 //============================================================================= 00481 00482 //============================================================================= 00483 // START: SHADOW FUNCTIONS 00484 //----------------------------------------------------------------------------- 00485 // Create a shadow projection matrix out of the plane equation 00486 // lightPos ==> { xPos, yPos, zPos, 1 } 00487 // planeEqn ==> a*x + b*y + c*z + d = 0 00488 template <typename T> 00489 Matrix4x4<T> CalShadowProjectionMatrix ( Vector4<T> const &lightPos, Vector4<T> const &planeEqn ) 00490 { 00491 T dot = planeEqn*lightPos; 00492 return Matrix4x4<T> ( 00493 dot - lightPos[0]*planeEqn[0], 00494 dot - lightPos[0]*planeEqn[1], 00495 dot - lightPos[0]*planeEqn[2], 00496 dot - lightPos[0]*planeEqn[3], 00497 dot - lightPos[1]*planeEqn[0], 00498 dot - lightPos[1]*planeEqn[1], 00499 dot - lightPos[1]*planeEqn[2], 00500 dot - lightPos[1]*planeEqn[3], 00501 dot - lightPos[2]*planeEqn[0], 00502 dot - lightPos[2]*planeEqn[1], 00503 dot - lightPos[2]*planeEqn[2], 00504 dot - lightPos[2]*planeEqn[3], 00505 dot - lightPos[3]*planeEqn[0], 00506 dot - lightPos[3]*planeEqn[1], 00507 dot - lightPos[3]*planeEqn[2], 00508 dot - lightPos[3]*planeEqn[3] 00509 ); 00510 } 00511 //----------------------------------------------------------------------------- 00512 // END: SHADOW FUNCTIONS 00513 //============================================================================= 00514 00515 //============================================================================= 00516 // START: TEXT FUNCTIONS 00517 //----------------------------------------------------------------------------- 00518 // Generate Text 00519 void GenerateScreenText( Enum::GLUT textStyle ) 00520 { 00521 //std::cout << "GenerateScreenText\n"; 00522 00523 if ( g_uiGLFontDisplayList == 0 ) { 00524 void * ptr = NULL; 00525 switch (textStyle) { 00526 case Enum::BITMAP_9_BY_15: 00527 ptr = GLUT_BITMAP_9_BY_15; 00528 break; 00529 case Enum::BITMAP_8_BY_13: 00530 ptr = GLUT_BITMAP_8_BY_13; 00531 break; 00532 case Enum::BITMAP_TIMES_ROMAN_10: 00533 ptr = GLUT_BITMAP_TIMES_ROMAN_10; 00534 break; 00535 case Enum::BITMAP_TIMES_ROMAN_24: 00536 ptr = GLUT_BITMAP_TIMES_ROMAN_24; 00537 break; 00538 case Enum::BITMAP_HELVETICA_10: 00539 ptr = GLUT_BITMAP_HELVETICA_10; 00540 break; 00541 case Enum::BITMAP_HELVETICA_12: 00542 ptr = GLUT_BITMAP_HELVETICA_12; 00543 break; 00544 case Enum::BITMAP_HELVETICA_18: 00545 ptr = GLUT_BITMAP_HELVETICA_18; 00546 break; 00547 default: 00548 ptr = GLUT_BITMAP_9_BY_15; 00549 } 00550 int baseSize = 256; 00551 //int base = glGenLists( baseSize ); // font list base 00552 g_uiGLFontDisplayList = glGenLists( baseSize ); // font list base 00553 // generate fonts 00554 for ( int i = 0; i < 256; ++i ) { 00555 //glNewList(base+i, GL_COMPILE); 00556 glNewList(g_uiGLFontDisplayList+i, GL_COMPILE); 00557 glutBitmapCharacter(ptr, i); 00558 glEndList(); 00559 } 00560 //glListBase(base); 00561 } 00562 } 00563 //----------------------------------------------------------------------------- 00564 // Draw Text at the current raster position 00565 //inline void DrawGLText( char const * const str ) 00566 //{ 00567 // if ( g_uiGLFontDisplayList == 0 ) { 00568 // GenerateScreenText( Enum::BITMAP_9_BY_15 ); 00569 // } 00570 // glListBase( g_uiGLFontDisplayList ); 00571 // glCallLists( static_cast<GLsizei>(strlen(str)) , GL_BYTE, str ); 00572 //} 00573 //----------------------------------------------------------------------------- 00574 // Draw Text at the position 00575 //inline void DrawGLText( char const * const str, GLfloat const pos[] ) 00576 //{ DrawGLText( str, pos[0], pos[1], pos[2] ); } 00577 //----------------------------------------------------------------------------- 00578 // Draw Text at the position 00579 //inline void DrawGLText( char const * const str, GLfloat x, GLfloat y, GLfloat z ) 00580 //{ 00581 // glRasterPos3f( x, y, z ); 00582 // DrawGLText( str ); 00583 //} 00584 //----------------------------------------------------------------------------- 00585 // Draw Text at the position 00586 //inline void DrawGLText( char const * const str, GLint x, GLint y, GLint z ) 00587 //{ 00588 // glRasterPos3i( x, y, z ); 00589 // DrawGLText( str ); 00590 //} 00591 //----------------------------------------------------------------------------- 00592 // END: TEXT FUNCTIONS 00593 //============================================================================= 00594 00595 //============================================================================= 00596 // START: DRAW OBJECTs 00597 //----------------------------------------------------------------------------- 00598 // Draw a line from P1 to P2 00599 void Draw3DLine ( const GLfloat x1, const GLfloat y1, const GLfloat z1, 00600 const GLfloat x2, const GLfloat y2, const GLfloat z2 ) 00601 { 00602 glBegin( GL_LINES ); 00603 glVertex3f( x1, y1, z1 ); 00604 glVertex3f( x2, y2, z2 ); 00605 glEnd(); 00606 } 00607 void Draw3DLine ( GLfloat const * const p1, GLfloat const * const p2 ) 00608 { 00609 glBegin( GL_LINES ); 00610 glVertex3fv( p1 ); 00611 glVertex3fv( p2 ); 00612 glEnd(); 00613 } 00614 void Draw3DLine ( const Vector3<GLint> P1, const Vector3<GLint> P2 ) 00615 { 00616 glBegin( GL_LINES ); 00617 glVertex3i( P1[0], P1[1], P1[2] ); 00618 glVertex3i( P2[0], P2[1], P2[2] ); 00619 glEnd(); 00620 } 00621 void Draw3DLine ( const Vector3<GLfloat> P1, const Vector3<GLfloat> P2 ) 00622 { 00623 glBegin( GL_LINES ); 00624 glVertex3f( P1[0], P1[1], P1[2] ); 00625 glVertex3f( P2[0], P2[1], P2[2] ); 00626 glEnd(); 00627 } 00628 void Draw3DLine ( const Vector3<GLdouble> P1, const Vector3<GLdouble> P2 ) 00629 { 00630 glBegin( GL_LINES ); 00631 glVertex3d( P1[0], P1[1], P1[2] ); 00632 glVertex3d( P2[0], P2[1], P2[2] ); 00633 glEnd(); 00634 } 00635 //----------------------------------------------------------------------------- 00636 // END: DRAW OBJECTs 00637 //============================================================================= 00638 00639 //============================================================================= 00640 // STRART: QUADRICS OBJECTS BY GLU ROUTINES 00641 //----------------------------------------------------------------------------- 00642 GLUquadricObj * NewGLUQuardic () 00643 { 00644 GLUquadricObj * qObj = gluNewQuadric(); 00645 #ifdef TAPs_DEBUG_ENABLE 00646 if ( !qObj ) { 00647 std::cerr << "Warning: GLUquadricObj cannot be created!\n"; 00648 return qObj; 00649 } 00650 #endif 00651 //gluQuadricCallback( qObj, GLU_ERROR, ErrorCallBack); 00652 gluQuadricDrawStyle( qObj, GLU_FILL ); // smooth shaded 00653 gluQuadricNormals( qObj, GLU_SMOOTH ); 00654 return qObj; 00655 } 00656 void DeleteGLUQuardic ( GLUquadricObj *qObj ) 00657 { 00658 gluDeleteQuadric( qObj ); 00659 } 00660 void ErrorCallBack ( GLenum errCode ) 00661 { 00662 const GLubyte *errStr = gluErrorString( errCode ); 00663 std::cerr << "Quadric Error: " << errStr << "!" << std::endl; 00664 exit(1); 00665 } 00666 //----------------------------------------------------------------------------- 00667 // END: QUADRICS OBJECTS BY GLU ROUTINES 00668 //============================================================================= 00669 00670 //============================================================================= 00671 END_NAMESPACE_TAPs__OpenGL__Fn 00672 //----------------------------------------------------------------------------- 00673 //345678901234567890123456789012345678901234567890123456789012345678901234567890 00674 //--+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8