Update 33

I have discovered that you cannot integrate shaders with SDL without using pure OpenGL. The other sad thing is if you have an OpenGL context associated with a renderer you cannot use SDL_Texture and OpenGL textures at the same time because  the OpenGL backend from the SDL_Texture will interfere. So if you want to support shader you have to go full OpenGL and drop the rendering part of SDL: SDL_RenderCopy, SDL_RenderClear, SDL_RenderPresent,… and only use OpenGL and GLEW or any other libraries to load extensions to have at least OpenGL 2.1.

It’s quite sad to learn that the preferred way to do things is to reinvent the wheel especially for something “classic” like a 2D game. In this case, SFML is a lot more interesting because you can apply a shader to a sprite in one line, not ten like with OpenGL. I have seriously thought about dropping the shader support because going full OpenGL change everything and “wasting” a lot of time reinventing the wheel. You could argue that OpenGL has it’s advantage in term of performances and compatibility across mobile phone and tablet. For a 2D game developed by one person, the price to pay is important  in term of time invested and I have already said it already: I do not have all the time in the world to make this game.

The one good news is that there is a non-official extension SDL library developed by one man who fit this purpose:  SDL_gpu. I have already written a test to see if it’s working with multi-texturing and it seem to work. It uses stb_image to load images so I will drop SDL_Image, I can keep SDL_ttf because SDL_Surface can be converted into GPU_Image.

Leave a Reply

Your email address will not be published. Required fields are marked *