How can I achieve a reflection of a texture like on this image: http://weblogs.java.net/blog/campbell/archive/images/ba3d.png ?
FLip your geometry, and use a fragmentshader to blend to black, depending on the Y (up) axis
I am new to shaders, is there any tutorial that exemplifies a simple reflection from a quad or something?
quad 1: (4 white vertices)
1.0 1.0 0.0 1.0
1.0 0.0 0.0 0.0
quad 2: (top vertices white, bottom vertices black)
1.0 0.0 0.0 0.0
1.0 -1.0 0.0 -1.0
Thanks,
so in this image: http://weblogs.java.net/blog/campbell/archive/images/ba3d.png, it´s actually using two quads, one for the actuall picture and one for the reflecting picture?
Yes, there is no such thing as reflection in OpenGL.
Thanks again. I will make a try and return here if I don´t succeed.
I have now succeeded in creating a quad below the main quad:
gl.glBegin(gl.GL_QUADS);
gl.glTexCoord2f(0.0f, 0.0f); gl.glVertex3f(topLeft, 1.0f, 0.0f);
gl.glTexCoord2f(1.0f, 0.0f); gl.glVertex3f(topRight, 1.0f, 0);
gl.glTexCoord2f(1.0f, 1.0f); gl.glVertex3f(bottomRight, -1.0f, 0);
gl.glTexCoord2f(0.0f, 1.0f); gl.glVertex3f(bottomLeft, -1.0f, 0.0f);
gl.glEnd();
// Second quad - "the reflection quad"
gl.glBegin(gl.GL_QUADS);
gl.glTexCoord2f(0.0f, 0.0f); gl.glVertex3f(topLeft, -1.0f, 0.0f);
gl.glTexCoord2f(1.0f, 0.0f); gl.glVertex3f(topRight, -1.0f, 0);
gl.glTexCoord2f(1.0f, 1.0f); gl.glVertex3f(bottomRight, -3.0f, 0);
gl.glTexCoord2f(0.0f, 1.0f); gl.glVertex3f(bottomLeft, -3.0f, 0.0f);
gl.glEnd();
The problem is that the image on the reflection quads is not upside-down as I want it to be.
If I add
gl.glRotated(180,0,0,0);
everything is messed up since I am creating a lot of quads with binded textures in a loop.
How to I rotate every “reflection quad” 180 degrees without messing up the first quads?
Flip the texture coords on one axis (usually the y axis). So all the v coords which are 0 become 1 and those that are 1 become 0.
Thanks, that made them upside-down, but I would also like to reverse the images. How is that possible?