0
votes

I'm doing an SDL/OpenGL project on MinGW Windows Code::Blocks 12.11, using GLEW. I'm trying to implement 2D off-screen rendering, so that I can eventually try some fragment shader effects.

Here is the scene rendered to the default framebuffer:

Scene Normal

However, if I render the scene to a Framebuffer Object's texture (called fbo_texture) and then try and render that to a full-screen quad, I get this:

Scene with Framebuffer Object

The image appears flipped, mirrored and green. I'm pretty sure that the rendering to the Framebuffer is working correctly, but for the life of me I can't figure out why the texture is appearing so skewed.

Here is how I tried to render fbo_texture to a textured quad, after calling glBindFramebufferEXT(GL_FRAMEBUFFER_EXT,0). I am using glMatrixMode(GL_MODELVIEW) and glOrtho(0, screen_width, screen_height, 0, 0, 1) when the program initializes. Screen_width is 400 and screen_height is 400.

glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, fbo_texture);
glBegin(GL_QUADS);
    x1= 0.5;
    x2= 400.5;
    y1= 0.5;
    y2 = 400.5;
    glTexCoord2f(0.0f, 0.0f); glVertex2f(x1, y1);
    glTexCoord2f(1.0f, 0.0f); glVertex2f(x2, y1);
    glTexCoord2f(0.0f, 1.0f); glVertex2f(x2, y2);
    glTexCoord2f(1.0f, 1.0f); glVertex2f(x1, y2);
glEnd();


glDisable(GL_TEXTURE_2D);

I really appreciate any help, please let me know if I should provide any more information.

1
also- I did not use a depth buffer at all, is that a problem for 2D rendering?Luminaire
No, you do not need a depth buffer for 2D rendering. Technically you do not even need it for 3D rendering if you can perfectly sort your geometry... but there are many cases where you cannot (such as intersecting objects) or would not want to (since it unnecessarily wastes fillrate) perfectly sort your draws from back-to-front.Andon M. Coleman
oh good it always worries me in the back of my head that that is the problemLuminaire

1 Answers

2
votes

This might not be your only problem, but from the part you show, two vertices are swapped in your texture coordinates. The 3rd of the 4 vertices is the top-right corner, with coordinates (x2, y2), so it should have texture coordinates (1.0f, 1.0f):

glTexCoord2f(0.0f, 0.0f); glVertex2f(x1, y1);
glTexCoord2f(1.0f, 0.0f); glVertex2f(x2, y1);
glTexCoord2f(1.0f, 1.0f); glVertex2f(x2, y2);
glTexCoord2f(0.0f, 1.0f); glVertex2f(x1, y2);

You're also saying that you call glOrtho() after glMatrixMode(GL_MODELVIEW). glOrtho() sets a projection matrix, so it should normally be called after glMatrixMode(GL_PROJECTION).