alopesajr
06-13-05, 08:09 AM
Hi,
I'm trying to use the FBO Extension in Linux (using the latest NVidia driver) but it doesnt work as it should. I tried to draw 2 triangles and recover the image as a texture, but the texture I got is all black....
That is what I'm doing:
/// ************************************************** *********************
//// ************************************************** *********************
void draw() {
glBegin(GL_TRIANGLE_STRIP);
glColor4f(1.0, 0.0, 0.0, 1.0);
glVertex3i(wTexture, hTexture/2, 1);
glColor4f(0.0, 1.0, 0.0, 1.0);
glVertex3i(wTexture/2, hTexture, 1);
glColor4f(0.0, 0.0, 1.0, 1.0);
glVertex3i(wTexture/2, 0, 1);
glColor4f(1.0, 1.0, 1.0, 1.0);
glVertex3i(0, hTexture/2, 1);
glEnd();
glBegin(GL_TRIANGLE_STRIP);
glColor4f(1.0, 0.0, 0.0, 1.0);
glVertex3i(3*wTexture/4, hTexture/4, 1);
glColor4f(0.0, 1.0, 0.0, 1.0);
glVertex3i(3*wTexture/4, 3*hTexture/4, 1);
glColor4f(0.0, 0.0, 1.0, 1.0);
glVertex3i(wTexture/4, hTexture/4, 1);
glColor4f(1.0, 1.0, 1.0, 1.0);
glVertex3i(wTexture/4, 3*hTexture/4, 1);
glEnd();
}
/// ************************************************** *********************
/// ************************************************** *********************
void stopFBO() {
if(indFB)
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
}
/// ************************************************** *********************
/// ************************************************** *********************
void keyboard(unsigned char key, int x, int y) {
switch (key) {
case 'F' :
case 'f' : initializeFBO (wTexture, hTexture);
renderToTextureFBO();
draw();
stopFBO();
renderFBO = true;
break;
....
glutPostRedisplay();
}
/// ************************************************** *********************
/// ************************************************** *********************
bool initializeFBO(int width, int height) {
// Ensure we have the necessary OpenGL FBO extensions.
if (glewGetExtension("GL_EXT_framebuffer_object") != GL_TRUE) {
cout << "Driver does not support FBO extension" << endl;
return false;
}
else
cout << "Driver does support FBO extension !!!" << endl;
hFBO = height;
wFBO = width;
if(wFBO <= 0 || hFBO <= 0) {
cout << "Width and height of FBO must be positive" << endl;
return false;
}
else
cout << "FBO size: " << int(wFBO) << " , " << int(hFBO) << ">" << endl;
glGenFramebuffersEXT(1, &indFB);
if(indFB)
cout << "GenFBO sucessifull !!! (" << indFB << ")" << endl;
else {
cout << "GenFBO failed !!" << endl;
return false;
}
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, indFB);
glGenRenderbuffersEXT(1, &indRB);
glBindRenderbufferEXT ( GL_RENDERBUFFER_EXT, indRB);
glRenderbufferStorageEXT ( GL_RENDERBUFFER_EXT,
GL_RGBA,
wFBO,
hFBO);
glFramebufferRenderbufferEXT ( GL_FRAMEBUFFER_EXT,
GL_COLOR_ATTACHMENT0_EXT,
GL_RENDERBUFFER_EXT,
indRB);
bool result = checkFrameBufferStatus();
return result;
}
/// ************************************************** *********************
/// ************************************************** *********************
bool renderToTextureFBO() {
cout << "Starting RenderToTextureFBO...." << endl;
glBindTexture( GL_TEXTURE_2D, tex);
// glActiveTexture(GL_TEXTURE1);
glFramebufferTexture2DEXT( GL_FRAMEBUFFER_EXT,
GL_COLOR_ATTACHMENT0_EXT,
GL_TEXTURE_2D,
tex,
0);
// attach renderbufferto framebufferdepth buffer
glFramebufferRenderbufferEXT ( GL_FRAMEBUFFER_EXT,
GL_COLOR_ATTACHMENT0_EXT,
GL_RENDERBUFFER_EXT,
indRB);
bool result = checkFrameBufferStatus();
return result;
}
/// ************************************************** *********************
/// ************************************************** *********************
void display(void) {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glViewport(0, 0, wTexture, hTexture);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, wTexture, 0, hTexture, -10, 10);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
drawAxis();
glEnable(GL_TEXTURE_2D);
if (renderFBO)
glBindTexture(GL_TEXTURE_2D, tex);
glBegin(GL_TRIANGLE_STRIP);
glTexCoord2f( 1.0, 0.0);
glVertex3i(wTexture, 0, 0);
glTexCoord2f( 1.0, 1.0);
glVertex3i(wTexture, hTexture, 0);
glTexCoord2f(0.0, 0.0);
glVertex3i(0, 0, 0);
glTexCoord2f(0.0, 1.0);
glVertex3i(0, hTexture, 0);
glEnd();
glDisable(GL_TEXTURE_2D);
if (!renderFBO)
draw();
glutSwapBuffers();
}
/// ************************************************** *********************
/// ************************************************** *********************
Does anyone have a demo code that works ? I downloaded some demos in this forum but all use the SXMLEngine which is not portable.
Thanks a lot for any help !!
Best Regards,
I'm trying to use the FBO Extension in Linux (using the latest NVidia driver) but it doesnt work as it should. I tried to draw 2 triangles and recover the image as a texture, but the texture I got is all black....
That is what I'm doing:
/// ************************************************** *********************
//// ************************************************** *********************
void draw() {
glBegin(GL_TRIANGLE_STRIP);
glColor4f(1.0, 0.0, 0.0, 1.0);
glVertex3i(wTexture, hTexture/2, 1);
glColor4f(0.0, 1.0, 0.0, 1.0);
glVertex3i(wTexture/2, hTexture, 1);
glColor4f(0.0, 0.0, 1.0, 1.0);
glVertex3i(wTexture/2, 0, 1);
glColor4f(1.0, 1.0, 1.0, 1.0);
glVertex3i(0, hTexture/2, 1);
glEnd();
glBegin(GL_TRIANGLE_STRIP);
glColor4f(1.0, 0.0, 0.0, 1.0);
glVertex3i(3*wTexture/4, hTexture/4, 1);
glColor4f(0.0, 1.0, 0.0, 1.0);
glVertex3i(3*wTexture/4, 3*hTexture/4, 1);
glColor4f(0.0, 0.0, 1.0, 1.0);
glVertex3i(wTexture/4, hTexture/4, 1);
glColor4f(1.0, 1.0, 1.0, 1.0);
glVertex3i(wTexture/4, 3*hTexture/4, 1);
glEnd();
}
/// ************************************************** *********************
/// ************************************************** *********************
void stopFBO() {
if(indFB)
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
}
/// ************************************************** *********************
/// ************************************************** *********************
void keyboard(unsigned char key, int x, int y) {
switch (key) {
case 'F' :
case 'f' : initializeFBO (wTexture, hTexture);
renderToTextureFBO();
draw();
stopFBO();
renderFBO = true;
break;
....
glutPostRedisplay();
}
/// ************************************************** *********************
/// ************************************************** *********************
bool initializeFBO(int width, int height) {
// Ensure we have the necessary OpenGL FBO extensions.
if (glewGetExtension("GL_EXT_framebuffer_object") != GL_TRUE) {
cout << "Driver does not support FBO extension" << endl;
return false;
}
else
cout << "Driver does support FBO extension !!!" << endl;
hFBO = height;
wFBO = width;
if(wFBO <= 0 || hFBO <= 0) {
cout << "Width and height of FBO must be positive" << endl;
return false;
}
else
cout << "FBO size: " << int(wFBO) << " , " << int(hFBO) << ">" << endl;
glGenFramebuffersEXT(1, &indFB);
if(indFB)
cout << "GenFBO sucessifull !!! (" << indFB << ")" << endl;
else {
cout << "GenFBO failed !!" << endl;
return false;
}
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, indFB);
glGenRenderbuffersEXT(1, &indRB);
glBindRenderbufferEXT ( GL_RENDERBUFFER_EXT, indRB);
glRenderbufferStorageEXT ( GL_RENDERBUFFER_EXT,
GL_RGBA,
wFBO,
hFBO);
glFramebufferRenderbufferEXT ( GL_FRAMEBUFFER_EXT,
GL_COLOR_ATTACHMENT0_EXT,
GL_RENDERBUFFER_EXT,
indRB);
bool result = checkFrameBufferStatus();
return result;
}
/// ************************************************** *********************
/// ************************************************** *********************
bool renderToTextureFBO() {
cout << "Starting RenderToTextureFBO...." << endl;
glBindTexture( GL_TEXTURE_2D, tex);
// glActiveTexture(GL_TEXTURE1);
glFramebufferTexture2DEXT( GL_FRAMEBUFFER_EXT,
GL_COLOR_ATTACHMENT0_EXT,
GL_TEXTURE_2D,
tex,
0);
// attach renderbufferto framebufferdepth buffer
glFramebufferRenderbufferEXT ( GL_FRAMEBUFFER_EXT,
GL_COLOR_ATTACHMENT0_EXT,
GL_RENDERBUFFER_EXT,
indRB);
bool result = checkFrameBufferStatus();
return result;
}
/// ************************************************** *********************
/// ************************************************** *********************
void display(void) {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glViewport(0, 0, wTexture, hTexture);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, wTexture, 0, hTexture, -10, 10);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
drawAxis();
glEnable(GL_TEXTURE_2D);
if (renderFBO)
glBindTexture(GL_TEXTURE_2D, tex);
glBegin(GL_TRIANGLE_STRIP);
glTexCoord2f( 1.0, 0.0);
glVertex3i(wTexture, 0, 0);
glTexCoord2f( 1.0, 1.0);
glVertex3i(wTexture, hTexture, 0);
glTexCoord2f(0.0, 0.0);
glVertex3i(0, 0, 0);
glTexCoord2f(0.0, 1.0);
glVertex3i(0, hTexture, 0);
glEnd();
glDisable(GL_TEXTURE_2D);
if (!renderFBO)
draw();
glutSwapBuffers();
}
/// ************************************************** *********************
/// ************************************************** *********************
Does anyone have a demo code that works ? I downloaded some demos in this forum but all use the SXMLEngine which is not portable.
Thanks a lot for any help !!
Best Regards,