PDA

View Full Version : problem computing ... (solved)



fazekaim
07-11-2005, 11:44 AM
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)\n" +
"{\n" +
" gl_Position = ftransform();\n" +
" gl_TexCoord[0] = gl_TextureMatrix[0] * gl_Vertex;\n" +
"}";

public static String waterFragmentShader =
"uniform sampler2D reflection;\n" +
"void main (void)\n" +
"{\n" +
" gl_FragColor = texture2DProj(reflection,gl_TexCoord[0]);\n" +
" gl_FragColor.a = 1.0;\n" +
"}";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();
}

fenris
07-11-2005, 01:55 PM
Try setting the translation vector for your water texture matrix to 0.5, 0.5, 0. You want to project from the center of the texture, not the edge.

fazekaim
07-11-2005, 09:05 PM
Thanks, i tried it, but nothing has changed.
I tried to use more vertexes (1024 and not 4) in the water plane, without better result.

fazekaim
07-12-2005, 12:24 AM
It is working...

I had to change these statements: from
gl.glMultMatrixf( projectionlMatrix );
gl.glMultMatrixf( modelMatrix );
to this:
gl.glMultMatrixf( modelMatrix );
gl.glMultMatrixf( projectionlMatrix );

Oh, i'm so stupid. :)