![]() |
TAPs 0.7.7.3
|
00001 /****************************************************************************** 00002 TAPsOpenGLFns.hpp 00003 00004 Global OpenGL Functions in TAPs::OpenGL::Fn namespace 00005 00006 SUKITTI PUNAK (10/04/2004) 00007 UPDATE (11/03/2006) 00008 ******************************************************************************/ 00009 #ifndef TAPs_OPENGL_FNS_HPP 00010 #define TAPs_OPENGL_FNS_HPP 00011 00012 #include "TAPsOpenGLEnumList.hpp" 00013 #include "../Core/TAPsLib.hpp" 00014 00015 #ifdef TAPs_USE_WXWIDGETS 00016 #include "wx/wx.h" 00017 #endif 00018 00019 BEGIN_NAMESPACE_TAPs__OpenGL__Fn 00020 //============================================================================= 00021 // START: OPENGL DEBUG/ERROR 00022 //----------------------------------------------------------------------------- 00023 // Check OpenGL Error 00032 //#ifdef TAPs_DEBUG_MODE 00033 void GFnCheckGLError ( char * file, int line, int * glErrCode = NULL ); 00034 //#else 00035 // void GFnCheckGLError ( char *file, int line, int * glErrCode = NULL ); 00036 //#endif 00037 #define CHECK_GL_ERROR() GFnCheckGLError( __FILE__, __LINE__ ) 00038 //----------------------------------------------------------------------------- 00039 // Check OpenGL Error with Custom Message 00051 //#ifdef TAPs_DEBUG_MODE 00052 void GFnCheckGLError ( char * customMessage, int * glErrCode = NULL ); 00053 //#else 00054 // void GFnCheckGLError ( char * customMessage, int * glErrCode = NULL ); 00055 //#endif 00056 #define CHECK_GL_ERROR_MESSAGE( s ) GFnCheckGLError( s ) 00057 //----------------------------------------------------------------------------- 00058 // Check OpenGL Frame Buffer Status 00067 #ifdef TAPs_DEBUG_MODE 00068 //#ifdef TAPs_USE_GLSL 00069 void GFnCheckFrameBufferStatus (); 00070 //#else 00071 // void GFnCheckFrameBufferStatus (); 00072 //#endif 00073 #else 00074 void GFnCheckFrameBufferStatus (); 00075 #endif 00076 #define CHECK_FRAMEBUFFER_STATUS() GFnCheckFrameBufferStatus() 00077 //----------------------------------------------------------------------------- 00078 // END: OPENGL DEBUG/ERROR 00079 //============================================================================= 00080 00081 //============================================================================= 00082 // START: OPENGL LIGHTING 00083 //----------------------------------------------------------------------------- 00084 // Initialize and Enable the Light (with the Default Values) 00085 // The light is a GLenum, which can be (at least 8 lights) from 00086 // GL_LIGHT0, GL_LIGHT1,..., or GL_LIGHT7. 00087 void InitializeLight( GLenum light, 00088 GLfloat a0 = 1.0, GLfloat a1 = 1.0, GLfloat a2 = 1.0, GLfloat a3 = 1.0, 00089 GLfloat d0 = 1.0, GLfloat d1 = 1.0, GLfloat d2 = 1.0, GLfloat d3 = 1.0, 00090 GLfloat s0 = 1.0, GLfloat s1 = 1.0, GLfloat s2 = 1.0, GLfloat s3 = 1.0, 00091 GLfloat p0 = 0.0, GLfloat p1 = 0.0, GLfloat p2 = 10.0, GLfloat p3 = 1.0 00092 ); 00093 //----------------------------------------------------------------------------- 00094 // Set the Light Ambient Property 00095 // OpenGL Default: (0,0,0,1) 00096 inline void SetLightAmbient( GLenum light, GLfloat r, GLfloat g, GLfloat b, GLfloat a ); 00097 //----------------------------------------------------------------------------- 00098 // Set the Light Diffuse Property 00099 // OpenGL Default: (1,1,1,1) for GL_LIGHT0 and (0,0,0,1) for other lights 00100 inline void SetLightDiffuse( GLenum light, GLfloat r, GLfloat g, GLfloat b, GLfloat a ); 00101 //----------------------------------------------------------------------------- 00102 // Set the Light Specular Property 00103 // OpenGL Default: (1,1,1,1) for GL_LIGHT0 and (0,0,0,1) for other lights 00104 inline void SetLightSpecular( GLenum light, GLfloat r, GLfloat g, GLfloat b, GLfloat a ); 00105 //----------------------------------------------------------------------------- 00106 // Set the Light Position Property 00107 // OpenGL Default: (0,0,1,0) <=> (x,y,z,w) -- means a DIRECTIONAL light 00108 // (a light at infinity) 00109 // If w component is not zero, the light is a POSITIONAL light. 00110 inline void SetLightPosition( GLenum light, GLfloat x, GLfloat y, GLfloat z, GLfloat w ); 00111 //----------------------------------------------------------------------------- 00112 // Set the Light Attenuation Property 00113 // OpenGL Default: 1.0 - GL_CONSTANT_ATTENUATION 00114 // 0.0 - GL_LINEAR_ATTENUATION 00115 // 0.0 - GL_QUADRATIC_ATTENUATION 00116 inline void SetLightAttenuation( GLenum light, 00117 GLfloat constant, GLfloat linear, GLfloat quadratic ); 00118 //----------------------------------------------------------------------------- 00119 // Set the Light Spot Cutoff Property - SPOTLIGHT cutoff angle 00120 // halfAngle is restricted to the range [0.0-90.0] in angles 00121 // OpenGL Default: 180.0 - i.e. the angle at the cone's apex is 360 degrees 00122 // means a light that radiates in all directions. 00123 inline void SetLightSpotCutoff( GLenum light, GLfloat halfAngle ); 00124 //----------------------------------------------------------------------------- 00125 // Set the Light Spot Direction Property - direction of spotlight 00126 // OpenGL Default: (0,0,-1) 00127 inline void SetLightSpotDirection( GLenum light, GLfloat x, GLfloat y, GLfloat z ); 00128 //----------------------------------------------------------------------------- 00129 // Set the Light Spot (Exponent) Attenuation Property - attenuated towards the egde 00130 // OpenGL Default: 0 00131 inline void SetLightSpotExponent( GLenum light, GLfloat exp ); 00132 //----------------------------------------------------------------------------- 00133 // Enable An OpenGL Light 00134 inline void EnableLight( GLenum light ); 00135 //----------------------------------------------------------------------------- 00136 // Disable An OpenGL Light 00137 inline void DisableLight( GLenum light ); 00138 //----------------------------------------------------------------------------- 00139 // Enable OpenGL Lighting with GL_SMOOTH Shading 00140 void EnableLightingWithTwoSide( bool twoSide = true ); 00141 //----------------------------------------------------------------------------- 00142 // Enable OpenGL Lighting with GL_SMOOTH Shading 00143 inline void EnableLightingWithOneSide( bool oneSide = true ); 00144 //----------------------------------------------------------------------------- 00145 // Enable OpenGL Lighting 00146 inline void EnableLighting(); 00147 //----------------------------------------------------------------------------- 00148 // Disable OpenGL Lighting 00149 inline void DisableLighting(); 00150 //----------------------------------------------------------------------------- 00151 // Toggle OpenGL Lighting 00152 inline void ToggleLighting(); 00153 //----------------------------------------------------------------------------- 00154 // Enable OpenGL Depth Test 00155 inline void EnableDepthTest(); 00156 //----------------------------------------------------------------------------- 00157 // Disable OpenGL Depth Test 00158 inline void DisableDepthTest(); 00159 //----------------------------------------------------------------------------- 00160 // Toggle OpenGL Depth Test: On <--> Off 00161 inline void ToggleDepthTest(); 00162 //----------------------------------------------------------------------------- 00163 // END: OPENGL LIGHTING 00164 //============================================================================= 00165 00166 00167 //============================================================================= 00168 // START: OPENGL DRAWING 00169 //----------------------------------------------------------------------------- 00170 // Set Polygon Face Oriantation with CCW 00171 inline void SetFrontFaceCCW( bool = true ); 00172 //----------------------------------------------------------------------------- 00173 // Set Polygon Face Oriantation with CW 00174 inline void SetFrontFaceCW( bool = true ); 00175 //----------------------------------------------------------------------------- 00176 // Toggle Polygon Face Oriantation: CCW <--> CW 00177 inline void ToggleFrontFaceOriantation(); 00178 //----------------------------------------------------------------------------- 00179 // Enable OpenGL Cull Face 00180 inline void EnableCullFace(); 00181 //----------------------------------------------------------------------------- 00182 // Disable OpenGL Cull Face 00183 inline void DisableCullFace(); 00184 //----------------------------------------------------------------------------- 00185 // Toggle OpenGL Cull Face 00186 inline void ToggleCullFace(); 00187 //----------------------------------------------------------------------------- 00188 // Set Drawing Mode 00189 // face (GLenum) can be 00190 // GL_FRONT_AND_BACK = 1032 00191 // GL_FRONT = 1028 00192 // GL_BACK = 1029 00193 // mode (GLenum) can be 00194 // GL_POINT = 6912 00195 // GL_LINE = 6913 00196 // GL_FILL = 6914 00197 inline void SetDrawingMode( GLenum face, GLenum mode ); 00198 //----------------------------------------------------------------------------- 00199 // Switch Drawing Mode 00200 // the drawing mode is switched circularly from 00201 // GL_POINT, GL_LINE, and GL_FILL 00202 void SwitchDrawingMode(); 00203 //----------------------------------------------------------------------------- 00204 // Switch Draw Face Mode 00205 // the draw face mode is switched circularly from 00206 // GL_FRONT, GL_BACK, and GL_FRONT_AND_BACK 00207 void SwitchDrawFaceMode(); 00208 //----------------------------------------------------------------------------- 00209 // Switch Cull Face Mode 00210 // the cull face mode is switched circularly from 00211 // GL_BACK, GL_FRONT, and GL_FRONT_AND_BACK 00212 void SwitchCullFaceMode(); 00213 //----------------------------------------------------------------------------- 00214 // END: OPENGL DRAWING 00215 //============================================================================= 00216 00217 00218 00219 00220 //============================================================================= 00221 // START: OPENGL VIEWING 00222 //----------------------------------------------------------------------------- 00223 /* 00224 // Reshape Orthogonal Viewing 00225 void ReshapeOrthogonal(int w, int h) 00226 { 00227 glViewport(0, 0, w, h); 00228 glMatrixMode(GL_PROJECTION); 00229 glLoadIdentity(); 00230 if (w <= h) 00231 glOrtho(-20.0, 20.0, -20.0 * (GLfloat) h / (GLfloat) w, 00232 20.0 * (GLfloat) h / (GLfloat) w, -100.0, 100.0); 00233 else 00234 glOrtho(-20.0 * (GLfloat) w / (GLfloat) h, 00235 20.0 * (GLfloat) w / (GLfloat) h, -20.0, 20.0, -100.0, 100.0); 00236 glMatrixMode(GL_MODELVIEW); 00237 00238 glutReshapeFunc(ReshapeOrthogonal); // set the reshape fn 00239 } 00240 //----------------------------------------------------------------------------- 00241 // Reshape Orthogonal Viewing 00242 void ReshapePerspectiveViewing(int w, int h) 00243 { 00244 glViewport(0, 0, w, h); 00245 glMatrixMode(GL_PROJECTION); 00246 glLoadIdentity(); 00247 if (w <= h) 00248 glOrtho(-20.0, 20.0, -20.0 * (GLfloat) h / (GLfloat) w, 00249 20.0 * (GLfloat) h / (GLfloat) w, -100.0, 100.0); 00250 else 00251 glOrtho(-20.0 * (GLfloat) w / (GLfloat) h, 00252 20.0 * (GLfloat) w / (GLfloat) h, -20.0, 20.0, -100.0, 100.0); 00253 glMatrixMode(GL_MODELVIEW); 00254 } 00255 */ 00256 //----------------------------------------------------------------------------- 00257 // END: OPENGL VIEWING 00258 //============================================================================= 00259 00260 //============================================================================= 00261 // START: SHADOW FUNCTIONS 00262 //----------------------------------------------------------------------------- 00263 // Create a shadow projection matrix out of the plane equation 00264 // lightPos ==> { xPos, yPos, zPos, 1 } 00265 // planeEqn ==> a*x + b*y + c*z + d = 0 00266 template <typename T> 00267 Matrix4x4<T> CalShadowProjectionMatrix ( Vector4<T> const &lightPos, Vector4<T> const &planeEqn ); 00268 //----------------------------------------------------------------------------- 00269 // END: SHADOW FUNCTIONS 00270 //============================================================================= 00271 00272 //============================================================================= 00273 // START: TEXT FUNCTIONS 00274 //----------------------------------------------------------------------------- 00275 // Generate Text 00276 // Enum::GLUT created to match Bitmap font constants in "glut.h" 00277 // BITMAP_9_BY_15, 00278 // BITMAP_8_BY_13, 00279 // BITMAP_TIMES_ROMAN_10, 00280 // BITMAP_TIMES_ROMAN_24, 00281 // BITMAP_HELVETICA_10, 00282 // BITMAP_HELVETICA_12, 00283 // BITMAP_HELVETICA_18 00284 00285 //extern GLuint g_uiGLFontDisplayList; 00286 GLuint GetGLFontDisplayList (); //{ return g_uiGLFontDisplayList; } 00287 00288 void GenerateScreenText( Enum::GLUT = Enum::BITMAP_9_BY_15 ); 00289 //----------------------------------------------------------------------------- 00290 // Draw Text at the current raster position 00291 inline void DrawGLText( char const * const str ) 00292 { 00293 //std::cout << "DrawGLText\n"; 00294 00295 if ( GetGLFontDisplayList() == 0 ) { 00296 GenerateScreenText( Enum::BITMAP_9_BY_15 ); 00297 } 00298 glListBase( GetGLFontDisplayList() ); 00299 glCallLists( static_cast<GLsizei>(strlen(str)) , GL_BYTE, str ); 00300 } 00301 inline void DrawGLText( std::string str ) 00302 { DrawGLText( str.c_str() ); } 00303 //----------------------------------------------------------------------------- 00304 // Draw Text at the position 00305 inline void DrawGLText( char const * const str, GLfloat x, GLfloat y, GLfloat z = 0.0f ) 00306 { 00307 glRasterPos3f( x, y, z ); 00308 DrawGLText( str ); 00309 } 00310 inline void DrawGLText( std::string str, GLfloat x, GLfloat y, GLfloat z = 0.0f ) 00311 { DrawGLText( str.c_str(), x, y, z ); } 00312 //----------------------------------------------------------------------------- 00313 // Draw Text at the position 00314 inline void DrawGLText( char const * const str, GLfloat const pos[] ) 00315 { DrawGLText( str, pos[0], pos[1], pos[2] ); } 00316 inline void DrawGLText( std::string str, GLfloat const pos[] ) 00317 { DrawGLText( str.c_str(), pos ); } 00318 //----------------------------------------------------------------------------- 00319 // Draw Text at the position 00320 //inline void DrawGLText( char const * const str, GLint x, GLint y, GLint z = 0 ); 00321 //----------------------------------------------------------------------------- 00322 // END: TEXT FUNCTIONS 00323 //============================================================================= 00324 00325 //============================================================================= 00326 // START: DRAW OBJECTs 00327 //----------------------------------------------------------------------------- 00328 // Draw a line from P1 to P2 00329 void Draw3DLine ( const GLfloat x1, const GLfloat y1, const GLfloat z1, 00330 const GLfloat x2, const GLfloat y2, const GLfloat z2 ); 00331 void Draw3DLine ( GLfloat const * const p1, GLfloat const * const p2 ); 00332 void Draw3DLine ( const Vector3<GLint> P1, const Vector3<GLint> P2 ); 00333 void Draw3DLine ( const Vector3<GLfloat> P1, const Vector3<GLfloat> P2 ); 00334 void Draw3DLine ( const Vector3<GLdouble> P1, const Vector3<GLdouble> P2 ); 00335 //----------------------------------------------------------------------------- 00336 // END: DRAW OBJECTs 00337 //============================================================================= 00338 00339 //============================================================================= 00340 // STRART: QUADRICS OBJECTS BY GLU ROUTINES 00341 //----------------------------------------------------------------------------- 00342 GLUquadricObj * NewGLUQuardic (); // *obj is NULL, if creation is fail 00343 void DeleteGLUQuardic ( GLUquadricObj *qObj ); 00344 void ErrorCallBack ( GLenum errorCode ); 00345 //----------------------------------------------------------------------------- 00346 // END: QUADRICS OBJECTS BY GLU ROUTINES 00347 //============================================================================= 00348 00349 //============================================================================= 00350 END_NAMESPACE_TAPs__OpenGL__Fn 00351 //----------------------------------------------------------------------------- 00352 // Include definition if TAPs_USE_EXPORT is not defined 00353 #if !defined( TAPs_USE_EXPORT ) 00354 #include "TAPsOpenGLFns.cpp" 00355 #endif 00356 //----------------------------------------------------------------------------- 00357 #endif 00358 //345678901234567890123456789012345678901234567890123456789012345678901234567890 00359 //--+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8