Mixing opengl and renderer?

Is there a good starting point somewhere for mixing the rendering functions
and opengl functions?

I want to implement:

SDL_RenderQuad(
SDL_Renderer *renderer,
SDL_Texture *texture,
SDL_Shader *shader, // <-- Written by me, just compiles and uses a GLSL
shader
float *geometry, // 4x x,y point <— Where to draw.
float *uv, // 4x u,v coordinate <— Data for the shader to use.
float *color, // 4x rgba color <— Data for the shader to use.
)

To do useful things like; procedural fog, fading, tinting in real time
(those tint functions are so terrribly slow on surfaces. :(, and generally
speaking to use as a total replacement for SDL_RenderCopyEx, which I find
not particularly useful (largely because it doesn’t let me use a shader).

I setup a opengl 2d context, rendered it, used RenderPresent() and tried a
few things, but I’m having no luck. I can either get the renderer to draw,
or opengl, but not both, even without calling SDL_RenderClear() or any
opengl clear functions.

I’ve seen a bunch of old posts about this, but any actual examples that
work would be really great.

Anyone seen any?

I’m rather fond of just treating everything as pixel surfaces and using the
SDL blit operations, but a few things there are just terribly slow if you
try to do them without using a shader.

Cheers,
Doug.

2013/9/5 Doug <douglas.linder at gmail.com>

Is there a good starting point somewhere for mixing the rendering
functions and opengl functions?

I want to implement:

SDL_RenderQuad(
SDL_Renderer *renderer,
SDL_Texture *texture,
SDL_Shader *shader, // <-- Written by me, just compiles and uses a GLSL
shader
float *geometry, // 4x x,y point <— Where to draw.
float *uv, // 4x u,v coordinate <— Data for the shader to use.
float *color, // 4x rgba color <— Data for the shader to use.
)

To do useful things like; procedural fog, fading, tinting in real time
(those tint functions are so terrribly slow on surfaces. :(, and generally
speaking to use as a total replacement for SDL_RenderCopyEx, which I find
not particularly useful (largely because it doesn’t let me use a shader).

I setup a opengl 2d context, rendered it, used RenderPresent() and tried a
few things, but I’m having no luck. I can either get the renderer to draw,
or opengl, but not both, even without calling SDL_RenderClear() or any
opengl clear functions.

I’ve seen a bunch of old posts about this, but any actual examples that
work would be really great.

Anyone seen any?

I’m rather fond of just treating everything as pixel surfaces and using
the SDL blit operations, but a few things there are just terribly slow if
you try to do them without using a shader.

A few ideas (and implementations!) from a recent thread:
http://forums.libsdl.org/viewtopic.php?t=9486--
Gabriel.

humm. I saw that thread, but I don’t see any useful actual code from it,
just talk about opengl. I’m specifically interested in mixing both, not
using purely opengl.

Here’s an example of actual code that renders exactly 1 perfect frame of a
red triangle and green square, followed by black.

If you comment out the SDL_RenderCopyEx it renders the triangle correctly;
if you comment out the opengl, it renders the square correctly.

I had a look at the sdl-gpu code, and as far as I can see I’m doing the
same thing; ie. glOrtho with the size matching the renderer size. :/~
Doug.

On Thu, Sep 5, 2013 at 8:27 PM, Gabriel Jacobo wrote:

2013/9/5 Doug <@Doug1>

Is there a good starting point somewhere for mixing the rendering
functions and opengl functions?

I want to implement:

SDL_RenderQuad(
SDL_Renderer *renderer,
SDL_Texture *texture,
SDL_Shader *shader, // <-- Written by me, just compiles and uses a
GLSL shader
float *geometry, // 4x x,y point <— Where to draw.
float *uv, // 4x u,v coordinate <— Data for the shader to use.
float *color, // 4x rgba color <— Data for the shader to use.
)

To do useful things like; procedural fog, fading, tinting in real time
(those tint functions are so terrribly slow on surfaces. :(, and generally
speaking to use as a total replacement for SDL_RenderCopyEx, which I find
not particularly useful (largely because it doesn’t let me use a shader).

I setup a opengl 2d context, rendered it, used RenderPresent() and tried
a few things, but I’m having no luck. I can either get the renderer to
draw, or opengl, but not both, even without calling SDL_RenderClear() or
any opengl clear functions.

I’ve seen a bunch of old posts about this, but any actual examples that
work would be really great.

Anyone seen any?

I’m rather fond of just treating everything as pixel surfaces and using
the SDL blit operations, but a few things there are just terribly slow if
you try to do them without using a shader.

A few ideas (and implementations!) from a recent thread:
http://forums.libsdl.org/viewtopic.php?t=9486


Gabriel.


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

Ok, this is what I did to mix Open GL with SDL_Render calls (before mixing
it all into SDL_RenderGeometry):
http://mdqinc.com/blog/2013/01/integrating-librocket-with-sdl-2/

2013/9/5 Doug <douglas.linder at gmail.com>> humm. I saw that thread, but I don’t see any useful actual code from it,

just talk about opengl. I’m specifically interested in mixing both, not
using purely opengl.

Here’s an example of actual code that renders exactly 1 perfect frame of a
red triangle and green square, followed by black.

If you comment out the SDL_RenderCopyEx it renders the triangle correctly;
if you comment out the opengl, it renders the square correctly.

https://gist.github.com/anonymous/6450139

I had a look at the sdl-gpu code, and as far as I can see I’m doing the
same thing; ie. glOrtho with the size matching the renderer size. :confused:

~
Doug.

On Thu, Sep 5, 2013 at 8:27 PM, Gabriel Jacobo <@Gabriel_Jacobo> wrote:

2013/9/5 Doug <douglas.linder at gmail.com>

Is there a good starting point somewhere for mixing the rendering
functions and opengl functions?

I want to implement:

SDL_RenderQuad(
SDL_Renderer *renderer,
SDL_Texture *texture,
SDL_Shader *shader, // <-- Written by me, just compiles and uses a
GLSL shader
float *geometry, // 4x x,y point <— Where to draw.
float *uv, // 4x u,v coordinate <— Data for the shader to use.
float *color, // 4x rgba color <— Data for the shader to use.
)

To do useful things like; procedural fog, fading, tinting in real time
(those tint functions are so terrribly slow on surfaces. :(, and generally
speaking to use as a total replacement for SDL_RenderCopyEx, which I find
not particularly useful (largely because it doesn’t let me use a shader).

I setup a opengl 2d context, rendered it, used RenderPresent() and tried
a few things, but I’m having no luck. I can either get the renderer to
draw, or opengl, but not both, even without calling SDL_RenderClear() or
any opengl clear functions.

I’ve seen a bunch of old posts about this, but any actual examples that
work would be really great.

Anyone seen any?

I’m rather fond of just treating everything as pixel surfaces and using
the SDL blit operations, but a few things there are just terribly slow if
you try to do them without using a shader.

A few ideas (and implementations!) from a recent thread:
http://forums.libsdl.org/viewtopic.php?t=9486


Gabriel.


SDL mailing list
SDL at lists.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


Gabriel.

Run this through gDEBugger (if you have an ATI video card) or something like apitrace if gDEBugger won’t work for you, and you’ll most likely find that SDL is changing shaders on you.? This is a very annoying thing to work around: SDL’s renderer wasn’t designed to work with other systems making render calls, and it behaves as if it owns the entire GL state.? So you need to make sure that, as you mix SDL calls with OpenGL of your own, you keep the GL render state the same as what SDL’s internal caching thinks it is.? Otherwise, you run into problems like this.

Mason________________________________
From: Doug <douglas.linder at gmail.com>
To: SDL Development List
Sent: Thursday, September 5, 2013 6:36 AM
Subject: Re: [SDL] Mixing opengl and renderer?

humm. I saw that thread, but I don’t see any useful actual code from it, just talk about opengl. I’m specifically interested in mixing both, not using purely opengl.

Here’s an example of actual code that renders exactly 1 perfect frame of a red triangle and green square, followed by black.

If you comment out the SDL_RenderCopyEx it renders the triangle correctly; if you comment out the opengl, it renders the square correctly.

I had a look at the sdl-gpu code, and as far as I can see I’m doing the same thing; ie. glOrtho with the size matching the renderer size. :confused:

~
Doug.

On Thu, Sep 5, 2013 at 8:27 PM, Gabriel Jacobo wrote:

2013/9/5 Doug <douglas.linder at gmail.com>

Is there a good starting point somewhere for mixing the rendering functions and opengl functions?

I want to implement:

SDL_RenderQuad(

? ?SDL_Renderer *renderer,
? ?SDL_Texture *texture,
? ?SDL_Shader *shader, // <-- Written by me, just compiles and uses a GLSL shader
? ?float *geometry, ?// 4x x,y point <— Where to draw.
? ?float *uv, // 4x u,v coordinate <— Data for the shader to use.
? ?float *color, // 4x rgba color <— Data for the shader to use.
)

To do useful things like; procedural fog, fading, tinting in real time (those tint functions are so terrribly slow on surfaces. :(, and generally speaking to use as a total replacement for SDL_RenderCopyEx, which I find not particularly useful (largely because it doesn’t let me use a shader).

I setup a opengl 2d context, rendered it, used RenderPresent() and tried a few things, but I’m having no luck. I can either get the renderer to draw, or opengl, but not both, even without calling SDL_RenderClear() or any opengl clear functions.?

I’ve seen a bunch of old posts about this, but any actual examples that work would be really great.

Anyone seen any?

I’m rather fond of just treating everything as pixel surfaces and using the SDL blit operations, but a few things there are just terribly slow if you try to do them without using a shader.

A few ideas (and implementations!) from a recent thread:?http://forums.libsdl.org/viewtopic.php?t=9486?


Gabriel.


SDL mailing list
SDL at lists.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

Ah, thank you, you’re right. That’s rather annoying.~
D.

On Thu, Sep 5, 2013 at 10:47 PM, Mason Wheeler wrote:

Run this through gDEBugger (if you have an ATI video card) or something
like apitrace if gDEBugger won’t work for you, and you’ll most likely find
that SDL is changing shaders on you. This is a very annoying thing to work
around: SDL’s renderer wasn’t designed to work with other systems making
render calls, and it behaves as if it owns the entire GL state. So you
need to make sure that, as you mix SDL calls with OpenGL of your own, you
keep the GL render state the same as what SDL’s internal caching thinks it
is. Otherwise, you run into problems like this.

Mason


From: Doug <@Doug1>
To: SDL Development List
Sent: Thursday, September 5, 2013 6:36 AM
Subject: Re: [SDL] Mixing opengl and renderer?

humm. I saw that thread, but I don’t see any useful actual code from it,
just talk about opengl. I’m specifically interested in mixing both, not
using purely opengl.

Here’s an example of actual code that renders exactly 1 perfect frame of a
red triangle and green square, followed by black.

If you comment out the SDL_RenderCopyEx it renders the triangle correctly;
if you comment out the opengl, it renders the square correctly.

https://gist.github.com/anonymous/6450139

I had a look at the sdl-gpu code, and as far as I can see I’m doing the
same thing; ie. glOrtho with the size matching the renderer size. :confused:

~
Doug.

On Thu, Sep 5, 2013 at 8:27 PM, Gabriel Jacobo wrote:

2013/9/5 Doug <@Doug1>

Is there a good starting point somewhere for mixing the rendering
functions and opengl functions?

I want to implement:

SDL_RenderQuad(
SDL_Renderer *renderer,
SDL_Texture *texture,
SDL_Shader *shader, // <-- Written by me, just compiles and uses a GLSL
shader
float *geometry, // 4x x,y point <— Where to draw.
float *uv, // 4x u,v coordinate <— Data for the shader to use.
float *color, // 4x rgba color <— Data for the shader to use.
)

To do useful things like; procedural fog, fading, tinting in real time
(those tint functions are so terrribly slow on surfaces. :(, and generally
speaking to use as a total replacement for SDL_RenderCopyEx, which I find
not particularly useful (largely because it doesn’t let me use a shader).

I setup a opengl 2d context, rendered it, used RenderPresent() and tried a
few things, but I’m having no luck. I can either get the renderer to draw,
or opengl, but not both, even without calling SDL_RenderClear() or any
opengl clear functions.

I’ve seen a bunch of old posts about this, but any actual examples that
work would be really great.

Anyone seen any?

I’m rather fond of just treating everything as pixel surfaces and using
the SDL blit operations, but a few things there are just terribly slow if
you try to do them without using a shader.

A few ideas (and implementations!) from a recent thread:
http://forums.libsdl.org/viewtopic.php?t=9486


Gabriel.


SDL mailing list
SDL at lists.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


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

Does it make sense to add a “reset” call that invalidates the renderer’s
idea of the 3D pipeline state?On Thu, Sep 5, 2013 at 7:47 AM, Mason Wheeler wrote:

Run this through gDEBugger (if you have an ATI video card) or something
like apitrace if gDEBugger won’t work for you, and you’ll most likely find
that SDL is changing shaders on you. This is a very annoying thing to work
around: SDL’s renderer wasn’t designed to work with other systems making
render calls, and it behaves as if it owns the entire GL state. So you
need to make sure that, as you mix SDL calls with OpenGL of your own, you
keep the GL render state the same as what SDL’s internal caching thinks it
is. Otherwise, you run into problems like this.

Mason


From: Doug <douglas.linder at gmail.com>
To: SDL Development List
Sent: Thursday, September 5, 2013 6:36 AM
Subject: Re: [SDL] Mixing opengl and renderer?

humm. I saw that thread, but I don’t see any useful actual code from it,
just talk about opengl. I’m specifically interested in mixing both, not
using purely opengl.

Here’s an example of actual code that renders exactly 1 perfect frame of a
red triangle and green square, followed by black.

If you comment out the SDL_RenderCopyEx it renders the triangle correctly;
if you comment out the opengl, it renders the square correctly.

https://gist.github.com/anonymous/6450139

I had a look at the sdl-gpu code, and as far as I can see I’m doing the
same thing; ie. glOrtho with the size matching the renderer size. :confused:

~
Doug.

On Thu, Sep 5, 2013 at 8:27 PM, Gabriel Jacobo wrote:

2013/9/5 Doug <douglas.linder at gmail.com>

Is there a good starting point somewhere for mixing the rendering
functions and opengl functions?

I want to implement:

SDL_RenderQuad(
SDL_Renderer *renderer,
SDL_Texture *texture,
SDL_Shader *shader, // <-- Written by me, just compiles and uses a GLSL
shader
float *geometry, // 4x x,y point <— Where to draw.
float *uv, // 4x u,v coordinate <— Data for the shader to use.
float *color, // 4x rgba color <— Data for the shader to use.
)

To do useful things like; procedural fog, fading, tinting in real time
(those tint functions are so terrribly slow on surfaces. :(, and generally
speaking to use as a total replacement for SDL_RenderCopyEx, which I find
not particularly useful (largely because it doesn’t let me use a shader).

I setup a opengl 2d context, rendered it, used RenderPresent() and tried a
few things, but I’m having no luck. I can either get the renderer to draw,
or opengl, but not both, even without calling SDL_RenderClear() or any
opengl clear functions.

I’ve seen a bunch of old posts about this, but any actual examples that
work would be really great.

Anyone seen any?

I’m rather fond of just treating everything as pixel surfaces and using
the SDL blit operations, but a few things there are just terribly slow if
you try to do them without using a shader.

A few ideas (and implementations!) from a recent thread:
http://forums.libsdl.org/viewtopic.php?t=9486


Gabriel.


SDL mailing list
SDL at lists.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


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

FYI, we planned doing that here:
https://bugzilla.libsdl.org/show_bug.cgi?id=1138

2013/9/5 Sam Lantinga > Does it make sense to add a “reset” call that invalidates the renderer’s

idea of the 3D pipeline state?

On Thu, Sep 5, 2013 at 7:47 AM, Mason Wheeler wrote:

Run this through gDEBugger (if you have an ATI video card) or something
like apitrace if gDEBugger won’t work for you, and you’ll most likely find
that SDL is changing shaders on you. This is a very annoying thing to work
around: SDL’s renderer wasn’t designed to work with other systems making
render calls, and it behaves as if it owns the entire GL state. So you
need to make sure that, as you mix SDL calls with OpenGL of your own, you
keep the GL render state the same as what SDL’s internal caching thinks it
is. Otherwise, you run into problems like this.

Mason


From: Doug <douglas.linder at gmail.com>
To: SDL Development List
Sent: Thursday, September 5, 2013 6:36 AM
Subject: Re: [SDL] Mixing opengl and renderer?

humm. I saw that thread, but I don’t see any useful actual code from it,
just talk about opengl. I’m specifically interested in mixing both, not
using purely opengl.

Here’s an example of actual code that renders exactly 1 perfect frame of
a red triangle and green square, followed by black.

If you comment out the SDL_RenderCopyEx it renders the triangle
correctly; if you comment out the opengl, it renders the square correctly.

https://gist.github.com/anonymous/6450139

I had a look at the sdl-gpu code, and as far as I can see I’m doing the
same thing; ie. glOrtho with the size matching the renderer size. :confused:

~
Doug.

On Thu, Sep 5, 2013 at 8:27 PM, Gabriel Jacobo <@Gabriel_Jacobo> wrote:

2013/9/5 Doug <douglas.linder at gmail.com>

Is there a good starting point somewhere for mixing the rendering
functions and opengl functions?

I want to implement:

SDL_RenderQuad(
SDL_Renderer *renderer,
SDL_Texture *texture,
SDL_Shader *shader, // <-- Written by me, just compiles and uses a
GLSL shader
float *geometry, // 4x x,y point <— Where to draw.
float *uv, // 4x u,v coordinate <— Data for the shader to use.
float *color, // 4x rgba color <— Data for the shader to use.
)

To do useful things like; procedural fog, fading, tinting in real time
(those tint functions are so terrribly slow on surfaces. :(, and generally
speaking to use as a total replacement for SDL_RenderCopyEx, which I find
not particularly useful (largely because it doesn’t let me use a shader).

I setup a opengl 2d context, rendered it, used RenderPresent() and tried
a few things, but I’m having no luck. I can either get the renderer to
draw, or opengl, but not both, even without calling SDL_RenderClear() or
any opengl clear functions.

I’ve seen a bunch of old posts about this, but any actual examples that
work would be really great.

Anyone seen any?

I’m rather fond of just treating everything as pixel surfaces and using
the SDL blit operations, but a few things there are just terribly slow if
you try to do them without using a shader.

A few ideas (and implementations!) from a recent thread:
http://forums.libsdl.org/viewtopic.php?t=9486


Gabriel.


SDL mailing list
SDL at lists.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


SDL mailing list
SDL at lists.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


Gabriel.

Yes, I was actually thinking of proposing exactly that when I wrote
this, but I figured it would be futile due to the API being frozen.? But
if you’re going to suggest it, I’d definitely say “yes, yes, we need
that!”

Mason________________________________
From: Sam Lantinga
To: Mason Wheeler <@Mason_Wheeler>; SDL Development List
Sent: Thursday, September 5, 2013 11:24 AM
Subject: Re: [SDL] Mixing opengl and renderer?

Does it make sense to add a “reset” call that invalidates the renderer’s idea of the 3D pipeline state?

On Thu, Sep 5, 2013 at 7:47 AM, Mason Wheeler <@Mason_Wheeler> wrote:

Run this through gDEBugger (if you have an ATI video card) or something like apitrace if gDEBugger won’t work for you, and you’ll most likely find that SDL is changing shaders on you.? This is a very annoying thing to work around: SDL’s renderer wasn’t designed to work with other systems making render calls, and it behaves as if it owns the entire GL state.? So you need to make sure that, as you mix SDL calls with OpenGL of your own, you keep the GL render state the same as what SDL’s internal caching thinks it is.? Otherwise, you run into problems like this.

Mason


From: Doug <douglas.linder at gmail.com>
To: SDL Development List
Sent: Thursday, September 5, 2013 6:36 AM
Subject: Re: [SDL] Mixing opengl and renderer?

humm. I saw that thread, but I don’t see any useful actual code from it, just talk about opengl. I’m specifically interested in mixing both, not using purely opengl.

Here’s an example of actual code that renders exactly 1 perfect frame of a red triangle and green square, followed by black.

If you comment out the SDL_RenderCopyEx it renders the triangle correctly; if you comment out the opengl, it renders the square correctly.

https://gist.github.com/anonymous/6450139

I had a look at the sdl-gpu code, and as far as I can see I’m doing the same thing; ie. glOrtho with the size matching the renderer size. :confused:

~
Doug.

On Thu, Sep 5, 2013 at 8:27 PM, Gabriel Jacobo wrote:

2013/9/5 Doug <douglas.linder at gmail.com>

Is there a good starting point somewhere for mixing the rendering functions and opengl functions?

I want to implement:

SDL_RenderQuad(

? ?SDL_Renderer *renderer,
? ?SDL_Texture *texture,
? ?SDL_Shader *shader, // <-- Written by me, just compiles and uses a GLSL shader
? ?float *geometry, ?// 4x x,y point <— Where to draw.
? ?float *uv, // 4x u,v coordinate <— Data for the shader to use.
? ?float *color, // 4x rgba color <— Data for the shader to use.
)

To do useful things like; procedural fog, fading, tinting in real time (those tint functions are so terrribly slow on surfaces. :(, and generally speaking to use as a total replacement for SDL_RenderCopyEx, which I find not particularly useful (largely because it doesn’t let me use a shader).

I setup a opengl 2d context, rendered it, used RenderPresent() and tried a few things, but I’m having no luck. I can either get the renderer to draw, or opengl, but not both, even without calling SDL_RenderClear() or any opengl clear functions.?

I’ve seen a bunch of old posts about this, but any actual examples that work would be really great.

Anyone seen any?

I’m rather fond of just treating everything as pixel surfaces and using the SDL blit operations, but a few things there are just terribly slow if you try to do them without using a shader.

A few ideas (and implementations!) from a recent thread:?http://forums.libsdl.org/viewtopic.php?t=9486?


Gabriel.


SDL mailing list
SDL at lists.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


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

It seems like that’s something we could do in SDL 2.0.1 if people are
interested. Adding APIs in a minor revision is fine.On Thu, Sep 5, 2013 at 11:41 AM, Gabriel Jacobo wrote:

FYI, we planned doing that here:
https://bugzilla.libsdl.org/show_bug.cgi?id=1138

2013/9/5 Sam Lantinga <@slouken>

Does it make sense to add a “reset” call that invalidates the renderer’s
idea of the 3D pipeline state?

On Thu, Sep 5, 2013 at 7:47 AM, Mason Wheeler wrote:

Run this through gDEBugger (if you have an ATI video card) or something
like apitrace if gDEBugger won’t work for you, and you’ll most likely find
that SDL is changing shaders on you. This is a very annoying thing to work
around: SDL’s renderer wasn’t designed to work with other systems making
render calls, and it behaves as if it owns the entire GL state. So you
need to make sure that, as you mix SDL calls with OpenGL of your own, you
keep the GL render state the same as what SDL’s internal caching thinks it
is. Otherwise, you run into problems like this.

Mason


From: Doug <douglas.linder at gmail.com>
To: SDL Development List
Sent: Thursday, September 5, 2013 6:36 AM
Subject: Re: [SDL] Mixing opengl and renderer?

humm. I saw that thread, but I don’t see any useful actual code from it,
just talk about opengl. I’m specifically interested in mixing both, not
using purely opengl.

Here’s an example of actual code that renders exactly 1 perfect frame of
a red triangle and green square, followed by black.

If you comment out the SDL_RenderCopyEx it renders the triangle
correctly; if you comment out the opengl, it renders the square correctly.

https://gist.github.com/anonymous/6450139

I had a look at the sdl-gpu code, and as far as I can see I’m doing the
same thing; ie. glOrtho with the size matching the renderer size. :confused:

~
Doug.

On Thu, Sep 5, 2013 at 8:27 PM, Gabriel Jacobo wrote:

2013/9/5 Doug <douglas.linder at gmail.com>

Is there a good starting point somewhere for mixing the rendering
functions and opengl functions?

I want to implement:

SDL_RenderQuad(
SDL_Renderer *renderer,
SDL_Texture *texture,
SDL_Shader *shader, // <-- Written by me, just compiles and uses a
GLSL shader
float *geometry, // 4x x,y point <— Where to draw.
float *uv, // 4x u,v coordinate <— Data for the shader to use.
float *color, // 4x rgba color <— Data for the shader to use.
)

To do useful things like; procedural fog, fading, tinting in real time
(those tint functions are so terrribly slow on surfaces. :(, and generally
speaking to use as a total replacement for SDL_RenderCopyEx, which I find
not particularly useful (largely because it doesn’t let me use a shader).

I setup a opengl 2d context, rendered it, used RenderPresent() and tried
a few things, but I’m having no luck. I can either get the renderer to
draw, or opengl, but not both, even without calling SDL_RenderClear() or
any opengl clear functions.

I’ve seen a bunch of old posts about this, but any actual examples that
work would be really great.

Anyone seen any?

I’m rather fond of just treating everything as pixel surfaces and using
the SDL blit operations, but a few things there are just terribly slow if
you try to do them without using a shader.

A few ideas (and implementations!) from a recent thread:
http://forums.libsdl.org/viewtopic.php?t=9486


Gabriel.


SDL mailing list
SDL at lists.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


SDL mailing list
SDL at lists.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


Gabriel.


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

Yes please.? There are several annoying little hacks I could take out of my codebase if I had a SDL_PushRenderState() and SDL_PopRenderState(), or a SDL_DeleteCachedRenderStateData() (needs a better name) at my disposal.

Mason________________________________
From: Sam Lantinga
To: SDL Development List
Sent: Thursday, September 5, 2013 12:18 PM
Subject: Re: [SDL] Mixing opengl and renderer?

It seems like that’s something we could do in SDL 2.0.1 if people are interested.? Adding APIs in a minor revision is fine.

On Thu, Sep 5, 2013 at 11:41 AM, Gabriel Jacobo wrote:

FYI, we planned doing that here:?https://bugzilla.libsdl.org/show_bug.cgi?id=1138

2013/9/5 Sam Lantinga

Does it make sense to add a “reset” call that invalidates the renderer’s idea of the 3D pipeline state?

On Thu, Sep 5, 2013 at 7:47 AM, Mason Wheeler <@Mason_Wheeler> wrote:

Run this through gDEBugger (if you have an ATI video card) or something like apitrace if gDEBugger won’t work for you, and you’ll most likely find that SDL is changing shaders on you.? This is a very annoying thing to work around: SDL’s renderer wasn’t designed to work with other systems making render calls, and it behaves as if it owns the entire GL state.? So you need to make sure that, as you mix SDL calls with OpenGL of your own, you keep the GL render state the same as what SDL’s internal caching thinks it is.? Otherwise, you run into problems like this.

Mason


From: Doug <douglas.linder at gmail.com>
To: SDL Development List
Sent: Thursday, September 5, 2013 6:36 AM
Subject: Re: [SDL] Mixing opengl and renderer?

humm. I saw that thread, but I don’t see any useful actual code from it, just talk about opengl. I’m specifically interested in mixing both, not using purely opengl.

Here’s an example of actual code that renders exactly 1 perfect frame of a red triangle and green square, followed by black.

If you comment out the SDL_RenderCopyEx it renders the triangle correctly; if you comment out the opengl, it renders the square correctly.

https://gist.github.com/anonymous/6450139

I had a look at the sdl-gpu code, and as far as I can see I’m doing the same thing; ie. glOrtho with the size matching the renderer size. :confused:

~
Doug.

On Thu, Sep 5, 2013 at 8:27 PM, Gabriel Jacobo wrote:

2013/9/5 Doug <douglas.linder at gmail.com>

Is there a good starting point somewhere for mixing the rendering functions and opengl functions?

I want to implement:

SDL_RenderQuad(

? ?SDL_Renderer *renderer,
? ?SDL_Texture *texture,
? ?SDL_Shader *shader, // <-- Written by me, just compiles and uses a GLSL shader
? ?float *geometry, ?// 4x x,y point <— Where to draw.
? ?float *uv, // 4x u,v coordinate <— Data for the shader to use.
? ?float *color, // 4x rgba color <— Data for the shader to use.
)

To do useful things like; procedural fog, fading, tinting in real time (those tint functions are so terrribly slow on surfaces. :(, and generally speaking to use as a total replacement for SDL_RenderCopyEx, which I find not particularly useful (largely because it doesn’t let me use a shader).

I setup a opengl 2d context, rendered it, used RenderPresent() and tried a few things, but I’m having no luck. I can either get the renderer to draw, or opengl, but not both, even without calling SDL_RenderClear() or any opengl clear functions.?

I’ve seen a bunch of old posts about this, but any actual examples that work would be really great.

Anyone seen any?

I’m rather fond of just treating everything as pixel surfaces and using the SDL blit operations, but a few things there are just terribly slow if you try to do them without using a shader.

A few ideas (and implementations!) from a recent thread:?http://forums.libsdl.org/viewtopic.php?t=9486?


Gabriel.


SDL mailing list
SDL at lists.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


SDL mailing list
SDL at lists.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


Gabriel.


SDL mailing list
SDL at lists.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

Mason Wheeler wrote:

Yes please. There are several annoying little hacks I could take out of my codebase if I had a SDL_PushRenderState() and SDL_PopRenderState(), or a SDL_DeleteCachedRenderStateData() (needs a better name) at my disposal.

Isn’t saving/restoring states a very expensive operation?

Seems to me that the best approach would be to go pure openGL, and just let SDL 2 handle the basics.

Looking at this code, I don’t see any reason why it should be expensive.? A simple linked list-based stack is trivial.

Mason________________________________
From: Sparks
To: sdl at lists.libsdl.org
Sent: Thursday, September 5, 2013 3:17 PM
Subject: Re: [SDL] Mixing opengl and renderer?

Mason Wheeler wrote:
Yes please. There are several annoying little hacks I could take out of my codebase if I had a SDL_PushRenderState() and SDL_PopRenderState(), or a SDL_DeleteCachedRenderStateData() (needs a better name) at my disposal.

Isn’t saving/restoring states a very expensive operation?

Seems to me that the best approach would be to go pure openGL, and just let SDL 2 handle the basics.


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

I don’t think the idea (at least in its original form) is to save a state,
but rather to have a way of telling SDL that something external touched the
GL context and that it should re setup everything internally.

2013/9/5 Mason Wheeler > Looking at this code, I don’t see any reason why it should be expensive.

A simple linked list-based stack is trivial.

Mason


From: Sparks
To: sdl at lists.libsdl.org
Sent: Thursday, September 5, 2013 3:17 PM
Subject: Re: [SDL] Mixing opengl and renderer?

Mason Wheeler wrote: Yes please. There are several annoying little
hacks I could take out of my codebase if I had a SDL_PushRenderState() and
SDL_PopRenderState(), or a SDL_DeleteCachedRenderStateData() (needs a
better name) at my disposal.

Isn’t saving/restoring states a very expensive operation?

Seems to me that the best approach would be to go pure openGL, and just
let SDL 2 handle the basics.


SDL mailing list
SDL at lists.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


Gabriel.

Yeah, that would work too.

Mason________________________________
From: Gabriel Jacobo
To: SDL Development List
Sent: Thursday, September 5, 2013 3:26 PM
Subject: Re: [SDL] Mixing opengl and renderer?

I don’t think the idea (at least in its original form) is to save a state, but rather to have a way of telling SDL that something external touched the GL context and that it should re setup everything internally.

2013/9/5 Mason Wheeler <@Mason_Wheeler>

Looking at this code, I don’t see any reason why it should be expensive.? A simple linked list-based stack is trivial.

Mason


From: Sparks
To: sdl at lists.libsdl.org
Sent: Thursday, September 5, 2013 3:17 PM
Subject: Re: [SDL] Mixing opengl and renderer?

Mason Wheeler wrote:
Yes please. There are several annoying little hacks I could take out of my codebase if I had a SDL_PushRenderState() and SDL_PopRenderState(), or a SDL_DeleteCachedRenderStateData() (needs a better name) at my disposal.

Isn’t saving/restoring states a very expensive operation?

Seems to me that the best approach would be to go pure openGL, and just let SDL 2 handle the basics.


SDL mailing list
SDL at lists.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


Gabriel.


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

Mason Wheeler wrote:

Looking at this code, I don’t see any reason why it should be expensive. A simple linked list-based stack is trivial.

If you need to save all/most openGL states, not to mention all the matrix modes, it becomes very expensive and if you have redundant state changes, it becomes really, really messy.
Sure, a linked-list stack is trivial, but, saving & restoring a openGL state is not a simple process, it must hit the driver to perform the task.
AFAIK the openGL video driver assumes people don’t do redundant state changes, so when it gets a state change, it marks everything dirty, and it does work to reset the dirty bit, which takes a long time which is why the driver guys says don’t do it–ever!

That is why I said, it would be better to leave SDL2 out of this, and continue to do what it does best (setup windows/screen/input/etc)

gabomdq wrote:

I don’t think the idea (at least in its original form) is to save a state, but rather to have a way of telling SDL that something external touched the GL context and that it should re setup everything internally.

IMO, SDL 2 would need to have some kind of internal housekeeping wrappers that check what is going on outside of its scope, and it would be up to the application developer to set dirty bits on what SDL2 needs to re-init.

It seems to me what we really need is a way to override SDL2’s built in stuff, and supply our own routines that do whatever (like using shaders on SDL2’s draw routines), or just have some kind of built in shader support that we can turn on/off based on what we are drawing. Then again, it is just easier to go full openGL to draw everything you need, and leave SDL 2 out of everything except creating the window/screen.

Yeah, and that’s all well and good, in theory.? In practice, however, I have 3 different blend modes and a good handful of shaders that get used all the time, and it would be pretty difficult to draw anything useful without switching between them.

As for redundant mode switches, it would be fairly simple to avoid.? SDL already has a cache of states it cares about.? The Resetfunction could basically just be implemented as a bunch of checks to whether the GL state is equal to the cached state (which is not expensive) and then setting the GL state if it is.

Mason________________________________
From: Sparks
To: sdl at lists.libsdl.org
Sent: Thursday, September 5, 2013 4:01 PM
Subject: Re: [SDL] Mixing opengl and renderer?

If you need to save all/most openGL states, not to mention all the matrix modes, it becomes very expensive and if you have redundant state changes, it becomes really, really messy.

Sure, a linked-list stack is trivial, but, saving & restoring a openGL state is not a simple process, it must hit the driver to perform the task.
AFAIK the openGL video driver assumes people don’t do redundant state changes, so when it gets a state change, it marks everything dirty, and it does work to reset the dirty bit, which takes a long time which is why the driver guys says don’t do it–ever!

glGetInteger etc. can be quite expensive. Getting the state from OpenGL like that probably shouldn’t be done in the render loop.> [glGet] must must be avoided, as it is not efficient. This is due to the fact that the driver may have to look for the value resulting from previous commands appended to the command queue.

On 2013-09-05, at 9:13 PM, Mason Wheeler wrote:

As for redundant mode switches, it would be fairly simple to avoid. SDL already has a cache of states it cares about. The Reset function could basically just be implemented as a bunch of checks to whether the GL state is equal to the cached state (which is not expensive) and then setting the GL state if it is.

Mason

Or if you want to avoid all that (no idea how expensive querying the
state is!), you could just make the reset function take which stuff
was invalidated (taking this idea from how GCC handles clobbering with
inline asm, also how I implemented a ResetVideoEx function some days
ago for some framework).

2013/9/5, Mason Wheeler :> Yeah, and that’s all well and good, in theory.? In practice, however, I have

3 different blend modes and a good handful of shaders that get used all the
time, and it would be pretty difficult to draw anything useful without
switching between them.

As for redundant mode switches, it would be fairly simple to avoid.? SDL
already has a cache of states it cares about.? The Resetfunction could
basically just be implemented as a bunch of checks to whether the GL state
is equal to the cached state (which is not expensive) and then setting the
GL state if it is.

Mason


From: Sparks
To: sdl at lists.libsdl.org
Sent: Thursday, September 5, 2013 4:01 PM
Subject: Re: [SDL] Mixing opengl and renderer?

If you need to save all/most openGL states, not to mention all the matrix
modes, it becomes very expensive and if you have redundant state changes, it
becomes really, really messy.

Sure, a linked-list stack is trivial, but, saving & restoring a openGL state
is not a simple process, it must hit the driver to perform the task.
AFAIK the openGL video driver assumes people don’t do redundant state
changes, so when it gets a state change, it marks everything dirty, and it
does work to reset the dirty bit, which takes a long time which is why the
driver guys says don’t do it–ever!

Hello! I know this is very old topic, but I too was concerned about this problem and seems have found the decision.
So mixing using opengl API directly and SDL 2D renderer API is possible with the following rules:

  1. Don’t do SDL_GL_CreateContext(), it is already done by SDL_CreateRenderer().
  2. After SDL_CreateRenderer() you need to choose created OpenGL context. To do it call any SDL 2D API call. E.g. SDL_RenderClear(). SDL_CreateTextureFromSurface() as in the example above works also.
  3. SDL_CreateRenderer() switch off GL_DEPTH_TEST and GL_CULL_FACE. So do glDisable of it before using SDL 2D API and do glEnable if you need it in your 3D Scene.
  4. SDL_RenderCopyEx() and some other SDL 2D API calls creates shaders, so you need do glUseProgramObjectARB(0) (or glUseProgram(0)) before using openGL API. It is why the example above works only on the first frame. Insert glUseProgramObjectARB(0) before glColor4f() in render(), add
    #include <GL/glext.h>
    PFNGLUSEPROGRAMOBJECTARBPROC glUseProgramObjectARB = NULL;
    in the headers of program, and add
    glUseProgramObjectARB = (PFNGLUSEPROGRAMOBJECTARBPROC)
    SDL_GL_GetProcAddress(“glUseProgramObjectARB”);
    to init_opengl() to make it working
  5. SDL_SetRenderTarget brakes view port. You need to init viewport (glOrtho(), glViewport() calls) again after each SDL_SetRenderTarget(renderer, NULL);
  6. Working with textures with SDL 2D API disables GL_TEXTURE_2D. Do glEnable(GL_TEXTURE_2D) when you need it.
  7. Before going to SDL 2D API make:
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    if you made some transformations.
  8. Creating textures with SDL sets not zero GL_UNPACK_ROW_LENGTH. Do glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
    before glTexImage2D() if you don’t know how to calculate not zero value of this setting.

That all. 8 rules makes this working. Very hope this will helpful for somebody.
Thanks.