Using FBOs with SDL 2.0 and OpenGL

Hi.

I’m currently porting a game engine to iOS. The game engine is using the latest SDL 2.0 and OpenGL for rendering.
I have now gotten the port to the point where everything works except one thing:

Binding another framebuffer causes the screen to render black even when rebinding the default framebuffer using glBindFramebuffer(GL_FRAMEBUFFER, 0);

On a previous project where I used pure OpenGL ES2 on iOS I learned that in order to reset the default FBO i needed to use https://developer.apple.com/library/ios/documentation/glkit/reference/glkview_classreference/Reference/Reference.html#//apple_ref/occ/instm/GLKView/bindDrawable

How can this be achieved using SDL 2.0? What is the correct way of dealing with offscreen FBOs using SDL 2.0?

  • Asbjoern

Use GL_FRAMEBUFFER_BINDING to get the currently bound framebufferOn Mon, May 5, 2014 at 7:33 AM, AsbjoernS wrote:

Hi.

I’m currently porting a game engine to iOS. The game engine is using the
latest SDL 2.0 and OpenGL for rendering.
I have now gotten the port to the point where everything works except one
thing:

Binding another framebuffer causes the screen to render black even when
rebinding the default framebuffer using glBindFramebuffer(GL_FRAMEBUFFER,
0);

On a previous project where I used pure OpenGL ES2 on iOS I learned that in
order to reset the default FBO i needed to use
https://developer.apple.com/library/ios/documentation/glkit/reference/glkview_classreference/Reference/Reference.html#//apple_ref/occ/instm/GLKView/bindDrawable

How can this be achieved using SDL 2.0? What is the correct way of dealing
with offscreen FBOs using SDL 2.0?

  • Asbjoern

SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Well that was easy…

Thank you Andre!

-Asbjoern

Binding another framebuffer causes the screen to render black even when
rebinding the default framebuffer using
glBindFramebuffer(GL_FRAMEBUFFER, 0);

On a previous project where I used pure OpenGL ES2 on iOS I learned that
in order to reset the default FBO i needed to use
https://developer.apple.com/library/ios/documentation/glkit/reference/glkview_classreference/Reference/Reference.html#//apple_ref/occ/instm/GLKView/bindDrawable

How can this be achieved using SDL 2.0? What is the correct way of
dealing with offscreen FBOs using SDL 2.0?

Right after creating the GL context, before binding another FBO…

 GLuint window_fbo = 0;
 glGetIntegerv(GL_FRAMEBUFFER_BINDING, &window_fbo);

…and then rebind window_fbo instead of zero when you’re ready to draw
to the window. In iOS (or maybe GLES in general? I don’t know),
framebuffer 0 is not how you get back to the window’s backbuffer.

–ryan.

GLES on Android (on devices that I’ve seen) does use 0 for the default
framebuffer index. Of course, don’t count on it as long as any exceptions
exist (iOS).

Jonny DOn Mon, May 5, 2014 at 12:06 PM, Ryan C. Gordon wrote:

Binding another framebuffer causes the screen to render black even when

rebinding the default framebuffer using
glBindFramebuffer(GL_FRAMEBUFFER, 0);

On a previous project where I used pure OpenGL ES2 on iOS I learned that
in order to reset the default FBO i needed to use
https://developer.apple.com/library/ios/documentation/
glkit/reference/glkview_classreference/Reference/
Reference.html#//apple_ref/occ/instm/GLKView/bindDrawable

How can this be achieved using SDL 2.0? What is the correct way of
dealing with offscreen FBOs using SDL 2.0?

Right after creating the GL context, before binding another FBO…

GLuint window_fbo = 0;
glGetIntegerv(GL_FRAMEBUFFER_BINDING, &window_fbo);

…and then rebind window_fbo instead of zero when you’re ready to draw to
the window. In iOS (or maybe GLES in general? I don’t know), framebuffer 0
is not how you get back to the window’s backbuffer.

–ryan.


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

My own anecdotal data is this:
Windows OpenGL: system fbo is 0.
Linux X11 OpenGL: system fbo is 0. (No idea about Wayland)
OSX Cocoa OpenGL: system fbo is 0.
Android OpenGL: system fbo is 0.
iPhoneOS Simulator: system fbo is 0.
iPhoneOS Device: system fbo is NOT 0.

Take note of that last one, Ryan’s advice mirrors my own, always use the glGetIntegerv(GL_FRAMEBUFFER_BINDING, &window_fbo); at startup and use it religiously, this is an inconvenient piece of global
state but if iPhoneOS is a target you must consider it.On 05/05/2014 11:03 AM, Jonathan Dearborn wrote:

GLES on Android (on devices that I’ve seen) does use 0 for the default framebuffer index. Of course, don’t count on it as long as any exceptions exist (iOS).

Jonny D

On Mon, May 5, 2014 at 12:06 PM, Ryan C. Gordon <icculus at icculus.org <mailto:icculus at icculus.org>> wrote:

    Binding another framebuffer causes the screen to render black even when
    rebinding the default framebuffer using
    glBindFramebuffer(GL___FRAMEBUFFER, 0);

    On a previous project where I used pure OpenGL ES2 on iOS I learned that
    in order to reset the default FBO i needed to use
    https://developer.apple.com/__library/ios/documentation/__glkit/reference/glkview___classreference/Reference/__Reference.html#//apple_ref/__occ/instm/GLKView/bindDrawable
    <https://developer.apple.com/library/ios/documentation/glkit/reference/glkview_classreference/Reference/Reference.html#//apple_ref/occ/instm/GLKView/bindDrawable>

    How can this be achieved using SDL 2.0? What is the correct way of
    dealing with offscreen FBOs using SDL 2.0?


Right after creating the GL context, before binding another FBO...

    GLuint window_fbo = 0;
    glGetIntegerv(GL_FRAMEBUFFER___BINDING, &window_fbo);

...and then rebind window_fbo instead of zero when you're ready to draw to the window. In iOS (or maybe GLES in general? I don't know), framebuffer 0 is not how you get back to the window's
backbuffer.

--ryan.



_________________________________________________
SDL mailing list
SDL at lists.libsdl.org <mailto:SDL at lists.libsdl.org>
http://lists.libsdl.org/__listinfo.cgi/sdl-libsdl.org <http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org>

SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


LordHavoc
Author of DarkPlaces Quake1 engine - http://icculus.org/twilight/darkplaces
Co-designer of Nexuiz - http://alientrap.org/nexuiz
"War does not prove who is right, it proves who is left." - Unknown
"Any sufficiently advanced technology is indistinguishable from a rigged demo." - James Klass
"A game is a series of interesting choices." - Sid Meier

2014-05-05 20:03 GMT+02:00 Jonathan Dearborn :

GLES on Android (on devices that I’ve seen) does use 0 for the default
framebuffer index. Of course, don’t count on it as long as any exceptions
exist (iOS).

Jonny D

Binding another framebuffer causes the screen to render black even when

rebinding the default framebuffer using
glBindFramebuffer(GL_FRAMEBUFFER, 0);

On a previous project where I used pure OpenGL ES2 on iOS I learned that
in order to reset the default FBO i needed to use
https://developer.apple.com/library/ios/documentation/
glkit/reference/glkview_classreference/Reference/
Reference.html#//apple_ref/occ/instm/GLKView/bindDrawable

How can this be achieved using SDL 2.0? What is the correct way of
dealing with offscreen FBOs using SDL 2.0?

Right after creating the GL context, before binding another FBO…

GLuint window_fbo = 0;
glGetIntegerv(GL_FRAMEBUFFER_BINDING, &window_fbo);

…and then rebind window_fbo instead of zero when you’re ready to draw
to the window. In iOS (or maybe GLES in general? I don’t know), framebuffer
0 is not how you get back to the window’s backbuffer.

–ryan.


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Isn’t this related to the way you have to setup a GL context on iOS? I read
somewhere that you
first have to manually generate a renderbuffer + FBO pair, and tell the
system to swap that to the
screen each frame.

Reference:
http://devnulldb.blogspot.de/2012/07/how-to-set-up-opengl-on-ios.html> On Mon, May 5, 2014 at 12:06 PM, Ryan C. Gordon wrote:

That’s right, doing the get call, the value was 1 and not 0.

I also encountered a similar issue where the GL_RENDERBUFFER needed to be rebound after ataching a stencil buffer to another FBO. Solved using the same technique.
I did not have to do any of this using regular OpenGL. So I’m guessing it’s iOS or ES specific.

-Asbjoern

Jonny D wrote:> GLES on Android (on devices that I’ve seen) does use 0 for the default framebuffer index. ??Of course, don’t count on it as long as any exceptions exist (iOS).

Jonny D

On Mon, May 5, 2014 at 12:06 PM, Ryan C. Gordon <icculus at icculus.org (icculus at icculus.org)> wrote:

Binding another framebuffer causes the screen to render black even when
rebinding the default framebuffer using
glBindFramebuffer(GL_FRAMEBUFFER, 0);

On a previous project where I used pure OpenGL ES2 on iOS I learned that
in order to reset the default FBO i needed to use
https://developer.apple.com/library/ios/documentation/glkit/reference/glkview_classreference/Reference/Reference.html#//apple_ref/occ/instm/GLKView/bindDrawable (https://developer.apple.com/library/ios/documentation/glkit/reference/glkview_classreference/Reference/Reference.html#//apple_ref/occ/instm/GLKView/bindDrawable)

How can this be achieved using SDL 2.0? What is the correct way of
dealing with offscreen FBOs using SDL 2.0?

Right after creating the GL context, before binding another FBO…

?? ?? GLuint window_fbo = 0;
?? ?? glGetIntegerv(GL_FRAMEBUFFER_BINDING, &window_fbo);

…and then rebind window_fbo instead of zero when you’re ready to draw to the window. In iOS (or maybe GLES in general? I don’t know), framebuffer 0 is not how you get back to the window’s backbuffer.

–ryan.


SDL mailing list
SDL at lists.libsdl.org (SDL at lists.libsdl.org)
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org (http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org)