![]() |
TAPs 0.7.7.3
|
00001 /****************************************************************************** 00002 TAPsOpenGLSupport.hpp 00003 00004 Design as a base class for OpenGL Drawing and Properties of inherited class. 00005 It contains texture and material properties. 00006 00007 SUKITTI PUNAK (09/16/2004) 00008 UPDATE (11/01/2004) 00009 ******************************************************************************/ 00010 #ifndef TAPs_OPENGL_SUPPORT_HPP 00011 #define TAPs_OPENGL_SUPPORT_HPP 00012 00013 #include <iostream> 00014 #include "TAPsOpenGLMaterial.hpp" 00015 #include "../ImageHandler/TAPsBitmapImageHandler.hpp" // bitmap image handler 00016 #include "../ImageHandler/TAPsTargaImageHandler.hpp" // targa image handler 00017 00018 // Render by GLSL ------------------------------------------------------------- 00019 #ifdef TAPs_RENDER_BY_GLSL_DS_FACE_VERTEX 00020 //#include "../GLSL/TAPsGLSLShaderPool.hpp" 00021 #include "../GLSL/TAPsGlobalGLSLShaderPool.hpp" 00022 //TAPs::OpenGL::GLSLShaderPool GLOBAL_ShaderPool; 00023 #endif//TAPs_RENDER_BY_GLSL_DS_FACE_VERTEX 00024 // ---------------------------------------------------------------------------- 00025 00026 BEGIN_NAMESPACE_TAPs__OpenGL 00027 //============================================================================= 00028 class OpenGLSupport { 00029 //============================================================================= 00030 // Friend Fn(s) ============================================================ 00031 //------------------------------------------------------------------------- 00032 // put it through ostream 00033 friend std::ostream & operator<< ( std::ostream &output, OpenGLSupport const &o ); 00034 //----------------------------------------------------------------------------- 00035 // Data Members ======================================================== 00036 protected: 00037 char * m_acImageFileName; // image file name 00038 GLuint texName[1]; // texture data 00039 public: 00040 //------------------------------------------------------------------------- 00042 BitmapImage *m_pcImg; 00043 TargaImage *m_pcImg2; 00044 00046 Material material; 00047 00049 #ifdef TAPs_SUPPORT_ASE_FORMAT 00050 std::vector< Material * > submaterials; 00051 #endif//TAPs_SUPPORT_ASE_FORMAT 00052 00053 public: 00054 //------------------------------------------------------------------------- 00055 // Get/Set Fn(s) 00056 inline void SetFacetShading( bool b ) { isFacetShading = b; } 00057 inline bool GetFacetShading() { return isFacetShading; } 00058 //------------------------------------------------------------------------- 00059 protected: 00060 bool isFacetShading; // should be used with DisplayGL fn below 00061 //----------------------------------------------------------------------------- 00062 public: 00063 // Helper Functions ==================================================== 00064 void EnableTexture( GLuint & texName ); 00065 //void GenerateTexture(); 00066 void EnableTexture(); 00067 //----------------------------------------------------------------------------- 00068 public: 00069 // Member Functions ==================================================== 00070 //OpenGLSupport (); 00071 OpenGLSupport ( BitmapImage * = NULL, TargaImage * = NULL ); // constructor 00072 OpenGLSupport ( TargaImage * ); // constructor 00073 virtual ~OpenGLSupport (); // destructor 00074 //------------------------------------------------------------------------- 00075 // To make the material affects the drawing, 00076 // this fn has to be called before drawing. 00077 inline void ApplyMaterial ( Enum::Face f = Enum::FRONT ) 00078 { material.ApplyMaterial( f ); } 00079 // This fn set the material property to the material parameter, 00080 // but does not apply the material. 00081 inline void SetMaterial ( Enum::MaterialType mt = Enum::CURRENT_MAT ) 00082 { material.SetMaterial( mt ); } 00083 //------------------------------------------------------------------------- 00084 // This fn must be called inside the DisplayGL() 00085 virtual void DrawTexture (); 00086 // Draw this 2-D image at a raster position 00087 void DrawImage1 ( Real x = 0, Real y = 0, Real z = 0 ); 00088 // Draw this 2-D image at a raster position 00089 void DrawImage2 ( Real x = 0, Real y = 0, Real z = 0 ); 00090 //------------------------------------------------------------------------- 00091 // Get/Set Fn(s) 00092 inline Material * const GetMaterial () { return &material; } 00093 char const * const GetImageFileName () const; 00094 void SetImageFileName ( char * fileName ); 00095 //------------------------------------------------------------------------- 00096 // Display By OpenGL 00097 virtual void DisplayGL ( OpenGL::Enum::DrawMode DM = OpenGL::Enum::POLYGON ) = 0; 00098 virtual void DisplayGLFaceRange ( 00099 int startFace, int endFace, 00100 OpenGL::Enum::DrawMode DM = OpenGL::Enum::POLYGON ) 00101 {} //{ DisplayGL( DM ); } 00102 00103 00104 #ifdef TAPs_ENABLE_FACE_VERTEX_COLOR 00105 00108 bool IsVertexColorsEnabled () const { return m_bEnableVertexColor; }; 00109 00113 int GetDimensionOfVertexColors () const { return static_cast<int>( m_uiVertexColorDimension ); }; 00114 00119 // SHOULD BE PURE VIRTUAL FN!!! 00120 virtual bool EnableVertexColors ( bool b ) { m_bEnableVertexColor = false; return false; } 00121 00122 // The codes below should be included in a class extended from this OpenGLSupport class. 00123 //#ifdef TAPs_ENABLE_FACE_VERTEX_COLOR 00124 //public: 00125 // virtual bool EnableVertexColors ( bool b ); 00126 //#endif//TAPs_ENABLE_FACE_VERTEX_COLOR 00127 00128 //#ifdef TAPs_ENABLE_FACE_VERTEX_COLOR 00129 //protected: 00130 // virtual void DrawGLWithFaceVertexColor_RGB ( GLenum ); 00131 // virtual void DrawGLWithFaceVertexColor_RGBA ( GLenum ); 00132 //#endif//TAPs_ENABLE_FACE_VERTEX_COLOR 00133 00134 #endif//TAPs_ENABLE_FACE_VERTEX_COLOR 00135 00136 00137 #ifdef TAPs_ENABLE_FACE_VERTEX_TEXTURE_COORDINATES 00138 00141 bool IsVertexTexturesEnabled () const { return m_bEnableVertexTexture; }; 00142 00146 int GetDimensionOfVertexTextures () const { return static_cast<int>( m_uiVertexTextureDimension ); }; 00147 00152 // SHOULD BE PURE VIRTUAL FN!!! 00153 virtual bool EnableVertexTextures ( bool b ) { m_bEnableVertexTexture = false; return false; } 00154 00155 // The codes below should be included in a class extended from this OpenGLSupport class. 00156 //#ifdef TAPs_ENABLE_FACE_VERTEX_TEXTURE_COORDINATES 00157 //public: 00158 // virtual bool EnableVertexTextures ( bool b ); 00159 //#endif//TAPs_ENABLE_FACE_VERTEX_TEXTURE_COORDINATES 00160 00161 //#ifdef TAPs_ENABLE_FACE_VERTEX_TEXTURE_COORDINATES 00162 //protected: 00163 // virtual void DrawGLWithFaceVertexTexture_S ( GLenum ); 00164 // virtual void DrawGLWithFaceVertexTexture_ST ( GLenum ); 00165 // virtual void DrawGLWithFaceVertexTexture_STR ( GLenum ); 00166 //#endif//TAPs_ENABLE_FACE_VERTEX_TEXTURE_COORDINATES 00167 00168 #endif//TAPs_ENABLE_FACE_VERTEX_TEXTURE_COORDINATES 00169 00170 00171 // Render by GLSL ------------------------------------------------------------- 00172 #ifdef TAPs_RENDER_BY_GLSL_DS_FACE_VERTEX 00173 GlobalGLSLShaderPool::SHADER ShaderName; 00174 // Set of parameters for shader program 00175 // ... 00176 #endif//TAPs_RENDER_BY_GLSL_DS_FACE_VERTEX 00177 // ---------------------------------------------------------------------------- 00178 00179 protected: 00180 //------------------------------------------------------------------------- 00181 // Pure Virtual Fns 00182 // Helper Fn 00183 // void DrawGL() 00184 virtual void DrawGL ( GLenum ) = 0; 00185 00186 #ifdef TAPs_ENABLE_FACE_VERTEX_COLOR 00187 virtual void DrawGLWithFaceVertexColor_RGB ( GLenum drawMode ) { DrawGL( drawMode ); } 00188 virtual void DrawGLWithFaceVertexColor_RGBA ( GLenum drawMode ) { DrawGL( drawMode ); } 00189 00190 bool m_bEnableVertexColor; 00191 unsigned int m_uiVertexColorDimension; 00192 #endif//TAPs_ENABLE_FACE_VERTEX_COLOR 00193 00194 #ifdef TAPs_ENABLE_FACE_VERTEX_TEXTURE_COORDINATES 00195 virtual void DrawGLWithFaceVertexTexture_RGB ( GLenum drawMode ) { DrawGL( drawMode ); } 00196 virtual void DrawGLWithFaceVertexTexture_RGBA ( GLenum drawMode ) { DrawGL( drawMode ); } 00197 00198 bool m_bEnableVertexTexture; 00199 unsigned int m_uiVertexTextureDimension; 00200 #endif//TAPs_ENABLE_FACE_VERTEX_TEXTURE_COORDINATES 00201 00202 // Render by GLSL ------------------------------------------------------------- 00203 #ifdef TAPs_RENDER_BY_GLSL_DS_FACE_VERTEX 00204 virtual void DrawGLSLWithDSFaceVertex_RGB ( GLenum drawMode ) { DrawGL( drawMode ); } 00205 virtual void DrawGLSLWithDSFaceVertex_RGBA ( GLenum drawMode ) { DrawGL( drawMode ); } 00206 #endif//TAPs_RENDER_BY_GLSL_DS_FACE_VERTEX 00207 // ---------------------------------------------------------------------------- 00208 00209 //------------------------------------------------------------------------- 00210 void SetTexture ( BitmapImage *img ); 00211 //------------------------------------------------------------------------- 00212 }; // END CLASS OpenGLSupport 00213 //============================================================================= 00214 END_NAMESPACE_TAPs__OpenGL 00215 //----------------------------------------------------------------------------- 00216 // Include definition if TAPs_USE_EXPORT is not defined 00217 #if !defined( TAPs_USE_EXPORT ) 00218 #include "TAPsOpenGLSupport.cpp" 00219 #endif 00220 //----------------------------------------------------------------------------- 00221 #endif 00222 //345678901234567890123456789012345678901234567890123456789012345678901234567890 00223 //--+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8