Waterflow
Visualize water in terrain
|
00001 00002 00003 00004 #ifndef MYDRAWABLE_H 00005 #define MYDRAWABLE_H 00006 00007 #include "loadobj.h" 00008 #include "glm.hpp" 00009 00010 #include "AntTweakBar.h" 00011 00012 #include <vector> 00013 00014 #ifdef _WINDOWS 00015 #include "sdlTexture.h" 00016 #endif 00017 00025 struct LightParams { 00026 glm::vec3 position; 00027 GLfloat isDirectional; 00028 glm::vec3 color; 00029 GLfloat specularComponent; 00030 }; 00031 00034 enum textureUnits { 00035 SKYBOX_TEXUNIT, 00036 TERRAINDATA_TEXUNIT, 00037 TERRAIN_FIRST_TEXUNIT, 00038 NOISE_TEXUNIT = TERRAIN_FIRST_TEXUNIT, 00039 DOTTED_TEXUNIT, 00040 GRASS_TEXUNIT, 00041 TOTAL_TEXTURES 00042 }; 00043 00049 class myDrawable { 00050 protected: 00051 static GLuint lightBuffer; 00052 static LightParams lightParam[2]; 00053 static GLuint texIDs[TOTAL_TEXTURES]; 00054 00055 GLuint program; 00056 00057 public: 00059 myDrawable(GLuint program); 00060 00062 virtual void draw() = 0; 00063 00065 virtual void update() = 0; 00066 00068 static void setLights(); 00069 00071 static void setTextures(GLuint* size); 00072 }; 00073 00074 00079 class SkyCube : public myDrawable { 00080 private: 00081 Model* model; 00082 00083 public: 00086 SkyCube(GLuint program); 00087 00091 virtual void update() {} 00092 00096 virtual void draw(); 00097 }; 00098 00104 class HeightMap : public myDrawable { 00105 protected: 00106 GLuint drawBuffers[4]; 00107 GLuint heightBuffer; 00108 GLuint drawVAO; 00109 GLuint texnum; 00110 00111 GLuint dataWidth; 00112 GLuint dataHeight; 00113 GLfloat dataTerrainHeight; 00114 GLuint numData; 00115 GLuint numIndices; 00116 00117 00118 GLuint normalsProgram; 00119 GLuint heightMapProgram; 00120 GLuint textureProgram; 00121 00125 void initUpdate(); 00126 00130 void initDraw(); 00131 00132 public: 00140 HeightMap(GLuint drawProgram, GLuint* sizes, GLfloat maxHeight, GLuint inputHeightBuffer); 00141 00147 virtual void update(); 00148 00150 virtual void draw(); 00151 00153 void generateHeightTexture(); 00154 00156 static void TW_CALL SetTextureCB(const void* value, void* clientData); 00157 00159 static void TW_CALL GetTextureCB(void* value, void* clientData); 00160 }; 00161 00167 class Water : public HeightMap { 00168 private: 00169 GLfloat transparency; 00170 GLfloat maxDepth; 00171 GLuint programs[2]; 00172 GLint programToDraw; 00173 GLuint vaos[2]; 00174 00179 void initDepthProgram(); 00180 00181 public: 00189 Water(GLuint* drawPrograms, GLuint* sizes, GLfloat maxHeight, GLuint inputHeightBuffer); 00190 00192 static void TW_CALL SetTransparencyCB(const void* value, void* clientData); 00194 static void TW_CALL GetTransparencyCB(void* value, void* clientData); 00195 00197 static void TW_CALL SetDrawProgramCB(const void* value, void* clientData); 00199 static void TW_CALL GetDrawProgramCB(void* value, void* clientData); 00200 00202 static void TW_CALL SetMaxDepthCB(const void* value, void* clientData); 00204 static void TW_CALL GetMaxDepthCB(void* value, void* clientData); 00205 }; 00206 00207 00208 00209 00210 00211 #endif // DRAWABLE_H