FBOs and CG-Shaders

Started by
3 comments, last by Ekast 16 years, 8 months ago
Hello, I´m trying to render a scene to the framebuffer, use that rendered "image" as a texture and place it onto a quad. This actually works quite fine so far using "OpenGL only". Now I want to split that process into 2 passes, which means I´d like to use a CG shader to render the scene to the frame-buffer. After that the renderered texture should be mapped onto the quad using another CG-shader. The problem is, there is nothig visible on the texture but the "clear-color". I don´t perform any object rotations/translations to the scene and the cg-shaders themselves don´t do anything at the moment but transforming the vertices. To encapsulate the problem: The FBO´s without any CG shader attached work just fine, and the CG-shaders without FBO´s as well, but combining those two results in a strange output. Any idea of what it might be? ...[edit] After playing around a little bit more I came to something strange. It seems that OpenGL matrix state changes have no effect on the shaders when rendering to the framebuffer. When rendering to the screen directly with the same shaders everything workes fine. Is there a limitation passing parameters to cg-shaders when rendering to the framebuffer? Thanks in advance Ralph [Edited by - Ekast on August 5, 2007 12:18:28 PM]
Advertisement
Doesn´t anyone have an idea?
Quote:Original post by Ekast
...[edit] After playing around a little bit more I came to something strange. It seems that OpenGL matrix state changes have no effect on the shaders when rendering to the framebuffer. When rendering to the screen directly with the same shaders everything workes fine. Is there a limitation passing parameters to cg-shaders when rendering to the framebuffer?


From what I remember, you need to upload the matrices by using the functions the cg API provides. No, there is no limitation with FBO.

Are you sure your FBO is valid? Are you able to render to it without shaders?
Are you clearing the FBO before rendering to it?
Sig: http://glhlib.sourceforge.net
an open source GLU replacement library. Much more modern than GLU.
float matrix[16], inverse_matrix[16];
glhLoadIdentityf2(matrix);
glhTranslatef2(matrix, 0.0, 0.0, 5.0);
glhRotateAboutXf2(matrix, angleInRadians);
glhScalef2(matrix, 1.0, 1.0, -1.0);
glhQuickInvertMatrixf2(matrix, inverse_matrix);
glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);
The FBO is valid since I´m able to render to it and use it as a texture without activating any cg-sdhader. And yes, I clear it before rendering to it.
I think I´d better post some code to make it more clear:

glMatrixMode(GL_MODELVIEW);glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, mFbo);glClearColor(0.1f, 0.1f, 1.0f, 1.0f);glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);glLoadIdentity();glColor4f(1.0f, 0.0f, 0.0f, 1.0f);glTranslatef(0,0,-2);glRotatef(-xRot,1.0,0.0,0.0);glRotatef(-yRot,0.0,1.0,0.0);//This works fine as long as not rendering to the framebuffer:AWShaderContainer::getSingletonPtr()->ActivateShader(mFBOShaderID);glutWireTeapot(2.0f);glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);glLoadIdentity();glClearColor(0.2f, 0.3f, 0.2f, 1.0f);glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);glLoadIdentity();glTranslatef(0.0f, 0.0f, -5.0f);	//as aboveAWShaderContainer::getSingletonPtr()->ActivateShader(mTexShaderID);glBegin(GL_QUADS);glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 0.0f);glTexCoord2f(1.0f, 0.0f); glVertex3f(1.0f, -1.0f, 0.0f);glTexCoord2f(1.0f, 1.0f); glVertex3f(1.0f, 1.0f, 0.0f);glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, 0.0f);glEnd();

The called method
AWShaderContainer::getSingletonPtr()->ActivateShader(...)

takes care to pass the current modelview/projection matrix to the shader like this:
cgGLSetStateMatrixParameter(pActivatedShader->mCGParam_ModelViewMatrix, CG_GL_MODELVIEW_PROJECTION_MATRIX, CG_GL_MATRIX_IDENTITY);


This does work fine as long as I´m not rendering FBOs. If I do so like in the code above it seems that passing the matrix to the first shader "mFBOShaderID" has no effect at all. The teapot keeps on rotating as I move around but it obviously should not.

It somehow makes me crazy :-)

Ralph

[Edited by - Ekast on August 7, 2007 6:30:08 AM]
Hi,

I finally got it working. There were some strange "Pushs / and Pops" in my code.
Thanks anyways.

Ralph

This topic is closed to new replies.

Advertisement