Skip to main content
gamedev.net
🔒 Locked

Water

Started by Paddeh Oct 24, 2001 at 3:44 PM 1 replies 550+ views
Original Post
Paddeh
Paddeh
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.
BlackHwk4
BlackHwk4
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.
Paddeh
Paddeh
That helped a hell of a lot, thanks man. muchly apreciated :]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.