• Advertisement

Archived

This topic is now archived and is closed to further replies.

Water

This topic is 5935 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I''ve recently been pondering the best way to go about making a water effect, im a total novice at opengl, and I was just wondering if anyone had any thoughts on how to go about coding such a thing. Think of the water in quake1, It doesnt flow, it just seems to morph the texture around. Any ideas would be greatly apreciated.

Share this post


Link to post
Share on other sites
Advertisement
It''s been a little while since I did something like this, so I might have forgot something. Here is an example of what you will do:

float angle;
float rotate;

init()
{
loadMyTextures();
}

drawStuff()
{
/* Draw stuff in the scene and do whatever else you''re gonna do here */

glMatrixMode(GL_TEXTURE);
glLoadIdentity();
glRotatef(angle, 1.0f, 1.0f, 0.0f);
glRotatef(rotate, 0.0f, 0.0f, 1.0f);
glTranslatef(0.0f, 0.0f, -280.0f);
glMatrixMode(GL_MODELVIEW);

// we want the water to be a little transparent
glEnable(GL_BLEND);
glDepthMask(GL_FALSE);

glBlendFunc(GL_SRC_ALPHA, GL_ONE);

glColor4f(0.3f, 0.3f, 0.8f, 0.8f);

glPushMatrix();
glBindTexture(GL_TEXTURE_2D, textureID);
drawCube(); // this will be the cube with a water texture on it
glPopMatrix();

// disable blending stuff
glDepthMask(GL_TRUE);
glDisable(GL_BLEND);

// reset the texture matrix or stuff will be screwed up
glMatrixMode(GL_TEXTURE);
glLoadIdentity();
glMatrixMode(GL_MODELVIEW);

angle += 0.0005f;
rotate += 0.01f;
}

Now the texture on the cube will look like it''s flowing to the southeast and will be going slowly counter clockwise. Basically what you''re doing when you set the matrix stack to GL_TEXTURE, is telling OpenGL to do these things to all the textures. So, if you don''t reset the texture matrix then it will do the stuff you told it to do to all the other textures. Like I said, I''m a bit rusty on this subject but that''s what I think is happening. Try looking for tutorials on the matrix stack if you want a better explanation. Hope this helped.

Share this post


Link to post
Share on other sites

  • Advertisement