How do I apply a shader to a texture?

I’ve got everything working pretty well with SDL 1.3, but there are a few times when I need to apply a shader to a texture instead of just rendering as-is. SDL doesn’t have any APIs for that, but I can probably do it from the outside if I just had the GLuint handle to the texture. But there doesn’t seem to be an API to obtain that either.

Has anyone tried to apply shaders to textures before? Has anyone succeeded?

Hello,

yes SDL textures are opaque types and could probably differ on various
platforms. What I did was I wrote my own functions for creating
textures, copying them to the screen and so on. That allows me to
attach shaders or fragment programs to my textures.

PavelOn 30.4.2010, at 6:28, Mason Wheeler wrote:

I’ve got everything working pretty well with SDL 1.3, but there are
a few times when I need to apply a shader to a texture instead of
just rendering as-is. SDL doesn’t have any APIs for that, but I can
probably do it from the outside if I just had the GLuint handle to
the texture. But there doesn’t seem to be an API to obtain that
either.

Has anyone tried to apply shaders to textures before? Has anyone
succeeded?


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


Pavel Kanzelsberger


E-Mail: pavel at kanzelsberger.com
Jabber: kanzelsberger at jabber.org, ICQ: 20990633

Hi,On Fri, 30 Apr 2010 09:10:00 +0200 Pavel Kanzelsberger wrote:

Hello,

yes SDL textures are opaque types and could probably differ on various
platforms. What I did was I wrote my own functions for creating
textures, copying them to the screen and so on. That allows me to
attach shaders or fragment programs to my textures.

Pavel

Given that OpenGL is already cross-platform, and looking at the extra
effort you’ve done in this case… Is it really worth using the texture
management functions etc. of SDL 1.3?

Why not just use SDL 1.2 + GL? I always found that to work quite good.
If 1.3 should be useful, it has to be complete, which would include
lots of complex stuff like cross-platform (and cross-API) shader
support, some efficient way of cross-platform, cross-API
render-to-texture, and so on. But I guess SDL will never try to reach
that level of completeness. Such a library would be huge.

I’m kind of wondering where SDL is going - what’s the point of using an
SDL with 3D functions if you still have to drop down to the native API
level for the more advanced stuff (which breaks the portability SDL
provides).

Hello,

well basically I’m using SDL 1.3 because of textures and for all basic
stuff like UI elements in a window are done using SDL functions. But
for special textures that need shaders I have my own code.

Then SDL 1.3 supports multiple windows and 1.2 doesn’t, SDL 1.3
supports complex language text composition and input while 1.2 doesn’t
etc.

But basically I agree with you that SDL 1.3 should somehow let you get
the OpenGL texture if you need to perform some other GL operations on
that texture… something like:

GLuint *SDL_GetTextureHandle (SDL_TextureID *texture);

PavelOn 30.4.2010, at 13:53, Johannes Kroll wrote:

Hi,

On Fri, 30 Apr 2010 09:10:00 +0200 Pavel Kanzelsberger <@Pavel_Kanzelsberger> wrote:

Hello,

yes SDL textures are opaque types and could probably differ on
various
platforms. What I did was I wrote my own functions for creating
textures, copying them to the screen and so on. That allows me to
attach shaders or fragment programs to my textures.

Pavel

Given that OpenGL is already cross-platform, and looking at the extra
effort you’ve done in this case… Is it really worth using the
texture
management functions etc. of SDL 1.3?

Why not just use SDL 1.2 + GL? I always found that to work quite good.
If 1.3 should be useful, it has to be complete, which would include
lots of complex stuff like cross-platform (and cross-API) shader
support, some efficient way of cross-platform, cross-API
render-to-texture, and so on. But I guess SDL will never try to reach
that level of completeness. Such a library would be huge.

I’m kind of wondering where SDL is going - what’s the point of using
an
SDL with 3D functions if you still have to drop down to the native API
level for the more advanced stuff (which breaks the portability SDL
provides).


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


Pavel Kanzelsberger


E-Mail: pavel at kanzelsberger.com
Jabber: kanzelsberger at jabber.org, ICQ: 20990633

You’d also want texture coordinates returned. So that SDL is able to do
optimizations like texture packing in the background.

cu.On Fri, Apr 30, 2010 at 1:54 PM, Pavel Kanzelsberger wrote:

Hello,

well basically I’m using SDL 1.3 because of textures and for all basic
stuff like UI elements in a window are done using SDL functions. But for
special textures that need shaders I have my own code.

Then SDL 1.3 supports multiple windows and 1.2 doesn’t, SDL 1.3 supports
complex language text composition and input while 1.2 doesn’t etc.

But basically I agree with you that SDL 1.3 should somehow let you get the
OpenGL texture if you need to perform some other GL operations on that
texture… something like:

GLuint *SDL_GetTextureHandle (SDL_TextureID *texture);

Pavel

On 30.4.2010, at 13:53, Johannes Kroll wrote:

Hi,

On Fri, 30 Apr 2010 09:10:00 +0200 Pavel Kanzelsberger wrote:

Hello,

yes SDL textures are opaque types and could probably differ on various
platforms. What I did was I wrote my own functions for creating
textures, copying them to the screen and so on. That allows me to
attach shaders or fragment programs to my textures.

Pavel

Given that OpenGL is already cross-platform, and looking at the extra
effort you’ve done in this case… Is it really worth using the texture
management functions etc. of SDL 1.3?

Why not just use SDL 1.2 + GL? I always found that to work quite good.
If 1.3 should be useful, it has to be complete, which would include
lots of complex stuff like cross-platform (and cross-API) shader
support, some efficient way of cross-platform, cross-API
render-to-texture, and so on. But I guess SDL will never try to reach
that level of completeness. Such a library would be huge.

I’m kind of wondering where SDL is going - what’s the point of using an
SDL with 3D functions if you still have to drop down to the native API
level for the more advanced stuff (which breaks the portability SDL
provides).


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


Pavel Kanzelsberger
http://www.kanzelsberger.com
E-Mail: pavel at kanzelsberger.com
Jabber: kanzelsberger at jabber.org, ICQ: 20990633


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

It could make sense to be able to compile a “light” version of SDL
without all the surface manipulation stuff. Just for setting up windows
with a OpenGL(/ES?) context, and input, audio and all that.

  • Gerry

Den Fri, 30 Apr 2010 14:24:34 +0100
skrev Ren? Dudfield :> You’d also want texture coordinates returned. So that SDL is able to

do optimizations like texture packing in the background.

cu.

On Fri, Apr 30, 2010 at 1:54 PM, Pavel Kanzelsberger wrote:

Hello,

well basically I’m using SDL 1.3 because of textures and for all
basic stuff like UI elements in a window are done using SDL
functions. But for special textures that need shaders I have my own
code.

Then SDL 1.3 supports multiple windows and 1.2 doesn’t, SDL 1.3
supports complex language text composition and input while 1.2
doesn’t etc.

But basically I agree with you that SDL 1.3 should somehow let you
get the OpenGL texture if you need to perform some other GL
operations on that texture… something like:

GLuint *SDL_GetTextureHandle (SDL_TextureID *texture);

Pavel

On 30.4.2010, at 13:53, Johannes Kroll wrote:

Hi,

On Fri, 30 Apr 2010 09:10:00 +0200 Pavel Kanzelsberger wrote:

Hello,

yes SDL textures are opaque types and could probably differ on
various platforms. What I did was I wrote my own functions for
creating textures, copying them to the screen and so on. That
allows me to attach shaders or fragment programs to my textures.

Pavel

Given that OpenGL is already cross-platform, and looking at the
extra effort you’ve done in this case… Is it really worth using
the texture management functions etc. of SDL 1.3?

Why not just use SDL 1.2 + GL? I always found that to work quite
good. If 1.3 should be useful, it has to be complete, which would
include lots of complex stuff like cross-platform (and cross-API)
shader support, some efficient way of cross-platform, cross-API
render-to-texture, and so on. But I guess SDL will never try to
reach that level of completeness. Such a library would be huge.

I’m kind of wondering where SDL is going - what’s the point of
using an SDL with 3D functions if you still have to drop down to
the native API level for the more advanced stuff (which breaks the
portability SDL provides).


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


Pavel Kanzelsberger
http://www.kanzelsberger.com
E-Mail: pavel at kanzelsberger.com
Jabber: kanzelsberger at jabber.org, ICQ: 20990633


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

Interestingly enough, if you look in SDL_renderer_gl.c, you see a few shaders and an internal API for binding one to a texture. They’re used internally to support various operations. Since the functionality is already there, it would be nice if it could be surfaced somehow.

I remember seeing SDL_TextureHandle or something like that while
browsing the SDL source, but I can’t remember where and a quick check
in hg shows nothing. In any case, there doesn’t seem to be a GLuint
SDL_GetTextureHandle(const SDL_Texture*) function in the public API…
Maybe you should add one?On 30 April 2010 00:28, Mason Wheeler wrote:

I’ve got everything working pretty well with SDL 1.3, but there are a few
times when I need to apply a shader to a texture instead of just rendering
as-is.? SDL doesn’t have any APIs for that, but I can probably do it from
the outside if I just had the GLuint handle to the texture.? But there
doesn’t seem to be an API to obtain that either.

I’m open to suggestions on doing this in a useful way that could work
across renderers, or maybe expose some renderer-specific APIs…On Fri, Apr 30, 2010 at 11:31 AM, Mason Wheeler wrote:

Interestingly enough, if you look in SDL_renderer_gl.c, you see a few
shaders and an internal API for binding one to a texture.? They’re used
internally to support various operations.? Since the functionality is
already there, it would be nice if it could be surfaced somehow.


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


-Sam Lantinga, Founder and President, Galaxy Gameworks LLC

Honestly, if you’re at the point where you’re trying to write shaders,
you’re probably better off just using SDL for context management and
write OpenGL code. :)On Sun, May 9, 2010 at 11:19 AM, Sam Lantinga <@slouken> wrote:

I’m open to suggestions on doing this in a useful way that could work
across renderers, or maybe expose some renderer-specific APIs…

On Fri, Apr 30, 2010 at 11:31 AM, Mason Wheeler wrote:

Interestingly enough, if you look in SDL_renderer_gl.c, you see a few
shaders and an internal API for binding one to a texture.? They’re used
internally to support various operations.? Since the functionality is
already there, it would be nice if it could be surfaced somehow.


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


? ? ? ?-Sam Lantinga, Founder and President, Galaxy Gameworks LLC


-Sam Lantinga, Founder and President, Galaxy Gameworks LLC

Honestly, if you’re at the point where you’re trying to write shaders,
you’re probably better off just using SDL for context management and
write OpenGL code. :slight_smile:

I’d agree, if I was making heavy use of them, but I’m really not. The
built-in texture management is enough for most things I need, but there
are a few times when I’m going to need to perform tasks such as HSL
modifications on a texture, and for that I’ll need a shader.>----- Original Message ----

From: Sam Lantinga
Subject: Re: [SDL] How do I apply a shader to a texture?

So what do you do when the renderer is software or Direct3D?On Sun, May 9, 2010 at 11:52 AM, Mason Wheeler wrote:

----- Original Message ----

From: Sam Lantinga <@slouken>
Subject: Re: [SDL] How do I apply a shader to a texture?

Honestly, if you’re at the point where you’re trying to write shaders,
you’re probably better off just using SDL for context management and
write OpenGL code. :slight_smile:

I’d agree, if I was making heavy use of them, but I’m really not. ?The
built-in texture management is enough for most things I need, but there
are a few times when I’m going to need to perform tasks such as HSL
modifications on a texture, and for that I’ll need a shader.


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


-Sam Lantinga, Founder and President, Galaxy Gameworks LLC

I don t. ;)On Sun May 9th, 2010 12:28 PM PDT Sam Lantinga wrote:

So what do you do when the renderer is software or Direct3D?

On Sun, May 9, 2010 at 11:52 AM, Mason Wheeler <@Mason_Wheeler> wrote:

----- Original Message ----

From: Sam Lantinga
Subject: Re: [SDL] How do I apply a shader to a texture?

Honestly, if you’re at the point where you’re trying to write shaders,
you’re probably better off just using SDL for context management and
write OpenGL code. :slight_smile:

I’d agree, if I was making heavy use of them, but I’m really not. ?The
built-in texture management is enough for most things I need, but there
are a few times when I’m going to need to perform tasks such as HSL
modifications on a texture, and for that I’ll need a shader.


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


-Sam Lantinga, Founder and President, Galaxy Gameworks LLC


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

I know I ve mentioned this before, but isn t the software renderer a bit useless these days? Every modern computer, be it a desktop, laptop, gaming console or smartphone, has a hardware-accelerated OpenGL or GLES implementation, and has (for personal computers at least) for ten years or more. So is there any valid reason to consider the question what if the software renderer can t do it? in feature-implementation decisions anymore?On Sun May 9th, 2010 12:28 PM PDT Sam Lantinga wrote:

So what do you do when the renderer is software or Direct3D?

On Sun, May 9, 2010 at 11:52 AM, Mason Wheeler <@Mason_Wheeler> wrote:

----- Original Message ----

From: Sam Lantinga
Subject: Re: [SDL] How do I apply a shader to a texture?

Honestly, if you’re at the point where you’re trying to write shaders,
you’re probably better off just using SDL for context management and
write OpenGL code. :slight_smile:

I’d agree, if I was making heavy use of them, but I’m really not. ?The
built-in texture management is enough for most things I need, but there
are a few times when I’m going to need to perform tasks such as HSL
modifications on a texture, and for that I’ll need a shader.


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


-Sam Lantinga, Founder and President, Galaxy Gameworks LLC


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