1
\$\begingroup\$

This is my first post here so any help would be massively appreciated :)

I'm using C++ with SDL and OpenGL 3.3

When rendering directly to screen I get the following result

Render To Screen

And when I render to texture I this happens

Render To Texture

Anti-aliasing is turned off for both. I'm guessing this has something to do with depth buffer accuracy but I've tried a lot of different methods to improve the result but, no success :( I'm currently using the following code to set up my FBO:

GLuint frameBufferID;
glGenFramebuffers(1, &frameBufferID);
glBindFramebuffer(GL_FRAMEBUFFER, frameBufferID);

glGenTextures(1, &coloursTextureID);

glBindTexture(GL_TEXTURE_2D, coloursTextureID);
glTexImage2D(GL_TEXTURE_2D,0,GL_RGB,SCREEN_WIDTH,SCREEN_HEIGHT,0,GL_RGB,GL_UNSIGNED_BYTE,NULL);

glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);



//Depth buffer setup

GLuint depthrenderbuffer;
glGenRenderbuffers(1, &depthrenderbuffer);
glBindRenderbuffer(GL_RENDERBUFFER, depthrenderbuffer);
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT24, SCREEN_WIDTH,SCREEN_HEIGHT);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depthrenderbuffer);


glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, coloursTextureID, 0);

GLenum DrawBuffers[1] = {GL_COLOR_ATTACHMENT0};
glDrawBuffers(1, DrawBuffers); // 

if(glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
        return false;

Thank you so much for any help :)

\$\endgroup\$
4
  • \$\begingroup\$ I fixed it!!!!! Finally!!!!! Turns out all that was required was a tiny change in the line: glTexImage2D(GL_TEXTURE_2D,0,GL_RGB,SCREEN_WIDTH,SCREEN_HEIGHT,0,GL_RGB,GL_UNSIGNED_BYTE,0); to glTexImage2D(GL_TEXTURE_2D,0,GL_RGB32F,SCREEN_WIDTH,SCREEN_HEIGHT,0,GL_RGB,GL_UNSIGNED_BYTE,0); This tutorial saved the day! Any help understanding why changing GL_RGB to GL_RGB32F solved the problem would still be greatly appreciated! Thanks to Heckel for helping reformat my question :) \$\endgroup\$ Jul 24, 2014 at 0:15
  • 1
    \$\begingroup\$ That's very odd that changing the color buffer format would have that result. After all the screen is not a 32F buffer, but you could render to the screen without those artifacts. Using a 32F buffer will also hurt performance if you are rendering a lot to it (though it might not matter for you now). \$\endgroup\$ Jul 24, 2014 at 1:23
  • \$\begingroup\$ Be sure to submit your own answer on the question & accept it so others can find it :) \$\endgroup\$
    – agmcleod
    Jul 24, 2014 at 12:42
  • \$\begingroup\$ @Nathan yeah it is strange as it looked like a problem with the depth buffer, sad to hear it will reduce performance but it seems to be fine at the moment. \$\endgroup\$ Jul 25, 2014 at 9:18

1 Answer 1

1
\$\begingroup\$

I fixed it!!!!! Finally!!!!!

Turns out all that was required was a tiny change in the line:

    glTexImage2D(GL_TEXTURE_2D,0,GL_RGB,SCREEN_WIDTH,SCREEN_HEIGHT,0,GL_RGB,GL_UNSIG‌NED_BYTE,0); 

to

    glTexImage2D(GL_TEXTURE_2D,0,GL_RGB32F,SCREEN_WIDTH,SCREEN_HEIGHT,0,GL_RGB,GL_UN‌​SIGNED_BYTE,0); 

This tutorial saved the day! Any help understanding why changing GL_RGB to GL_RGB32F solved the problem would still be greatly appreciated! Thanks to Heckel for helping reformat my question :)

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .