Changeset 7823 in orxonox.OLD for branches/water/src/world_entities
- Timestamp:
- May 24, 2006, 6:10:25 PM (19 years ago)
- Location:
- branches/water/src/world_entities/environments
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/water/src/world_entities/environments/mapped_water.cc
r7817 r7823 18 18 #include "util/loading/factory.h" 19 19 #include "util/loading/resource_manager.h" 20 #include "state.h" 20 21 21 22 … … 38 39 mat.setDiffuseMap("pictures/dudvmap.bmp", GL_TEXTURE_2D, 0); 39 40 // load refraction texture 40 //mat.setDiffuseMap(&this->refractionTexture, 1);41 mat.setDiffuseMap("pictures/sky-replace.jpg", 1); 41 42 // load normal map 42 //mat.setDiffuseMap("pictures/normalmap.bmp", GL_TEXTURE_2D, 2);43 mat.setDiffuseMap("pictures/normalmap.bmp", GL_TEXTURE_2D, 2); 43 44 // load dudv map 44 //mat.setDiffuseMap("pictures/dudvmap.bmp", GL_TEXTURE_2D, 3);45 mat.setDiffuseMap("pictures/dudvmap.bmp", GL_TEXTURE_2D, 3); 45 46 // set up depth texture 46 //mat.setDiffuseMap(&this->depthTexture, 4);47 mat.setDiffuseMap("pictures/sky-replace.jpg", 4); 47 48 48 49 // set the size of the refraction and reflection textures … … 55 56 unsigned int channels = 32; 56 57 GLenum type = GL_RGBA; 57 unsigned int* pTexture = new unsigned int [this->textureSize * this->textureSize * channels]; 58 memset(pTexture, 0, this->textureSize * this->textureSize * channels * sizeof(unsigned int)); 58 unsigned int* pTextureReflection = new unsigned int [this->textureSize * this->textureSize * channels]; 59 memset(pTextureReflection, 0, this->textureSize * this->textureSize * channels * sizeof(unsigned int)); 60 unsigned int* pTextureRefraction = new unsigned int [this->textureSize * this->textureSize * channels]; 61 memset(pTextureRefraction, 0, this->textureSize * this->textureSize * channels * sizeof(unsigned int)); 59 62 // Register the texture with OpenGL and bind it to the texture ID 60 63 mat.select(); … … 62 65 63 66 // Create the texture and store it on the video card 64 glTexImage2D(GL_TEXTURE_2D, 0, channels, this->textureSize, this->textureSize, 0, type, GL_UNSIGNED_INT, pTexture );67 glTexImage2D(GL_TEXTURE_2D, 0, channels, this->textureSize, this->textureSize, 0, type, GL_UNSIGNED_INT, pTextureReflection); 65 68 66 69 //gluBuild2DMipmaps(GL_TEXTURE_2D, channels, this->textureSize, this->textureSize, type, GL_UNSIGNED_INT, pTexture); 70 71 //the same for the refraction 72 glBindTexture(GL_TEXTURE_2D, this->mat.getDiffuseTexture(1)); 73 glTexImage2D(GL_TEXTURE_2D, 0, channels, this->textureSize, this->textureSize, 0, type, GL_UNSIGNED_INT, pTextureRefraction); 67 74 68 75 // Set the texture quality … … 73 80 74 81 // Since we stored the texture space with OpenGL, we can delete the image data 75 delete [] pTexture; 82 delete [] pTextureReflection; 83 delete [] pTextureRefraction; 76 84 77 85 78 86 //shader = new Shader( "/home/stefalie/svn/orxonox/data/trunk/shaders/water.vert", "/home/stefalie/svn/orxonox/data/trunk/shaders/mapped_water.frag"); 79 87 shader = new Shader( ResourceManager::getInstance()->getDataDir() + "/shaders/mapped_water.vert", ResourceManager::getInstance()->getDataDir() +"/shaders/mapped_water.frag"); 88 89 this->move = 0.0f; 90 this->g_WaterUV = 35.0f; 91 this->kNormalMapScale = 0.25f; 92 this->g_WaterFlow = 0.0015f; 80 93 } 81 94 … … 119 132 120 133 // Shader init 121 //this->shader->activateShader();122 //GLint uniform;134 this->shader->activateShader(); 135 GLint uniform; 123 136 124 137 // Set the variable "reflection" to correspond to the first texture unit 125 //uniform = glGetUniformLocationARB(shader->getProgram(), "reflection");126 //glUniform1iARB(uniform, 0); //second paramter is the texture unit138 uniform = glGetUniformLocationARB(shader->getProgram(), "reflection"); 139 glUniform1iARB(uniform, 0); //second paramter is the texture unit 127 140 128 141 // Set the variable "refraction" to correspond to the second texture unit 129 //uniform = glGetUniformLocationARB(shader->getProgram(), "refraction"); 130 //glUniform1iARB(uniform, 0); 131 // FIXME glUniform1iARB(uniform, 1); 142 uniform = glGetUniformLocationARB(shader->getProgram(), "refraction"); 143 glUniform1iARB(uniform, 1); 132 144 133 145 // Set the variable "normalMap" to correspond to the third texture unit 134 //uniform = glGetUniformLocationARB(shader->getProgram(), "normalMap");135 //glUniform1iARB(uniform, 2);146 uniform = glGetUniformLocationARB(shader->getProgram(), "normalMap"); 147 glUniform1iARB(uniform, 2); 136 148 137 149 // Set the variable "dudvMap" to correspond to the fourth texture unit 138 //uniform = glGetUniformLocationARB(shader->getProgram(), "dudvMap");139 //glUniform1iARB(uniform, 3);150 uniform = glGetUniformLocationARB(shader->getProgram(), "dudvMap"); 151 glUniform1iARB(uniform, 3); 140 152 141 153 // Set the variable "depthMap" to correspond to the fifth texture unit 142 //uniform = glGetUniformLocationARB(shader->getProgram(), "depthMap");143 //glUniform1iARB(uniform, 4);154 uniform = glGetUniformLocationARB(shader->getProgram(), "depthMap"); 155 glUniform1iARB(uniform, 4); 144 156 // FIXME we dont have a depthMap yet :-( 145 157 146 158 // Give the variable "waterColor" a blue color 147 //uniform = glGetUniformLocationARB(shader->getProgram(), "waterColor");148 //glUniform4fARB(uniform, 0.1f, 0.2f, 0.4f, 1.0f);159 uniform = glGetUniformLocationARB(shader->getProgram(), "waterColor"); 160 glUniform4fARB(uniform, 0.1f, 0.2f, 0.4f, 1.0f); 149 161 150 162 // FIXME set camera and light information 151 Vector lightPos(100.0f, 150.0f, 100.0f);152 163 Vector lightPos(100.0f, 600.0f, 100.0f); 164 Vector vPosition = State::getCameraNode()->getAbsCoor(); 153 165 // Store the camera position in a variable 154 166 //CVector3 vPosition = g_Camera.Position(); … … 156 168 157 169 // Give the variable "lightPos" our hard coded light position 158 //uniform = glGetUniformLocationARB(shader->getProgram(), "lightPos");159 //glUniform4fARB(uniform, lightPos.x, lightPos.y, lightPos.z, 1.0f);170 uniform = glGetUniformLocationARB(shader->getProgram(), "lightPos"); 171 glUniform4fARB(uniform, lightPos.x, lightPos.y, lightPos.z, 1.0f); 160 172 161 173 // Give the variable "cameraPos" our camera position 162 //uniform = glGetUniformLocationARB(shader->getProgram(), "cameraPos"); 163 //glUniform4fARB(uniform, vPosition.x, vPosition.y, vPosition.z, 1.0f); 174 uniform = glGetUniformLocationARB(shader->getProgram(), "cameraPos"); 175 glUniform4fARB(uniform, vPosition.x, vPosition.y, vPosition.z, 1.0f); 176 177 178 179 float move2 = this->move * this->kNormalMapScale; 180 float refrUV = this->g_WaterUV; 181 float normalUV = this->g_WaterUV * this->kNormalMapScale; 182 164 183 165 184 glBegin(GL_QUADS); 166 glNormal3f(0, 1, 0); 167 glMultiTexCoord2f(GL_TEXTURE0, 0, 0); 168 glMultiTexCoord2f(GL_TEXTURE1, 0, 0); 169 glMultiTexCoord2f(GL_TEXTURE2, 0, 0); 170 glMultiTexCoord2f(GL_TEXTURE3, 0, 0); 171 glMultiTexCoord2f(GL_TEXTURE4, 0, 0); 172 glVertex3f(0, 0, 0); 173 174 glMultiTexCoord2f(GL_TEXTURE0, 1, 0); 175 glMultiTexCoord2f(GL_TEXTURE1, 1, 0); 176 glMultiTexCoord2f(GL_TEXTURE2, 1, 0); 177 glMultiTexCoord2f(GL_TEXTURE3, 1, 0); 178 glMultiTexCoord2f(GL_TEXTURE4, 1, 0); 179 glVertex3f(0, 0, 1000); 180 181 glMultiTexCoord2f(GL_TEXTURE0, 1, 1); 182 glMultiTexCoord2f(GL_TEXTURE1, 1, 1); 183 glMultiTexCoord2f(GL_TEXTURE2, 1, 1); 184 glMultiTexCoord2f(GL_TEXTURE3, 1, 1); 185 glMultiTexCoord2f(GL_TEXTURE4, 1, 1); 186 glVertex3f(1000, 0, 1000); 187 188 glMultiTexCoord2f(GL_TEXTURE0, 0, 1); 189 glMultiTexCoord2f(GL_TEXTURE1, 0, 1); 190 glMultiTexCoord2f(GL_TEXTURE2, 0, 1); 191 glMultiTexCoord2f(GL_TEXTURE3, 0, 1); 192 glMultiTexCoord2f(GL_TEXTURE4, 0, 1); 193 glVertex3f(1000, 0, 0); 185 // The back left vertice for the water 186 glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 0.0f, g_WaterUV); // Reflection texture 187 glMultiTexCoord2fARB(GL_TEXTURE1_ARB, 0.0f, refrUV - move); // Refraction texture 188 glMultiTexCoord2fARB(GL_TEXTURE2_ARB, 0.0f, normalUV + move2); // Normal map texture 189 glMultiTexCoord2fARB(GL_TEXTURE3_ARB, 0, 0); // DUDV map texture 190 glMultiTexCoord2fARB(GL_TEXTURE4_ARB, 0, 0); // Depth texture 191 glVertex3f(0.0f, waterHeight, 0.0f); 192 193 // The front left vertice for the water 194 glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 0.0f, 0.0f); // Reflection texture 195 glMultiTexCoord2fARB(GL_TEXTURE1_ARB, 0.0f, 0.0f - move); // Refraction texture 196 glMultiTexCoord2fARB(GL_TEXTURE2_ARB, 0.0f, 0.0f + move2); // Normal map texture 197 glMultiTexCoord2fARB(GL_TEXTURE3_ARB, 0, 0); // DUDV map texture 198 glMultiTexCoord2fARB(GL_TEXTURE4_ARB, 0, 0); // Depth texture 199 glVertex3f(0.0f, waterHeight, 1000.0f); 200 201 // The front right vertice for the water 202 glMultiTexCoord2fARB(GL_TEXTURE0_ARB, g_WaterUV, 0.0f); // Reflection texture 203 glMultiTexCoord2fARB(GL_TEXTURE1_ARB, refrUV, 0.0f - move); // Refraction texture 204 glMultiTexCoord2fARB(GL_TEXTURE2_ARB, normalUV, 0.0f + move2); // Normal map texture 205 glMultiTexCoord2fARB(GL_TEXTURE3_ARB, 0, 0); // DUDV map texture 206 glMultiTexCoord2fARB(GL_TEXTURE4_ARB, 0, 0); // Depth texture 207 glVertex3f(1000.0f, waterHeight, 1000.0f); 208 209 // The back right vertice for the water 210 glMultiTexCoord2fARB(GL_TEXTURE0_ARB, g_WaterUV, g_WaterUV); // Reflection texture 211 glMultiTexCoord2fARB(GL_TEXTURE1_ARB, refrUV, refrUV - move); // Refraction texture 212 glMultiTexCoord2fARB(GL_TEXTURE2_ARB, normalUV, normalUV + move2); // Normal map texture 213 glMultiTexCoord2fARB(GL_TEXTURE3_ARB, 0, 0); // DUDV map texture 214 glMultiTexCoord2fARB(GL_TEXTURE4_ARB, 0, 0); // Depth texture 215 glVertex3f(1000.0f, waterHeight, 0.0f); 194 216 glEnd(); 195 217 196 218 this->shader->deactivateShader(); 197 219 220 198 221 glPopMatrix(); 199 222 } … … 201 224 void MappedWater::tick(float dt) 202 225 { 226 this->move += this->g_WaterFlow; 203 227 } 204 228 -
branches/water/src/world_entities/environments/mapped_water.h
r7816 r7823 34 34 35 35 private: 36 float waterHeight; //!< y-coord of the Water36 float waterHeight; //!< y-coord of the Water 37 37 Material mat; 38 float move; 39 float g_WaterUV; //!< The scale for the water textures 40 float kNormalMapScale; 41 float g_WaterFlow; 38 42 39 int textureSize; //!< size of the texture43 int textureSize; //!< size of the texture 40 44 Shader* shader; 41 45
Note: See TracChangeset
for help on using the changeset viewer.