SDL2 shader usage

Started by
3 comments, last by slideside12 9 years, 4 months ago

Hey quick question. I've done a lot of searching and can't seem to find an answer so here is my problem:

I want to use SDL2 to handle all the entirety of my 2d game. This not only includes window creation, input, and audio but also rendering. The problem is I have little to no knowledge or experience with openGL. The thing is I do not want to learn openGL (especially since its a 2D game) only to learn how to integrate shaders with SDL. With the SDL hardware accelerated textures I don't see the need to learn openGL for just a 2D game. I wanted to know if there is some example code/walkthrough that can explain how to apply a shader to a SDL texture (or surface even since you can access pixel data there) essentially. Ive done a lot of searching and the basic suggestion is to learn openGL, handle rendering with openGL and then apply the shader through that. Just want to know if there a a simpler solution.

Thanks in advance!

Edit: Second question: Would there really be any benefit in using openGL to render as opposed to SDL? Especially since I don't have any experience with openGL so if I were try it probably wouldn't be anything that advanced/optimized.

Advertisement

Hmm, aren't shaders a part of OpenGL? I mean, you want to use the GPU to render to a texture, and the API to the GPU is called 'OpenGL', so I think you'll have to change your requirement to either use the right tools or not use shaders.

You can, of course, create textures without the use of the GPU using pure SDL and the CPU.

Stephen M. Webb
Professional Free Software Developer

Hmm, aren't shaders a part of OpenGL? I mean, you want to use the GPU to render to a texture, and the API to the GPU is called 'OpenGL', so I think you'll have to change your requirement to either use the right tools or not use shaders.

You can, of course, create textures without the use of the GPU using pure SDL and the CPU.

Thanks for the fast reply.

And I get what you're saying. Honestly I want to use shaders mainly for effects and I could just premake the effects in a graphics program and just animate it but Im under the impression that this will decrease performance and lag the game. For example if I wanted a glow effect I could easily just create a "glow" sprite which would just be like a transparent brightly lit sprite and resize over the game sprite. However if I wanted to do this to lets say 100 sprites that would definitely cause lag. I really don't have a problem learning openGL but I would like to limit it to essentially where I could call a texture->applyShader("shader.frag") function but everywhere I've looked the tutorials and guides go over creating contexts and matrixes and such which is beyond the scope of what I am trying to do.

As for the creating textures on the CPU from what I know that would disable the application of the shader effects and such correct? Like I said I want to use shaders for effects.

Thanks in advance

SDL2 does not have a shader abstraction system. It is a simple hardware abstraction library. Its rendering library is likewise extremely simple.

You might try SFML, which does include a shader library for its custom rendering interface, on account of it exclusively using OpenGL.

Alternatively, use a more complete engine like Unreal (and its 2D-oriented Paper mode) or Unity (and its 2D-oriented game support).

There are also a number of smaller, simpler game engines that focus on 2D, include a bunch of pre-written drawing and rendering support, and allow shaders. I don't know the names of any off hand, but there's like 50 new ones announced every week.

Sean Middleditch – Game Systems Engineer – Join my team!

SDL2 does not have a shader abstraction system. It is a simple hardware abstraction library. Its rendering library is likewise extremely simple.

You might try SFML, which does include a shader library for its custom rendering interface, on account of it exclusively using OpenGL.

Alternatively, use a more complete engine like Unreal (and its 2D-oriented Paper mode) or Unity (and its 2D-oriented game support).

There are also a number of smaller, simpler game engines that focus on 2D, include a bunch of pre-written drawing and rendering support, and allow shaders. I don't know the names of any off hand, but there's like 50 new ones announced every week.

I know SDL2 itself does not have shader abstraction. Like I said I don't have a problem learning openGL to implement shader but I would just prefer to learn it only to the extent of getting the shaders implemented but that probably won't be possible from what I've seen. Also I'd prefer to stay low level so I might just have to learn openGL after all in order to get what I want done. Not sure if there is maybe a library I could use. Anyways thanks for your help. Might look at SFML as I've seen it a couple of times.

This topic is closed to new replies.

Advertisement