Creating SDL Wrapper? OpenGL question

Hello,

So I had some questions I was hoping someone could answer.

Does anyone know of a good way to create a Window and Renderer class and leave options for using OpenGL? I’ve been trying to create classes and I’m a bit confused on a few things. I’d like to give it SFML-like syntax and I came across a cool project called SDLpp and SDLxx. I don’t want to use those though as it’s bloated with a lot of files and I just really want a basic setup. Window, Color, Renderer, View and making what I need from there.

I don’t know much OpenGL and have only dabbled in it. If I got to the point where I could load textures in using SDL and OpenGL instead of SDL_Renderer, would I end up being okay (hope that makes sense)? I just want to make 2D games, but I don’t want to really learn OpenGL to do so. But I like the idea of using Shaders later, much like SFML.

Also, I have a course that also creates its own ScreenBuffer and he claimed because SDL doesn’t have double buffering. Doesn’t SDL_RenderPresent() already do this? What would be the benefit of providing a screen buffer class?

If anyone has some barebone frameworks/examples I’d greatly appreciate it because this has drove me nuts figuring the best way to go about this and not bloat my project.

Thanks

Hi, I’m actually working on exactly this! I’m writing this small-scoped C++ framework called ion that adds RAII resource handlers for various SDL and OpenGL components and some basic higher-level event handling. All classes are written as if they were std::expected objects - meaning that instead of throwing exceptions, they have falsey-ness and an error message, and they’re also implicitly convertible to their underlying SDL types.

So far, I’ve found it to be really useful for prototyping games. I’m still working on writing an example for the OpenGL part, but I currently have shader and shader-program classes to make loading, compiling and using shaders sweat-free! For example

ion::shader_program simple_shader('simple', '../shaders');

finds all shaders with the name ‘simple’ and with standard shader extension names in the directory ../shaders, and compiles them into a single shader program, which you can then use directly as an opengl id: glUseProgram(simple_shader)

The project is lacking in documentation right now and doesn’t have any tests, because I’ve just been using it to prototype some games. I’m currently a student so I probably won’t have a lot of time to add extensive documentation and unit-tests until I graduate next year, but I expect to make small progress here and there before then.

Although, since I don’t have documentation for it, I’ll say it here: if you want to use opengl functionality, you need to use a glwindow instead of a render_window:

#include <ion/gl.hpp>
...
ion::glwindow window{"An SDL-opengl window", 640, 480};

I’ll try to add more documentation soon about this in particular, since the opengl part of the library is actually its own CMake component, so compiling it is a little different than the simple example on the github page I linked.

Hey, Appreciate it! I’ll look closer at it later. I actually found something that worked out great and will continue to keep an eye on your project.

I ended up using a lot of this: https://github.com/edhebi/cpp-sdl2 and taking parts I like out from https://github.com/fallahn/crogine/tree/master/crogine. The first link is great because I could simply take the Window, Renderer, Color and have a nice example to use OpenGL or SDL_Renderer based on choice. It also has an example on running either. Maybe there is some help in there for you as well!

Take care.