Hello,
I’m using framebuffer object to render-to-texture, and i use it as texture to make water reflection effect.
If i use the texture without projection, the texture is ok, the scene is rendered to texture well. But i can’t use projection on to it.
Any idea or correction could be helpfully.
scrfeenshot: http://delfin.klte.hu/~fazekaim/water3.jpg
my water shaders:
public static String waterVertexShader =
"void main(void)
" +
"{
" +
" gl_Position = ftransform();
" +
" gl_TexCoord[0] = gl_TextureMatrix[0] * gl_Vertex;
" +
"}";
public static String waterFragmentShader =
"uniform sampler2D reflection;
" +
"void main (void)
" +
"{
" +
" gl_FragColor = texture2DProj(reflection,gl_TexCoord[0]);
" +
" gl_FragColor.a = 1.0;
" +
"}";
my water rendering code:
private void EnableWaterTextureMatrix(){
float[] modelMatrix = new float[16];gl.glGetFloatv(GL.GL_MODELVIEW_MATRIX, modelMatrix);
float[] projectionlMatrix = new float[16];gl.glGetFloatv(GL.GL_PROJECTION_MATRIX, projectionlMatrix);
gl.glMatrixMode( GL.GL_TEXTURE );
gl.glLoadIdentity();
gl.glScalef(0.5f, 0.5f, 1.0f);
gl.glTranslatef(1.0f, 1.0f, 0.0f);
gl.glMultMatrixf( modelMatrix );
gl.glMultMatrixf( projectionlMatrix );
gl.glMatrixMode( GL.GL_MODELVIEW );
}
private void DisableWaterTextureMatrix() {
gl.glMatrixMode( GL.GL_TEXTURE );
gl.glLoadIdentity();
gl.glMatrixMode( GL.GL_MODELVIEW );
}
public void waterrender() {
EnableWaterTextureMatrix();
gl.glEnable( GL.GL_DEPTH_TEST);
gl.glEnable(GL.GL_MULTISAMPLE_ARB);
activateTexture( 0, FBOTexture[0], GL.GL_TEXTURE_2D );
gl.glUseProgramObjectARB( waterShaderObj[0] );
gl.glUniform1iARB( waterReflection[0], 0 );
gl.glBegin( GL.GL_QUADS);
gl.glMultiTexCoord2f( 0, vertexes[0][0], vertexes[0][1] );
gl.glVertex3f( vertexes[0][0], waterLevel, vertexes[0][1] );
gl.glMultiTexCoord2f( 0, vertexes[1][0], vertexes[1][1] );
gl.glVertex3f( vertexes[1][0], waterLevel, vertexes[1][1] );
gl.glMultiTexCoord2f( 0, vertexes[2][0], vertexes[2][1] );
gl.glVertex3f( vertexes[2][0], waterLevel, vertexes[2][1] );
gl.glMultiTexCoord2f( 0, vertexes[3][0], vertexes[3][1] );
gl.glVertex3f( vertexes[3][0], waterLevel, vertexes[3][1] );
gl.glEnd();
gl.glUseProgramObjectARB( 0 );
deactivateTexture( 0, GL.GL_TEXTURE_2D );
DisableWaterTextureMatrix();
}