Understanding of How Rendering Works

I am interested in possibly using SDL .NET for a project and wanted to make sure I understand something.

My question is what does SDL use for rendering graphics? Is it OpenGL or DirectX?

Also, I have read that it knows what to use depending on the OS. So if your building for windows it uses DirectX mappings and if other operating systems, it uses OpenGL. But I have already read that it uses GDI by default on Windows OS? I don’t want this. So in the scenario with building and mapping the correct layer, does that only apply to C++ version of SDL?

I would like to have SDL use OpenGL all the time no matter what. The end result is 2D games, so does that mean it would use the GDI? I also read somewhere that if you do 3D it uses OpenGL by default, but not for 2D.

But in the end, yes I am not going to be doing 3D, only 2D textures. But can I use the GPU if I am rendering 2D textures?

Any clarification on this would be awesome.


That’s what I do. It’s easily achieved using a hint (assuming the platform supports it):


I am not going to be doing 3D, only 2D textures. But can I use the GPU if I am rendering 2D textures?

Yes, SDL uses the GPU for 2D rendering if it can.

1 Like

Ok awesome. Couple more questions.

You said that it will use the GPU for 2D rendering if it can.

  1. So if I am on windows, what are the requirements on a windows machine to be able to render using the GPU and OpenGL?

  2. Do I have to actually turn on the switch using SDL_SetHint()? Or is it all automatic?

I understand that if the situation is an incompatible GPU or no GPU at all, that obviously it won’t work. But is that all you mean? I take it that it auto detects if it cannot, and if it can’t use the GPU, it just defaults to GDI/Software rendering?

Perfect. That’s everything I needed.

Thanks for answering my questions!!

This is not quite correct.
Windows only ships some broken OpenGL 1.1 implementation - is that even enough for SDL?
Even if it is, DirectX will work a lot better in that case.
To have proper OpenGL support you need drivers from the GPU vendor. That can be a problem for older GPUs, specifically I know that Intel does not provide Win10 drivers for HD 3000 GPUs (as built into Sandy Bridge CPUs), and the one provided by Microsoft via Windows update don’t support OpenGL.

So unless you have a very good reason to enforce OpenGL, just let SDL select the render driver.

I’m not aware that it is “broken”, and I’ve always assumed it is enough for SDL. The docs for SDL_GL_CreateContext state “for historical reasons, GL functions added after OpenGL version 1.1 are not available by default. Those functions must be loaded at run-time” which I read as implying OpenGL 1.1 is the base level needed by SDL.

Even if it is, DirectX will work a lot better in that case.

I have no choice in my app. I need to call glLogicOp to enable exclusive or (as well as OR, AND) plotting modes so I have to force OpenGL using the hint. None of my users has reported a problem when running on Windows.

If I was to develop a game and during run time it would just select the proper drivers for the OS its running on, and it all runs fine, then it is cross platform enough for me and I am happy. :smiley:

I think those are OpenGL’s historical reasons, not SDLs.
Also, the docs for SDL_GL_CreateContext have nothing to do with SDL_Renderer

BTW, @KinsonDigital, as I think this hasn’t explicitly been mentioned yet: Make sure to use the SDL_Renderer API for HW accelerated 2D rendering: https://wiki.libsdl.org/CategoryRender

Awesome. Thanks!!

What is HW accelerated 2D rendering.

The HW part specifically.

HW == Hardware, HW accelerated meaning GPU accelerated, which is what you want