Unclear on purpose of the SDL renderer vs. GL functions?

I’m a bit unclear as to whether I should be using GL functions or using the SDL renderer, or a combination of both.

The SDL renderer seems to focus primarily on basic primitives and images in a 2D environment. There is no 3D pipeline. Is that correct?

If I’m using GL, should I keep creating the SDL renderer, or shall I avoid it? In particular it’d be still convenient to load images and fonts.

I’m using the various sdl_gl* functions to setup the GL context. I also noticed that when the window size changes I must call glViewport on my own – like beyond context setup SDL does nothing with GL. Is this correct, or could I possibly be doing something wrong?

I’m a bit unclear as to whether I should be using GL functions or using the
SDL renderer, or a combination of both.

Consider the SDL renderer and the GL stuff as mutually exclusive.

The SDL renderer seems to focus primarily on basic primitives and images in
a 2D environment. There is no 3D pipeline. Is that correct?

Correct. The SDL renderer is a simple API, mostly good for simple 2D needs.

As an implementation detail, the SDL renderer may use native platform
rendering backends. So for example, on Windows, it uses Direct3D by
default instead of OpenGL. And theoretically, the SDL renderer could
use Metal on Apple platforms and Vulkan on platforms that support it.

The SDL renderer is not tied to OpenGL, which is why you should
consider them mutually exclusive.

If I’m using GL, should I keep creating the SDL renderer, or shall I avoid
it? In particular it’d be still convenient to load images and fonts.

Generally, you should avoid it. (Consider what happens if the SDL
renderer is using Direct3D on Windows, and you then try to mix
OpenGL.)

I’m using the various sdl_gl* functions to setup the GL context. I also
noticed that when the window size changes I must call glViewport on my own
– like beyond context setup SDL does nothing with GL. Is this correct, or
could I possibly be doing something wrong?

Correct. The SDL_GL APIs exist to fill in the missing native platform
specific APIs, that OpenGL itself does not provide, needed to manage
an OpenGL context (and in a cross-platform way). Generally, SDL does
not replace functionality in OpenGL and you are expected to take full
responsibility for your GL code, e.g. calling glViewport when
appropriate.

-Eric

1 Like

glViewport seems to be a special case. I found it necessary to call it myself on iOS, but not on any of the other platforms I support (Windows, Linux, Mac OS, Raspberry Pi, Android). This feels wrong to me, but whether one should always call it or whether SDL is behaving anomalously on iOS I don’t know.