Sign in to follow this  
Ekast

OpenGL FBOs and CG-Shaders

Recommended Posts

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]

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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 above
AWShaderContainer::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]

Share this post


Link to post
Share on other sites
Hi,

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

Ralph

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this