Hi sorry to bother again. I went back to basics and made it work… in a PYTHON prototype.
Then I decided to do a C++ prototype to check all again. The code follows of a prototype without PBO. This exact code in python works and the image read from FBO and saved is a red triangle and nothing appears on window. But in CCp is like the FBO never binds and nothing is rendered to the FBO, in fact all goes to the back buffer.
The code is very short to just summarize the issue. If any one can point me what is so wrong that the FBO is never used I would appreciate a lot.
[source ]#include "GLee.h"
#include <GL/glut.h>
#include <fstream>
#include <iostream>
float color[3];
GLuint framebuffer,colorbuffer,depthbuffer;
void renderScene(void);
void init()
{
//create a FBO
glGenFramebuffers(1, &framebuffer);
glBindFramebuffer(GL_FRAMEBUFFER_EXT, framebuffer);
// Setup depthbuffer and colorbuffer
glGenRenderbuffers(1,&depthbuffer);
glGenRenderbuffersEXT(1,&colorbuffer);
glBindRenderbufferEXT (GL_RENDERBUFFER_EXT,depthbuffer);
glRenderbufferStorageEXT (GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT, 1024, 1024);
glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT,GL_RENDERBUFFER_EXT, depthbuffer);
glBindRenderbufferEXT (GL_RENDERBUFFER_EXT,colorbuffer);
glRenderbufferStorageEXT (GL_RENDERBUFFER_EXT, GL_RGBA, 1024, 1024);
glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT,
GL_RENDERBUFFER_EXT, colorbuffer);
GLuint status = glCheckFramebufferStatusEXT (GL_FRAMEBUFFER_EXT);
if( status != GL_FRAMEBUFFER_COMPLETE)
{
std::cout<< "Error in framebuffer activation:"<<status<<std::endl;
}
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, framebuffer);
glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT);
glViewport (0, 0, 1024, 1024);
//make render red
color[0]=1.0f;
color[1]=0.0f;
color[2]=0.0f;
//render
renderScene();
//read data from the buffer
glReadBuffer(GL_COLOR_ATTACHMENT0_EXT);
char * data = new char[1024*1024*4];
glReadPixels (0, 0, 1024, 1024, GL_RGBA, GL_UNSIGNED_BYTE,data);
//write to file
std::ofstream file("/tmp/foca.raw");
file.write(data,1024*1024*4);
delete[] data;
//make it render green
color[0]=0.0f;
color[1]=1.0f;
color[2]=0.0f;
}
void renderScene(void)
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glColor3fv(color);
glBegin(GL_TRIANGLES);
glVertex3f(-0.5,-0.5,0.0);
glVertex3f(0.5,0.0,0.0);
glVertex3f(0.0,0.5,0.0);
glEnd();
glutSwapBuffers();
}
int main(int argc, char **argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGB);
glutInitWindowPosition(100,100);
glutInitWindowSize(256,256);
glutCreateWindow(“I HATE FBOs!!”);
GLeeInit();
init();
glutDisplayFunc(renderScene);
glutMainLoop();
}
[/source]