PDA

View Full Version : Align texture with eye



Swiftless
05-25-2006, 05:32 AM
I have created a texture with the glTexGenSubImage command, and I want to map it to a quad so that it is in cahoots with the eye.

So as the eye rotates, this texture rotates to match the eye.

What I am trying to do is a reflection of my terrain, that will be mapped to a quad and distorted using a shader to look like water. The problem is the way that the reflection is mapped to the quad.

Currently I have the image taken from the screen 'as is'. I then map it to my quad which currently has set texture coordinates.

It is all weird, and I am pretty sure I have no idea how to fix it.

Any help would be appreciated.

jide
05-25-2006, 05:54 AM
GL texture coordinates generation with eye linear is surely what you're looking for.

Swiftless
05-25-2006, 04:43 PM
Ok, I have tried it and it seems to be that this is not the problem.

I have some pictures here of the texture that is taken from the scene, and what it looks like when attached to the water.

Original created texture
*Image Removed*
Original created texture
*Image Removed*
Texture mapped to water (water above as seen from below)
*Image Removed*
Water mapped, as seen from above
*Image Removed*
As you will be able to see, the texture does not seem to be created correctly. The code I am using is:


glRenderTerrain();
glGenTextures(1, &treflect);
glBindTexture( GL_TEXTURE_2D, treflect );

glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 0, 0, w1, h1, 0);
Where it renders my terrain and then creates the reflection texture.

w1 and h1 are integer variables the width and height of my window.

jide
05-25-2006, 05:49 PM
Can you explain what are supposed to be the four images, which one should have corresponded to what ?

I can't see any GL texture generation here.

For texture coordinates generation the code should look like this:



glTexGeni (GL_S, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
glTexGenfv (GL_S, GL_EYE_PLANE, sm);
glEnable (GL_TEXTURE_GEN_S);To be done for each 4 coordinates components (s,t,r,q)

Also try to have a look at cubemaps. As far as I understood you only have one face that will reflect the world, but that could at least give you pretty much information.

Swiftless
05-25-2006, 07:27 PM
I am not using texture coordinates generation. I tried this and it made NO difference.

As you should be able to see from the first two images, these are the texture as it is created. This looks nothing like what is on the screen at the time of drawing, which is similar to the terrain you can see in the last image.

My problem now lies in the texture itself, not the way it is aligned.

** I have found the line causing the problem **
glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 0, 0, w1, h1, 0);

If I change w1 and h1 to specific values, such as 256,256. It then works. w1 and h1 are variables set in my reshape function to take the width and height of the window. What could be wrong?

** I am so sorry, I have found out the problem. **

When I was in my reshape function, I was setting h1 but not w1.

Sorry.