home *** CD-ROM | disk | FTP | other *** search
/ Quark 3 / Quark3.iso / KATALOG / ARCHIV / TOOL / T001.ZIP / SOURCE.ZIP / md3gl.h < prev    next >
Encoding:
C/C++ Source or Header  |  1999-05-19  |  4.9 KB  |  140 lines

  1. /*
  2. Copyright (C) Matthew 'pagan' Baranowski & Sander 'FireStorm' van Rossen
  3.  
  4. This program is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU General Public License
  6. as published by the Free Software Foundation; either version 2
  7. of the License, or (at your option) any later version.
  8.  
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12. GNU General Public License for more details.
  13.  
  14. You should have received a copy of the GNU General Public License
  15. along with this program; if not, write to the Free Software
  16. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  17. */
  18. #ifndef _MD3_GL_H_
  19. #define _MD3_GL_H_
  20.  
  21. typedef struct
  22. {
  23.     unsigned char          *Data;              // actual texture bitmap
  24.     unsigned int            Width, Height;     // size of TextureData
  25.     GLenum                  Type;              // type of texture ie.    
  26.     GLuint                   Bind;               // id the texture is bound to
  27.     char                   *File;              // allocated string storing path name
  28.     int                     numUsed;
  29. } TextureGL;
  30.  
  31. typedef struct
  32. {            
  33.     GLuint         *textureBinds;              // array of texture binds, one for each mesh
  34.     int            topTextureBind;    
  35.     Vec3           *iterVerts;                // arrays of vertices for interpolation, one for each mesh    
  36.     NodeDictionary textureRes;                 // map of texture names to TextureGL data, stores texture resources
  37. } MD3GL;
  38.  
  39. typedef Vec3 *FMeshFrame;                // frame of VertexFloats
  40.  
  41. /*
  42. run time model data structure
  43. */
  44.  
  45. struct gl_mesh
  46. {
  47.     char          name[64];
  48.     unsigned int  vertexNum;                    // number of vertices in model
  49.     unsigned int  triangleNum;                  // number of triangles in gl_model
  50.     unsigned int  meshFrameNum;                 // same as global frame but convenient
  51.     
  52.     TriVec         *triangles;                    // array of triangle vertex indices of size triangleNum
  53.     TexVec       *textureCoord;                 // array of float s/t texture cooridnates of sie vertexNum
  54.     FMeshFrame   *meshFrames;                   // 2d array of size of [frameNum][vertexNum] stores mesh frame vertices
  55.     Vec3         *iterMesh;                     // buffer mesh frame used to store interpolated mesh of size vertexNum
  56.  
  57.     unsigned int  skinNum;                      // number of skins this model has
  58.     GLuint       *bindings;                     // array of texture bindings of size skinNum;    
  59. };
  60.  
  61. struct gl_model;
  62. struct gl_model
  63. {
  64.     unsigned int   frameNum;                     // number of frames in gl_model
  65.     unsigned int   tagNum;                         // number of tags in gl_model         
  66.     unsigned int   meshNum;                      // number of meshes in whole model
  67.     NodePosition   modelListPosition;            // link to its mdview.modelList
  68.     float          CTM_matrix[16];               // object transformation matrix for manipulating mesh
  69.         
  70.     gl_mesh       *meshes;                       // array of meshes of size meshNum
  71.  
  72.     gl_model     **linkedModels;                 // array of links of size tagNum, each link corresponds to a tag
  73.     gl_model      *parent;
  74.     TagFrame      *tags;                         // 2d array of tags size [frameNum][tagNum]
  75.     BoneFrame     *boneFrames;                   // 2d array of bone frames size [frameNum][tagNum]
  76.  
  77.     unsigned int   currentFrame;                // current frame being displayed
  78.  
  79.     // this requires more work once the script parser is done
  80.     bool          isBlended;                    
  81.     GLenum        blendParam1, blendParam2;         
  82. };
  83.  
  84.  
  85. #define NEAR_GL_PLANE 0.1
  86. #define FAR_GL_PLANE 512
  87.  
  88. void initialize_glstate();
  89. bool loadmd3gl( MD3GL &data );
  90. void rendermd3gl( MD3GL &mdl );
  91. void freemd3gl( MD3GL &data );
  92. void renderFrame();
  93.  
  94. void oglStateFlatTextured();
  95. void oglStateShadedTextured();
  96. void oglStateShadedFlat();
  97. void oglStateWireframe();
  98.  
  99.  
  100. /*
  101. damn smart and efficient texture loader, 
  102. first searches for an existing teature name is parent directories
  103. then checks if texture has already been loaded,
  104. otherwise it loads it up, enters in textureRes manager and returns the new binding
  105. */
  106. GLuint loadTexture( char *texturepath );
  107.  
  108. /*
  109. frees a texture resource, called whenever a mesh is being freed. a texture is freed only if nothing is using it anymore
  110. */
  111. void freeTexture( GLuint bind );
  112.  
  113. /*
  114. deletes the entire texture resource manager with all its textures, usually called at the end of the program
  115. or when a whole new model is loaded
  116. */
  117. void freeTextureRes();
  118.  
  119. /*
  120. reloads all texture resources from disk
  121. */
  122. void refreshTextureRes();
  123.  
  124. /*
  125. chooses the specific filter to be applied based on current mode
  126. */
  127. void setTextureToFilter();
  128.  
  129. /*
  130. sets texture parameters to the current texMode
  131. */
  132. void setTextureFilter();
  133.  
  134. /*
  135. renders the current frame 
  136. */
  137. void draw_view();
  138. void draw_viewSkeleton();
  139.  
  140. #endif