Original Post
I need to use a Framebuffer object in my current project and I have never worked with them before. I read several tutorials, and the help provided here: http://www.opengl.org/wiki/Framebuffer_Object
But my own system is not working. I have debugged, and what I found was that after I generate the texture id and bind it to GL_FRAMEBUFFER and then attach a texture to the first color buffer the function glIsFramebuffer returns false, as does glIsBuffer. (I wasn't sure if there was a difference there.)
Here is my code for creating the FBO. If you need to see anything else ask, but I am not sure that it would be relevant unless this problem gets solved.
Thanks for the help.
EDIT: Ok this is embarrassing but I figured out the above problem, the fbo now works... kinda... I have a different problem though.
(Above the problem was I used glGenBuffers which, it turns out is different than glGenFramebuffers)
So now I have a new problem, when I try to draw the texture onto the screen it does not show up. I know that I am binding the framebuffer correctly because if I leave it (don't bind back to the screen) it flashes black and white (which is it flipping the buffers on the screen with nothing on them due to all the rendering going to my own framebuffer). I know that its not any of my rendering settings because when I don't leave it bound my normal sprites work correctly, moving as they should. I have tried setting the matrices up for the surface when I try to render to it. (I am not sure if I need to do that). I have tried using the matrices with the screen settings, with settings to match the texture size, and with settings of glOrtho(0,1,1,0,-1,1). (If I didn't mention this is 2D not 3D). Even if the sprites are not rendering correctly I tried clearing the texture with black and it is not showing up even now.
Here is my rendering to the fbo code
And here is my function for rendering the surface
But my own system is not working. I have debugged, and what I found was that after I generate the texture id and bind it to GL_FRAMEBUFFER and then attach a texture to the first color buffer the function glIsFramebuffer returns false, as does glIsBuffer. (I wasn't sure if there was a difference there.)
Here is my code for creating the FBO. If you need to see anything else ask, but I am not sure that it would be relevant unless this problem gets solved.
// texture
GLuint tex;
glGenTextures(1,&tex);
glBindTexture(GL_TEXTURE_RECTANGLE_NV,tex);
glTexImage2D(GL_TEXTURE_RECTANGLE_NV,0,GL_RGBA8,w,h,0,GL_RGBA,GL_UNSIGNED_BYTE,0); // should generate blank pixel data
glTexParameteri(GL_TEXTURE_RECTANGLE_NV,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_RECTANGLE_NV,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
bool is = glIsTexture(tex);
if (!is)
throw "texture not real";
GLuint fbo, ren;
// render buffer - not sure if this is required
glGenRenderbuffers(1, &ren);
glBindRenderbuffer(GL_RENDERBUFFER,ren);
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, w, h);
// framebuffer
glGenBuffers(1,&fbo);
glBindBuffer(GL_FRAMEBUFFER,fbo);
// attachments
glFramebufferTexture2D(GL_FRAMEBUFFER,GL_COLOR_ATTACHMENT0,GL_TEXTURE_RECTANGLE_NV,tex,0);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, ren);
is = glIsBuffer(fbo);
if (!is)
throw "framebuffer not real";
auto er = glCheckFramebufferStatus(GL_FRAMEBUFFER);
if (er != GL_FRAMEBUFFER_COMPLETE){
throw "framebuffer failed to complete";
}
ptr->fboid = fbo;
ptr->tid = tex;
glClearColor(1,1,1,1);
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glBindFramebuffer(GL_FRAMEBUFFER,0);Thanks for the help.
EDIT: Ok this is embarrassing but I figured out the above problem, the fbo now works... kinda... I have a different problem though.
(Above the problem was I used glGenBuffers which, it turns out is different than glGenFramebuffers)
So now I have a new problem, when I try to draw the texture onto the screen it does not show up. I know that I am binding the framebuffer correctly because if I leave it (don't bind back to the screen) it flashes black and white (which is it flipping the buffers on the screen with nothing on them due to all the rendering going to my own framebuffer). I know that its not any of my rendering settings because when I don't leave it bound my normal sprites work correctly, moving as they should. I have tried setting the matrices up for the surface when I try to render to it. (I am not sure if I need to do that). I have tried using the matrices with the screen settings, with settings to match the texture size, and with settings of glOrtho(0,1,1,0,-1,1). (If I didn't mention this is 2D not 3D). Even if the sprites are not rendering correctly I tried clearing the texture with black and it is not showing up even now.
Here is my rendering to the fbo code
ore::Surface surface;
ore::SurfaceF::New(&surface,100,100);
ore::Screen::Set(&surface);
/*
glMatrixMode(GL_PROJECTION); // projection
glPushMatrix();
glLoadIdentity();
glOrtho(0, 100, 100, 0, -50, 50);
glMatrixMode(GL_MODELVIEW); // modelview
glPushMatrix();
glLoadIdentity();
*/
ore::SpriteF::Render(&spinner,25,50);
ore::SpriteF::Render(&spinner,75,50);
ore::Screen::Reset();
/*
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
glPopMatrix();
*/
And here is my function for rendering the surface
int w = ptr->w,
h = ptr->h;
glBindTexture(GL_TEXTURE_RECTANGLE_NV,ptr->tid);
glBegin(GL_QUADS);
{
glTexCoord2i(0, 0); glVertex2i(x, y);
glTexCoord2i(w, 0); glVertex2i(x+w, y);
glTexCoord2i(w, h); glVertex2i(x+w, y+h);
glTexCoord2i(0, h); glVertex2i(x, y+h);
}
glEnd();