Jump to content
  • Advertisement
Sign in to follow this  
RoyChen204

OpenGL Water Rendering Problems

This topic is 3604 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

Hi, I read up on Bonzai's Software water creation tutorial, however when I tried it out I ran into some errors. Using his method, I tried to recreate the same effect after modifying the files. When that failed, after various attempts to correct it, I tried to use the exact same codes being used in a sample project to see. However, when RenderWater is called, my skybox textures goes haywire, and the water plane just renders without any sign of water. When I commented Renderwater(), the skybox is just fine. RenderWater()
    // Use The Program Object Instead Of Fixed Function OpenGL
	glUseProgramObjectARB(my_program);
	
	int uniform = glGetUniformLocationARB(my_program, "viewpos");
	glUniform4fARB(uniform, g_Camera->mPos.x,g_Camera->mPos.y,g_Camera->mPos.z, 1.0);

	uniform = glGetUniformLocationARB(my_program, "lightpos");
	glUniform4fARB(uniform, 5.0f,25.0f,6.0f, 1.0f);

	uniform = glGetUniformLocationARB(my_program, "time");
	glUniform1fARB(uniform, texmove);

	uniform = glGetUniformLocationARB(my_program, "time2");
	glUniform1fARB(uniform, -texmove);

	texmove += 0.01;
	
	uniform = glGetUniformLocationARB(my_program, "water_reflection");
	glUniform1iARB(uniform, 0);

	uniform = glGetUniformLocationARB(my_program, "water_refraction");
	glUniform1iARB(uniform, 1);
	
	uniform = glGetUniformLocationARB(my_program, "water_normalmap");
	glUniform1iARB(uniform, 2);	

	uniform = glGetUniformLocationARB(my_program, "water_dudvmap");
	glUniform1iARB(uniform, 3);

	uniform = glGetUniformLocationARB(my_program, "water_depthmap");
	glUniform1iARB(uniform, 4);

	uniform = glGetUniformLocationARB(my_program, "waterColor");
	glUniform4fARB(uniform, 1.0f,1.0f,1.0f, 1.0f);

	uniform = glGetUniformLocationARB(my_program, "waterDepth");
	glUniform4fARB(uniform, 1.0f,1.0f,1.0f, 1.0f);


//bind all textures
    glActiveTextureARB(GL_TEXTURE0_ARB);
    glEnable(GL_TEXTURE_2D);
	glBindTexture(GL_TEXTURE_2D, reflectionTexture);

    glActiveTextureARB(GL_TEXTURE1_ARB);
	glEnable(GL_TEXTURE_2D);
	glBindTexture(GL_TEXTURE_2D, refractionTexture);

    glActiveTextureARB(GL_TEXTURE2_ARB);
	glEnable(GL_TEXTURE_2D);
    glBindTexture(GL_TEXTURE_2D, normalmap);

    glActiveTextureARB(GL_TEXTURE3_ARB);
    glEnable(GL_TEXTURE_2D);
    glBindTexture(GL_TEXTURE_2D, dudvmap);

    glActiveTextureARB(GL_TEXTURE4_ARB);
	glEnable(GL_TEXTURE_2D);
	glBindTexture(GL_TEXTURE_2D, depthTexture);

    //Render the water surface
    glBegin(GL_QUADS);
		glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 0.0f, 5.0f);
		glMultiTexCoord2fARB(GL_TEXTURE1_ARB, 0.0f, 1.0f);
		glMultiTexCoord2fARB(GL_TEXTURE2_ARB, 0.0f, 1.0f);
		glMultiTexCoord2fARB(GL_TEXTURE3_ARB, 0.0f, 1.0f);
		glMultiTexCoord2fARB(GL_TEXTURE4_ARB, 0.0f, 1.0f);
		glVertex3f(-5.0f, 0.0f, 5.0f);

		glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 0.0f, 0.0f);
		glMultiTexCoord2fARB(GL_TEXTURE1_ARB, 0.0f, 1.0f);
		glMultiTexCoord2fARB(GL_TEXTURE2_ARB, 0.0f, 1.0f);
		glMultiTexCoord2fARB(GL_TEXTURE3_ARB, 0.0f, 1.0f);
		glMultiTexCoord2fARB(GL_TEXTURE4_ARB, 0.0f, 1.0f);
		glVertex3f(-5.0f, 0.0f, -5.0f);

		glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 5.0f, 0.0f);
		glMultiTexCoord2fARB(GL_TEXTURE1_ARB, 0.0f, 1.0f);
		glMultiTexCoord2fARB(GL_TEXTURE2_ARB, 0.0f, 1.0f);
		glMultiTexCoord2fARB(GL_TEXTURE3_ARB, 0.0f, 1.0f);
		glMultiTexCoord2fARB(GL_TEXTURE4_ARB, 0.0f, 1.0f);
		glVertex3f(5.0f, 0.0f, -5.0f);

		glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 5.0f, 5.0f);
		glMultiTexCoord2fARB(GL_TEXTURE1_ARB, 0.0f, 1.0f);
		glMultiTexCoord2fARB(GL_TEXTURE2_ARB, 0.0f, 1.0f);
		glMultiTexCoord2fARB(GL_TEXTURE3_ARB, 0.0f, 1.0f);
		glMultiTexCoord2fARB(GL_TEXTURE4_ARB, 0.0f, 1.0f);
		glVertex3f(5.0f, 0.0f, 5.0f);
    glEnd();

    //Disable texture units and shader programs
	glActiveTextureARB(GL_TEXTURE0_ARB); glDisable(GL_TEXTURE_2D);
	glActiveTextureARB(GL_TEXTURE1_ARB); glDisable(GL_TEXTURE_2D);
	glActiveTextureARB(GL_TEXTURE2_ARB); glDisable(GL_TEXTURE_2D);
	glActiveTextureARB(GL_TEXTURE3_ARB); glDisable(GL_TEXTURE_2D);
	glActiveTextureARB(GL_TEXTURE4_ARB); glDisable(GL_TEXTURE_2D);
	glUseProgramObjectARB(0);

Share this post


Link to post
Share on other sites
Advertisement
When you disable all texture units, you activate texture unit 4 the last, which means any textures you bind will go to unit 4 instead of unit 0. Try placing the

glActiveTextureARB(GL_TEXTURE0_ARB); glDisable(GL_TEXTURE_2D);

line at the bottom.

This is a common mistake btw. When I undo changes I made to the render state, I always try to do it exactly opposite (so first i disable unit 4, then 3, ... and then 0), just to avoid these kind of problems.

Share this post


Link to post
Share on other sites
Thanks Tree Penguin.

Now I got another problem.

why is it that when I turn the camera around, the lightning goes crazy?
On some rotation of the camera, it brightens, and sometimes it darkens
Why?

if I want a clearer reflection, what can I do?

[Edited by - RoyChen204 on November 9, 2008 10:00:12 AM]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!