cl.h

Go to the documentation of this file.
00001 
00105 #ifndef CL_H
00106 #define CL_H
00107 
00108 #ifdef __cplusplus
00109 extern "C" {
00110 #endif
00111   
00112 #include <stdlib.h>
00113 #include <stdio.h>
00114 #include <math.h>
00115 #include <stdbool.h>
00116 #include <limits.h>
00117 #include <string.h>
00118 #include <assert.h>
00119 
00120 #ifdef __linux__
00121 #include <values.h>
00122 #include <GL/gl.h>
00123 #include <GL/glu.h>
00124 #include <GL/glut.h>
00125 #endif
00126 
00127 #ifdef __APPLE__
00128 #include <float.h>
00129 #include <OpenGL/gl.h>
00130 #include <OpenGL/glu.h>
00131 #include <GLUT/glut.h>
00132 #endif
00133 
00134 /* 
00135    constants
00136 */
00137 #define CL_VERSION 2.0
00138 #define CL_PI 3.14159265358979323846
00139 #define CL_PI_2 1.57079632679489661923 
00140 #define CL_EPSILON 1.0e-5
00141 
00142 /*
00143   enums
00144 */
00145 #define CL_NONE                  0
00146 #define CL_LIGHT_DISPLAY_LIST    (1<<0)
00147 #define CL_MATERIAL_DISPLAY_LIST (1<<1)
00148 #define CL_TEXTURE_OBJECT        (1<<2)
00149 #define CL_COLOUR                (1<<3)
00150 #define CL_MATERIAL              (1<<4)
00151 #define CL_TEXTURE               (1<<5)
00152 #define CL_TEXTURE_ENV_MODE      (1<<6)
00153 #define CL_VERTICES              (1<<7)
00154 #define CL_NORMALS               (1<<8)
00155 #define CL_COLOURS               (1<<9)
00156 #define CL_TEXCOORDS             (1<<10)
00157 #define CL_EDGEFLAGS             (1<<11)
00158 #define CL_MESH_DISPLAY_LIST     (1<<12)
00159 
00160 #define CL_VERBOSE               (1<<16)
00161 
00162 #define CL_ALL                   -1
00163 
00175 #define CL_DEG2RAD(f) (((f) * CL_PI_2) / 90.0f)
00176 #define CL_RAD2DEG(f) (((f) * 90.0f) / (CL_PI_2))
00177 #define CL_CROP(f, lb, ub) ((f) < (lb) ? (lb) : (f) > (ub) ? (ub) : (f))
00178 #define CL_MIN(a, b) ((a) > (b) ? (b) : (a))
00179 #define CL_MAX(a, b) ((a) < (b) ? (b) : (a))
00180 #define CL_BOOLEAN(a) ((bool)((a) ? GL_TRUE : GL_FALSE))
00181 
00182 #define CL_PRINTF(...) if (printf(__VA_ARGS__) < 0) return GL_FALSE 
00183 #define CL_ERROR(...) fprintf(stderr, "%s:%u:%s() : ERROR : ", __FILE__, __LINE__, __FUNCTION__); fprintf(stderr, __VA_ARGS__)
00184 #define CL_FUNCENTRY() if (clIsEnabled(CL_VERBOSE)) printf ("%s() : ENTRY\n", __FUNCTION__)
00185 #define CL_FUNCEXIT() if (clIsEnabled(CL_VERBOSE)) printf ("%s() : EXIT\n", __FUNCTION__)
00186 #define CL_MALLOC(n) ((n) ? malloc(n) : 0)
00187 #define CL_MEMCPY(dest, src, size) (((dest) && (src) && (size)) ? memcpy((dest), (src), (size)) : 0)
00188 
00192 /*
00193   types
00194 */
00195 typedef GLenum                CLenum;
00196 typedef struct CLcolour       CLcolour;
00197 typedef struct CLvertex       CLvertex;
00198 typedef struct CLnormal       CLnormal;
00199 typedef struct CLtexcoord     CLtexcoord;
00200 typedef bool                  CLedgeflag;
00201 typedef struct CLmatrix       CLmatrix;
00202 typedef struct CLimage        CLimage;
00203 typedef struct CLlight        CLlight;
00204 typedef struct CLmaterial     CLmaterial;
00205 typedef struct CLtexture      CLtexture;
00206 typedef struct CLprimitiveset CLprimitiveset;
00207 typedef struct CLmesh         CLmesh;
00208 typedef struct CLmodel        CLmodel;
00209 typedef struct CLcontext      CLcontext;
00210 
00227 struct CLcolour
00228 {
00229     GLfloat r;
00230     GLfloat g;
00231     GLfloat b;
00232     GLfloat a;
00233 };
00234     
00252 struct CLvertex
00253 {
00254     GLfloat x;
00255     GLfloat y;
00256     GLfloat z;
00257 };
00258 
00276 struct CLnormal
00277 {
00278     GLfloat i;
00279     GLfloat j;
00280     GLfloat k;
00281 };
00282 
00300 struct CLtexcoord
00301 {
00302     GLfloat s;
00303     GLfloat t;
00304 };
00305 
00334 struct CLmatrix
00335 {
00336     GLfloat m00; /* [0] */
00337     GLfloat m01; /* [1] */
00338     GLfloat m02; /* [2] */
00339     GLfloat m03; /* [3] */
00340     GLfloat m10; /* [4] */
00341     GLfloat m11; /* [5] */
00342     GLfloat m12; /* [6] */
00343     GLfloat m13; /* [7] */
00344     GLfloat m20; /* [8] */
00345     GLfloat m21; /* [9] */
00346     GLfloat m22; /* [10] */
00347     GLfloat m23; /* [11] */
00348     GLfloat m30; /* [12] */
00349     GLfloat m31; /* [13] */
00350     GLfloat m32; /* [14] */
00351     GLfloat m33; /* [15] */
00352 };
00353 
00377 struct CLimage
00378 {
00379     GLuint  width;
00380     GLuint  height;
00381     GLenum  format;
00382     GLenum  type;
00383     void*   data;
00384 };
00385 
00422 struct CLlight
00423 {
00424     GLenum   id;
00425     
00426     CLcolour ambient;
00427     CLcolour diffuse;
00428     CLcolour specular;
00429     GLfloat  position[4];
00430     CLnormal spot_direction;
00431     GLfloat  spot_exponent;
00432     GLfloat  spot_cutoff;
00433     GLfloat  constant_attenuation;
00434     GLfloat  linear_attenuation;
00435     GLfloat  quadratic_attenuation;
00436     
00437     GLuint   display_list;
00438 };
00439 
00476 struct CLmaterial
00477 {
00478     GLenum   face;
00479     
00480     CLcolour ambient;
00481     CLcolour diffuse;
00482     CLcolour specular;
00483     CLcolour emission;
00484     GLfloat  shininess;
00485     
00486     GLuint   display_list;
00487 };
00488 
00521 struct CLtexture
00522 {
00523     CLimage image;
00524     
00525     GLenum  min_filter;
00526     GLenum  mag_filter;
00527     
00528     GLenum  wrap_s;
00529     GLenum  wrap_t;
00530     
00531     GLuint  texture_object;
00532 };
00533 
00570 struct CLprimitiveset
00571 {
00572     GLenum  mode;
00573     
00574     unsigned int num_indices;
00575     GLuint*      indices;
00576 };
00577 
00707 struct CLmesh 
00708 {
00709     /* remove this? */
00710     CLcontext*       context;
00711     
00712     CLcolour*        colour;
00713     unsigned int     material_index;
00714     /* change material_index to:
00715        
00716       GLuint front_material_index;
00717       GLuint back_material_index;
00718     */
00719     unsigned int     texture_index;
00720     GLenum           texture_env_mode;
00721   
00722     unsigned int     num_vertices;
00723     CLvertex*        vertices;
00724     CLcolour*        colours;
00725     CLnormal*        normals; 
00726     CLtexcoord*      texcoords;
00727     CLedgeflag*      edgeflags;
00728     
00729     unsigned int     num_primitivesets;
00730     CLprimitiveset** primitivesets;
00731     
00732     GLuint           display_list;
00733 };
00734 
00749 struct CLmodel
00750 {
00751     /* remove this? */
00752     CLcontext* context;
00753     
00754     unsigned int num_meshes;
00755     CLmesh**     meshes;
00756 };
00757 
00774 struct CLcontext
00775 {
00776     unsigned int num_materials;
00777     CLmaterial** materials;
00778     
00779     unsigned int num_textures;
00780     CLtexture**  textures;
00781     
00782     unsigned int num_lights;
00783     CLlight**    lights;
00784     
00785     unsigned int num_models;
00786     CLmodel**    models;
00787 };
00788 
00838 CLimage*        clInitImage(CLimage* image);
00839 CLmaterial*     clInitMaterial(CLmaterial* material);
00840 CLlight*        clInitLight(CLlight* light);
00841 CLtexture*      clInitTexture(CLtexture* texture);
00842 CLprimitiveset* clInitPrimitiveSet(CLprimitiveset* primitiveset);
00843 CLmesh*         clInitMesh(CLmesh* mesh);
00844 CLcontext*      clInitContext(CLcontext* context);
00845 CLmodel*        clInitModel(CLmodel* model);
00871 CLimage*        clClearImage(CLimage* image);
00872 CLlight*        clClearLight(CLlight* light);
00873 CLmaterial*     clClearMaterial(CLmaterial* material);
00874 CLtexture*      clClearTexture(CLtexture* texture);
00875 CLprimitiveset* clClearPrimitiveSet(CLprimitiveset* primitiveset);
00876 CLmesh*         clClearMesh(CLmesh* mesh);
00877 CLcontext*      clClearContext(CLcontext* context);
00878 CLmodel*        clClearModel(CLmodel* model);
00904 CLcolour*       clNewColour(GLvoid);
00905 CLvertex*       clNewVertex(GLvoid);
00906 CLnormal*       clNewNormal(GLvoid);
00907 CLtexcoord*     clNewTexCoord(GLvoid);
00908 CLedgeflag*     clNewEdgeFlag(GLvoid); /* silly, but for completeness */
00909 CLmatrix*       clNewMatrix(GLvoid);
00910 CLimage*        clNewImage(GLvoid);
00911 CLlight*        clNewLight(GLvoid);
00912 CLmaterial*     clNewMaterial(GLvoid);
00913 CLtexture*      clNewTexture(GLvoid);
00914 CLprimitiveset* clNewPrimitiveSet(GLvoid);
00915 CLmesh*         clNewMesh(GLvoid);
00916 CLcontext*      clNewContext(GLvoid);
00917 CLmodel*        clNewModel(GLvoid);
00942 void clDeleteColour(CLcolour* colour);
00943 void clDeleteVertex(CLvertex* vertex);
00944 void clDeleteNormal(CLnormal* normal);
00945 void clDeleteTexCoord(CLtexcoord* texcoord);
00946 void clDeleteEdgeFlag(CLedgeflag* edgeflag);
00947 void clDeleteMatrix(CLmatrix* matrix);
00948 void clDeleteImage(CLimage* image);
00949 void clDeleteLight(CLlight* light); 
00950 void clDeleteMaterial(CLmaterial* material);
00951 void clDeleteTexture(CLtexture* texture);
00952 void clDeletePrimitiveSet(CLprimitiveset* primitiveset);
00953 void clDeleteMesh(CLmesh* mesh);
00954 void clDeleteContext(CLcontext* context);
00955 void clDeleteModel(CLmodel* model);
00980 CLcolour*       clCopyColour(CLcolour* dest, const CLcolour* src);
00981 CLvertex*       clCopyVertex(CLvertex* dest, const CLvertex* src);
00982 CLnormal*       clCopyNormal(CLnormal* dest, const CLnormal* src);
00983 CLtexcoord*     clCopyTexCoord(CLtexcoord* dest, const CLtexcoord* src);
00984 CLedgeflag*     clCopyEdgeFlag(CLedgeflag* dest, const CLedgeflag* src);
00985 CLmatrix*       clCopyMatrix(CLmatrix* dest, const CLmatrix* src);
00986 CLimage*        clCopyImage(CLimage* dest, const CLimage* src);
00987 CLlight*        clCopyLight(CLlight* dest, const CLlight* src); 
00988 CLmaterial*     clCopyMaterial(CLmaterial* dest, const CLmaterial* src);
00989 CLtexture*      clCopyTexture(CLtexture* dest, const CLtexture* src);
00990 CLprimitiveset* clCopyPrimitiveSet(CLprimitiveset* dest, const CLprimitiveset* src);
00991 CLmesh*         clCopyMesh(CLmesh* dest, const CLmesh* src);
00992 CLcontext*      clCopyContext(CLcontext* dest, const CLcontext* src);
00993 CLmodel*        clCopyModel(CLmodel* dest, const CLmodel* src);
01021 CLcolour*       clDefaultColour(CLcolour* colour);
01022 CLvertex*       clDefaultVertex(CLvertex* vertex);
01023 CLnormal*       clDefaultNormal(CLnormal* normal);
01024 CLtexcoord*     clDefaultTexCoord(CLtexcoord* texcoord);
01025 CLedgeflag*     clDefaultEdgeFlag(CLedgeflag* edgeflag);
01026 CLmatrix*       clDefaultMatrix(CLmatrix* matrix);
01027 CLimage*        clDefaultImage(CLimage* image);
01028 CLlight*        clDefaultLight(CLlight* light); 
01029 CLmaterial*     clDefaultMaterial(CLmaterial* material);
01030 CLtexture*      clDefaultTexture(CLtexture* texture);
01031 CLprimitiveset* clDefaultPrimitiveSet(CLprimitiveset* primitiveset);
01032 CLmesh*         clDefaultMesh(CLmesh* mesh);
01033 CLcontext*      clDefaultContext(CLcontext* context);
01034 CLmodel*        clDefaultModel(CLmodel* model);
01066 bool clWriteColour(const CLcolour* src, FILE* file);
01067 bool clWriteVertex(const CLvertex* src, FILE* file);
01068 bool clWriteNormal(const CLnormal* src, FILE* file);
01069 bool clWriteTexCoord(const CLtexcoord* src, FILE* file);
01070 bool clWriteEdgeFlag(const CLedgeflag* src, FILE* file);
01071 bool clWriteMatrix(const CLmatrix* src, FILE* file);
01072 bool clWriteImage(const CLimage* src, FILE* file);
01073 bool clWriteLight(const CLlight* src, FILE* file);
01074 bool clWriteMaterial(const CLmaterial* src, FILE* file);
01075 bool clWriteTexture(const CLtexture* src, FILE* file);
01076 bool clWritePrimitiveSet(const CLprimitiveset* src, FILE* file);
01077 bool clWriteMesh(const CLmesh* src, FILE* file);
01078 bool clWriteContext(const CLcontext* src, FILE* file);
01079 bool clWriteModel(const CLmodel* src, FILE* file);
01110 bool clReadColour(CLcolour* dest, FILE* file);
01111 bool clReadVertex(CLvertex* dest, FILE* file);
01112 bool clReadNormal(CLnormal* dest, FILE* file);
01113 bool clReadTexCoord(CLtexcoord* dest, FILE* file);
01114 bool clReadEdgeFlag(CLedgeflag* dest, FILE* file);
01115 bool clReadMatrix(CLmatrix* dest, FILE* file);
01116 bool clReadImage(CLimage* dest, FILE* file);
01117 bool clReadLight(CLlight* dest, FILE* file);
01118 bool clReadMaterial(CLmaterial* dest, FILE* file);
01119 bool clReadTexture(CLtexture* dest, FILE* file);
01120 bool clReadPrimitiveSet(CLprimitiveset* dest, FILE* file);
01121 bool clReadMesh(CLmesh* dest, FILE* file);
01122 bool clReadContext(CLcontext* dest, FILE* file);
01123 bool clReadModel(CLmodel* dest, FILE* file);
01148 bool clPrintEnum(const CLenum* e);
01149 bool clPrintColour(const CLcolour* colour);
01150 bool clPrintVertex(const CLvertex* vertex);
01151 bool clPrintNormal(const CLnormal* normal);
01152 bool clPrintTexCoord(const CLtexcoord* texcoord);
01153 bool clPrintEdgeFlag(const CLedgeflag* edgeflag);
01154 bool clPrintMatrix(const CLmatrix* matrix);
01155 bool clPrintImage(const CLimage* image);
01156 bool clPrintLight(const CLlight* light);
01157 bool clPrintMaterial(const CLmaterial* material);
01158 bool clPrintTexture(const CLtexture* texture);
01159 bool clPrintPrimitiveSet(const CLprimitiveset* primitiveset);
01160 bool clPrintMesh(const CLmesh* mesh);
01161 bool clPrintContext(const CLcontext* context);
01162 bool clPrintModel(const CLmodel* model);
01163 
01165 bool clPrintContextSummary(const CLcontext* context);
01166 bool clPrintModelSummary(const CLmodel* model);
01206 void clEnable(CLenum e);
01207 void clDisable(CLenum e);
01208 bool clIsEnabled(CLenum e);
01226 void clUpdateLight(CLlight* light);
01227 void clUpdateMaterial(CLmaterial* material);
01228 void clUpdateTexture(CLtexture* texture);
01229 void clUpdateMesh(CLmesh* mesh);
01230 void clUpdateContext(CLcontext* context);
01240 void clLoadLight(const CLlight* light);
01241 void clLoadMaterial(const CLmaterial* material);
01242 void clLoadTexture(const CLtexture* texture);
01252 void clDrawImage(const CLimage* image);
01262 void clRenderMesh(const CLmesh* mesh);
01263 void clRenderMeshVisible(const CLmesh* mesh, const bool** flags);
01264 void clRenderModel(const CLmodel* model);
01286 GLuint clImageNumPixels(const CLimage* image);
01287 GLuint clImagePixelSize(const CLimage* image);
01288 GLuint clImageNumElements(const CLimage* image);
01289 GLuint clImageElementSize(const CLimage* image);
01290 GLuint clImageDataSize(const CLimage* image);
01300 unsigned int clMeshAddPrimitiveSet(CLmesh* mesh, CLprimitiveset* primitiveset);
01310 unsigned int clModelAddMesh(CLmodel* model, CLmesh* mesh);
01319 unsigned int clContextAddMaterial(CLcontext* context, CLmaterial* material);
01320 unsigned int clContextAddTexture(CLcontext* context, CLtexture* texture);
01321 unsigned int clContextAddLight(CLcontext* context, CLlight* light);
01322 unsigned int clContextAddModel(CLcontext* context, CLmodel* model);
01331 /* maybe implement these later? */
01332 /*
01333 ...
01334 bool clContextRemoveMaterial(CLcontext* context, GLuint index);
01335 bool clContextRemoveTexture(CLcontext* context, GLuint index);
01336 bool clContextRemoveLight(CLcontext* context, GLuint index);
01337 bool clContextRemoveModel(CLcontext* context, GLuint index);
01338 */
01339 
01340 #ifdef __cplusplus
01341 }
01342 #endif
01343 
01344 #endif
01345 

Generated on Thu Dec 27 13:53:41 2007 for CL by  doxygen 1.4.6