# Help projecting a reflected texture (distorting)

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

## Recommended Posts

I’m rendering my scene to a texture that I then want to project to a flat plane. I’m thinking I want to draw a plane at the water level to the 2 side and back and front of the frustum. Is this how I should do this? Next comes the actual projecting part. I was doing it like :
    glMatrixMode(GL_TEXTURE);
glPushMatrix();
glTranslatef(0.5, 0.5, 0.0);
glScalef(0.05, 0.05, 1.0);

gluLookAt(nCamera.pos.x, nCamera.pos.y, nCamera.pos.z, nCamera.view.x, -3, nCamera.view.z,
nCamera.up.x, nCamera.up.y, nCamera.up.z);
glMatrixMode(GL_MODELVIEW);

But I am not sure how to adjust the scale so it using gluLookAt() so the texture is fits perfect. I found an old Yann post with this, but when I did that the entire plane was colored a solid color.
	glMatrixMode(GL_TEXTURE);
glPushMatrix();
glScalef(0.5f, 0.5f, 1.0f);
glTranslatef(1.0f, 1.0f, 0.0f);

glMultMatrixf(camPointer->projMatrix);
glMultMatrixf(camPointer->modelMatrix);

// OK, the matrix is set, get back to modelview

glMatrixMode(GL_MODELVIEW);

Any help is greatly appreciated. [Edited by - skow on August 27, 2004 7:49:52 PM]

##### Share on other sites
I wrote a small class called "Reflection Matrix And Render To Texture In OpenGL". Check out the code on my home page.

##### Share on other sites
I'm getting a "The page cannot be displayed"

##### Share on other sites
Quote:
 Original post by skowI'm getting a "The page cannot be displayed"

Thanks for pointing that out, I will try and find the error and fix it.

##### Share on other sites
Cool it works now, that reflection matrix is nice to have.

Got it basicly working, now I need to try and distort the text cords, hopfully this will go smoothly.

##### Share on other sites
Hmm I'm getting this flaw when I distort the texture cords.

As you can see at the edges, the texture is distorted and leaves gaps. I really can't think of what I can do to to solve this problem other than fidning out where verts are near the edge of the screem and not distorting them (doesn't seem like a good solution).

Any suggestions?

##### Share on other sites
How did you distorted the texture coords ?
As far as i know, we cannot change them when texgen is enabled

##### Share on other sites
I'm passing in 3d cords for the projection matrix, and I'm simply adding sin(x)+cos(z) to the y component and sin(x) to x component and cos(z) to the z component. This isn't the final way I'll be distoring but the problem is taht distorting them at the edge will case the texture near the edges to extend past the 1.0, 0.0 marks causing those ugly things you see in the screenshot.

##### Share on other sites
There are couple of ways around it if you can use vertex programs. But I don't know how this can be solved using fixed function pipeline.

##### Share on other sites
Dark would I not have the same problem using a vertex shader? It would be faster but the same translation of 3d text cords would yeild the same result, would it not?

##### Share on other sites
If you use VP, then you can do things like clamp tex coordinats to 0-1 range. Or, something that might work even without VP, is to render to texture with differnt (bigger) FOV, but that is not so easy to get right. There is better alternative to this but I can't find that thread now (I know it was posted by Yann).

##### Share on other sites
Ok, I'm using a VP now so it should be easy to clap that, but first I have a problem when using the vp.

When using a VP I dont know how to get this to pass though the program.
	glMatrixMode(GL_TEXTURE);	glLoadIdentity();	glPushMatrix();	glScalef(0.5f, 0.5f, 1.0f);	glTranslatef(1.0f, 1.00f, 0.0f);	glMultMatrixf(camPointer->projMatrix);	glMultMatrixf(camPointer->modelMatrix);	glMatrixMode(GL_MODELVIEW);

So I went to try and do this in cg. I can do the multMatrix no problem but I have no idea how do the scale and translation.

My VP
vfconn main(appdata IN,	uniform float4x4 ModelViewProj,uniform float4x4 ProjMatrix){	vfconn OUT;		OUT.HPos = mul(ModelViewProj, IN.position);		OUT.Col0 = IN.color;		OUT.textcrdo = mul(ModelViewProj, IN.textcrd);	return OUT;}

##### Share on other sites
Ok I found out you can pass in the texture matrix *duh*.

But the problem is now clamping so the texture doesnt extend beyond where it should (creating the problem you see in the picture above). I can't just clap between 0 and 1, how should I go about clamping?

Here is by cg vp:
vfconn main(appdata IN,	uniform float4x4 ModelViewProj, uniform float4x4 TextureMatrix){	vfconn OUT;		float ts, tc;		ts = .5*sin(IN.position.x/2.0+IN.wave);	tc = .5*cos(IN.position.z+IN.wave);	OUT.HPos = mul(ModelViewProj, IN.position);	OUT.Col0 = IN.color;		OUT.textcrdo = IN.position;	OUT.textcrdo.x += ts;	OUT.textcrdo.y += tc+ts;		OUT.textcrdo.y += tc;				OUT.textcrdo = mul(TextureMatrix, OUT.textcrdo);	return OUT;}

Any one?

Bump :(

##### Share on other sites

I actually just fixed that same problem in my code, after realizing how obvious the solution was.

I wasnt setting my rendered texture to be clamped - it was set to repeat by default.

I told it to CLAMP_TO_EDGE and now everything works great...

##### Share on other sites
skow : is that you who's replying here ?

<rant>I always hate anonymous posters who write interesting things. It's so frustrating not to know if this is a member that couldn't log or someone else.</rant>

##### Share on other sites
Hah that worked easy!

Thanks!

##### Share on other sites

It was me, sorry about the confusion. I usually post anonymous, unless there is a real reason to do otherwise.

##### Share on other sites

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

## Create an account

Register a new account

• ### Forum Statistics

• Total Topics
628719
• Total Posts
2984384

• 25
• 11
• 10
• 15
• 14