PDA

View Full Version : glBlitFramebuffer() not working as expected??



noobscratcher
12-22-2011, 09:20 AM
Hello I'm creating a game using OpenGL for the vertexes and texturing them with SDL_Surfaces with images loaded in them and because of that I'm using SDL



glReadBuffer(GL_FRONT_AND_BACK);

glDrawBuffer(GL_FRONT_AND_BACK);

glBlitFramebuffer(640, 480, 640,480,
640, 480,640, 480,
(GL_COLOR_BUFFER_BIT,GL_DEPTH_BUFFER_BIT,GL_STENCI L_BUFFER_BIT),GL_NEAREST);


It doesn't seem to work as expected which is that it should Blit the framebuffer too the other framebuffer which I setup with glReadBuffer(GL_FRONT); and glDrawBuffer(GL_BACK); when I switch the buffers with this function SDL_GL_SwapBuffers(); it just shows the black back framebuffer instead of the front buffer onto the framebuffer.

I'm Using OpenGL 3.3 and SDL 1.2

Could someone tell me if I'm doing it wrong or doing it the right way but missing a step also how to do so thank you?.

thokra
12-22-2011, 09:39 AM
The above code shouldn't even compile since the mask isn't ORed together but seperated by commas. Furthermore, why would you blit the the front and back buffers anyway? Why even bother with the front buffer? In a double buffered setting, the front buffer is merely used for displaying the last frame while the current frame is being rendered to the back buffer. The content of the back buffer is automatically copied to the front buffer on swap. Add to that, you're blitting the buffers to themselves.

I really don't think you need framebuffer blitting. Are you working with framebuffer objects or just the default framebuffer?

I just realized that you've probably never had a good look at the spec or the API reference page. Can you tell me how you would copy an area determined by (640, 480) to (640, 480)? Add to that, the ref page states: "If the source and destination rectangles overlap or are the same, and the read and draw buffers are the same, the result of the operation is undefined." So your above code will never, ever, work.

noobscratcher
12-22-2011, 10:01 AM
and I'm just doing it how any other knew person would do it. "stupidly"

so how do I do it the right way can you give me a code sample that works?

thokra
12-22-2011, 10:36 AM
You simply don't blit. You don't need to blit the back buffer to the front buffer. The window system does that for you.

noobscratcher
12-22-2011, 10:37 AM
so how do I update the SDL version of OpenGL context without using SDL_GL_SwapBuffers();? because that's What I read glBlitFramebuffer(); does.

heres the link glBlitFramebuffer() (http://www.opengl.org/sdk/docs/man3/xhtml/glBlitFramebuffer.xml)

Alfonse Reinheart
12-22-2011, 10:45 AM
It doesn't seem to work as expected which is that it should Blit the framebuffer too the other framebuffer which I setup with glReadBuffer(GL_FRONT); and glDrawBuffer(GL_BACK); when I switch the buffers with this function SDL_GL_SwapBuffers(); it just shows the black back framebuffer instead of the front buffer onto the framebuffer.

I don't understand what you're saying here.

The way rendering generally works is that you render to the back buffer. Then you swap the back and front buffers, so that the user can actually see what you rendered. This is done with an OS-dependent call, which SDL_GL_SwapBuffers() calls for you.

In short, for common rendering, you don't need framebuffer blitting. The system handles that for you.


The above code shouldn't even compile since the mask isn't ORed together but seperated by commas.

Why shouldn't it compile? The comma operator is well-defined in both C and C++.

It doesn't OR the components together, but the statement is well-defined and has a predictable result. Not the one that the user wants, but a predictable one none-the-less.


and I'm just doing it how any other knew person would do it.

Generally, most new people would look up the reference for `glBlitFramebuffer` and see how it works. At the very least, they'd get the rectangle part right.

noobscratcher
12-22-2011, 10:47 AM
What do I need to "do" too update the opengl Context :)

Alfonse Reinheart
12-22-2011, 10:56 AM
Did you not read this line:


This is done with an OS-dependent call, which SDL_GL_SwapBuffers() calls for you.

So just call that.

noobscratcher
12-22-2011, 11:05 AM
when I call that it swaps the buffer updates the screen and the background that was already on the buffer will be gone and will show a blank screen with the vertex ontop on the backbuffer which is not what I want :)

What I want is to SDL_GL_SwapBuffer(); and still have the contents of the frontbuffer on the backbuffer with the knew vertex "not a blank screen with the vertex".

if thats not possible with SDL_GL_SwapBuffers() which I assume it is from testing it then how?

Alfonse Reinheart
12-22-2011, 11:34 AM
Just redraw the background just like everyone else.

noobscratcher
12-22-2011, 11:35 AM
How :) ??? in code?

thokra
12-22-2011, 02:46 PM
Oh boy. I'd strongly suggest you pick up a random beginner's book on OpenGL or read an online tutorial. Just like me when I got my statement totally wrong:


Why shouldn't it compile? The comma operator is well-defined in both C and C++.

Yeah, just had a look at it. I've never used or seen this anywhere. Thanks for the hint. :)