Is there is any guide for mixing Opengl and SDL rendering?

Hello All,

I’ve tried to implement a 2D dynamic lighting algorithm based on filling triangles, unfortunately it would not perform well with the SLD_Renderer functions, and so I realized that using OpenGL (with which I have no experience) for drawing the triangles would be a possible solution.

Basically, what I would like to be able to do is: Keep using SDL for copying to and from SDL_Textures just as I have been working so far, and use OpenGL only to render triangles to an SDL_Texture which I also could copy from.

So…, It has been weeks now, reading and experimenting with OpenGL, and unfortunately I have not been able to mix SDL and OpenGL, here is basically the test I am stuck with:

  • Initialized OpenGL with SDL (OpenGL SDL window, OpenGL context tied to the SDL window).
  • Created an SDL_Renderer tied to the SDL window so that I could create SDL_Textures.
  • Created an SDL_Texture that I filled with a color using the SDL_Renderer.
  • Created the data buffers (VBOs and VAO) for a QUAD that fills the screen and the VUs that would texture the QUAD.
  • I bond the SDL_Texture with SDL_GL_BindTexture.
  • Run the shader program (vertex and fragment shaders) that is supposed that take the data and draw to the screen.

So well, it did not work, I don’t even know if it is possible or what I am missing.

Lastly, just to be clear, I have been able to draw and fill the QUAD with colors using OpenGL rendering only, but I’m having a hard time with mixing SDL_Textures and Renderer with OpenGL.

Any help I could get I’ll be so very thankful, I don’t want to give up on my 2D Dynamic lighting.

Best Regards
Gabriel------------------------
Gabriel Alejandro Banales Fabian

Working on a 2D game engine based on SDL since 2012

From what I’ve read SDL basically uses the entire OpenGL state when you use
the render api. You could have a look at the source and see how much SDL
actually needs from the OpenGL state, but I’ve never read any guarantees
about that from SDL’s side. I could be wrong though. Maybe you can describe
what exactly “did not work”? In what way did it not match your expectations?On 11 May 2016 at 09:37, gabf83 wrote:

Hello All,

I’ve tried to implement a 2D dynamic lighting algorithm based on filling
triangles, unfortunately it would not perform well with the SLD_Renderer
functions, and so I realized that using OpenGL (with which I have no
experience) for drawing the triangles would be a possible solution.

Basically, what I would like to be able to do is: Keep using SDL for
copying to and from SDL_Textures just as I have been working so far, and
use OpenGL only to render triangles to an SDL_Texture which I also could
copy from.

So…, It has been weeks now, reading and experimenting with OpenGL, and
unfortunately I have not been able to mix SDL and OpenGL, here is basically
the test I am stuck with:

  • Initialized OpenGL with SDL (OpenGL SDL window, OpenGL context tied to
    the SDL window).
  • Created an SDL_Renderer tied to the SDL window so that I could create
    SDL_Textures.
  • Created an SDL_Texture that I filled with a color using the SDL_Renderer.
  • Created the data buffers (VBOs and VAO) for a QUAD that fills the screen
    and the VUs that would texture the QUAD.
  • I bond the SDL_Texture with SDL_GL_BindTexture.
  • Run the shader program (vertex and fragment shaders) that is supposed
    that take the data and draw to the screen.

So well, it did not work, I don’t even know if it is possible or what I am
missing.

Lastly, just to be clear, I have been able to draw and fill the QUAD with
colors using OpenGL rendering only, but I’m having a hard time with mixing
SDL_Textures and Renderer with OpenGL.

Any help I could get I’ll be so very thankful, I don’t want to give up on
my 2D Dynamic lighting.

Best Regards
Gabriel


Gabriel Alejandro Banales Fabian

Working on a 2D game engine based on SDL since 2012


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

There have been previous threads on this and related topics, though
they are scattered and hard to find. Here is my attempt to organize
them.

On mixing OpenGL and the SDL 2D renderer, Gabriel Jacobo developed
this solution for integrating a GUI library called librocket.
http://mdqinc.com/blog/2013/01/integrating-librocket-with-sdl-2/

There was a discussion/proposal of adding a batching API for
submitting quads to the 2D renderer.
https://forums.libsdl.org/viewtopic.php?p=48449&sid=cc802ffa803aa9e6614a9ee23ff476a2

Gabriel Jacobo also proposed a direct triangle rendering function
“SDL_RenderGeometry” to handle more arbitrary geometry submission to
the 2D renderer.
https://forums.libsdl.org/viewtopic.php?t=8850&sid=0e06d37272e22e0204ce68f8fb92c424

For your situation though, you might strongly consider using SDL_gpu
by Jonathan Dearborn. You can think of it as another alternative SDL
2D renderer (which happens to be built on top of OpenGL right now). It
tries to bridge that gap between keeping a lot of SDL’s simpler/easier
semantics, while still giving you a lot more access to OpenGL
features. I think it has done a pretty good job striking that balance.
It provides APIs to pass an SDL_surface and load it as GPU_Image which
is very similar to an SDL_Texture. It provides GPU_Blit* functions
which are very similar to SDL_RenderCopy*. And SDL_gpu provides access
to GLSL shaders so you can load in your shaders.

I’m currently writing a couple of demos using it, including a dynamic
lighting system for 2D sprites using normal maps generated by popular
tools out there.

-EricOn 5/11/16, gabf83 wrote:

Hello All,

I’ve tried to implement a 2D dynamic lighting algorithm based on filling
triangles, unfortunately it would not perform well with the SLD_Renderer
functions, and so I realized that using OpenGL (with which I have no
experience) for drawing the triangles would be a possible solution.

Basically, what I would like to be able to do is: Keep using SDL for copying
to and from SDL_Textures just as I have been working so far, and use OpenGL
only to render triangles to an SDL_Texture which I also could copy from.

So…, It has been weeks now, reading and experimenting with OpenGL, and
unfortunately I have not been able to mix SDL and OpenGL, here is basically
the test I am stuck with:

  • Initialized OpenGL with SDL (OpenGL SDL window, OpenGL context tied to the
    SDL window).
  • Created an SDL_Renderer tied to the SDL window so that I could create
    SDL_Textures.
  • Created an SDL_Texture that I filled with a color using the SDL_Renderer.
  • Created the data buffers (VBOs and VAO) for a QUAD that fills the screen
    and the VUs that would texture the QUAD.
  • I bond the SDL_Texture with SDL_GL_BindTexture.
  • Run the shader program (vertex and fragment shaders) that is supposed that
    take the data and draw to the screen.

So well, it did not work, I don’t even know if it is possible or what I am
missing.

Lastly, just to be clear, I have been able to draw and fill the QUAD with
colors using OpenGL rendering only, but I’m having a hard time with mixing
SDL_Textures and Renderer with OpenGL.

Any help I could get I’ll be so very thankful, I don’t want to give up on my
2D Dynamic lighting.

Best Regards
Gabriel

Hi

my experience so far is that some mixing between openGL and Renderer
is possible with some care. For instance you can render an SDL texture
and then render directly some openGL quads onscreen. For this to work
you need to reset things like shader programs at every frame. However
I have never tried to use openGL to render directly onto and SDL
texture. This might be impossible at this point. I hope that SDL can
evolve in this direction in the future.

S.

Le 11/05/2016 09:37, gabf83 a ?crit :

Hello All, > > I’ve tried to implement a 2D dynamic lighting algorithm based on
filling triangles, unfortunately it would not perform well with the
SLD_Renderer functions, and so I realized that using OpenGL (with which
I have no experience) for drawing the triangles would be a possible
solution. > > Basically, what I would like to be able to do is: Keep
using SDL for copying to and from SDL_Textures just as I have been
working so far, and use OpenGL only to render triangles to an
SDL_Texture which I also could copy from. > > So…, It has been weeks
now, reading and experimenting with OpenGL, and unfortunately I have not
been able to mix SDL and OpenGL, here is basically the test I am stuck
with: > > * Initialized OpenGL with SDL (OpenGL SDL window, OpenGL
context tied to the SDL window). > * Created an SDL_Renderer tied to the
SDL window so that I could create SDL_Textures. > * Created an
SDL_Texture that I filled with a color using the SDL_Renderer. > *
Created the data buffers (VBOs and VAO) for a QUAD that fills the screen
and the VUs that would texture the QUAD. > * I bond the SDL_Texture with
SDL_GL_BindTexture. > * Run the shader program (vertex and fragment
shaders) that is supposed that take the data and draw to the screen. > >
So well, it did not work, I don’t even know if it is possible or what I
am missing. > > Lastly, just to be clear, I have been able to draw and
fill the QUAD with colors using OpenGL rendering only, but I’m having a
hard time with mixing SDL_Textures and Renderer with OpenGL. > > Any
help I could get I’ll be so very thankful, I don’t want to give up on my
2D Dynamic lighting. > > Best Regards > Gabriel > > > > Gabriel
Alejandro Banales Fabian >
------------------------------------------------------ > Working on a 2D
game engine based on SDL since 2012 > > >
_______________________________________________ > SDL mailing list >
SDL at lists.libsdl.org > http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Thanks for your replies. Fortunately, Gabriel Jacobo released a patch that provides the SDL Renderer with a Geometry Rendering function. I was able to patch SDL 2.0.0 and tested that it works and does exactly what I was looking for.

Interestingly, it appears that the trick is having the same OpenGL render context that SDL Render uses render whatever you want OpenGL to render for you.

Regards
Gabriel------------------------
Gabriel Alejandro Banales Fabian

Working on a 2D game engine based on SDL since 2012

interesting, coud you give the link to the patch ?

Le 30/05/2016 22:52, gabf83 a ?crit :> Thanks for your replies. Fortunately, Gabriel Jacobo released a patch

that provides the SDL Renderer with a Geometry Rendering function. I
was able to patch SDL 2.0.0 and tested that it works and does exactly
what I was looking for.

Interestingly, it appears that the trick is having the same OpenGL
render context that SDL Render uses render whatever you want OpenGL to
render for you.

Regards
Gabriel


Gabriel Alejandro Banales Fabian

Working on a 2D game engine based on SDL since 2012


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

Sure,

This is the link to the bug where the patch is:

This is the post where it was shared:

https://forums.libsdl.org/viewtopic.php?t=8850&sid=0e06d37272e22e0204ce68f8fb92c424

Really hopping this officially makes it to SDL next releases.

Regards

Sanette wrote:> interesting, coud you give the link to the patch ?

Le 30/05/2016 22:52, gabf83 a ???crit???:

Thanks for your replies. Fortunately, Gabriel Jacobo released a patch that provides the SDL Renderer with a Geometry Rendering function. I was able to patch SDL 2.0.0 and tested that it works and does exactly what I was looking for.

Interestingly, it appears that the trick is having the same OpenGL render context that SDL Render uses render whatever you want OpenGL to render for you.

Regards
Gabriel

Gabriel Alejandro Banales Fabian

Working on a 2D game engine based on SDL since 2012


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)


Gabriel Alejandro Banales Fabian

Working on a 2D game engine based on SDL since 2012