SDL2 What it was missing, why and..

SDL2 was missing a lot of base functions that I never really understood why, for example, SDL2 lacked set and get pixel functions, why? It also lacked basic line drawing and primitives other than SDL_FillRect().

Does anyone know why these basic functions where never accepted into the project and if they will be added to SDL3?

In SDL2 it is possible to use SDL_GetWindowSurface to obtain the surface of the window, then use ->pixels to get the native array of pixels. The set and get pixel functions there are simply the native integer read/write operations in C, allowing software rendering to be done. SDL_UpdateWindowSurface on each frame gets the surface contents natively to the screen.

You mean by accessing the pixel array in SDL_Surface?

That’s not good enough, because an SDL_Surface can have multiple pixel formats, that’s the point of get and set pixel functions, that they can detect the format for you.

Detecting format on each pixel read/write incurs a branch though, making it slower than native integer read/write, which slows down software rendering, making it bloatware.

They are provided in the companion SDL2_gfx project, which I have extended to include more anti-aliased drawing functions (see here for my modified version).

It seems to me entirely reasonable for this functionality to be in a companion project rather than bloating core SDL (as with SDL2_mixer, SDL2_image etc.), but I don’t know what the plans for SDL3 are in this regard.

Note that in SDL 1.2 we used to pass SDL_Surfaces to the drawing functions. SDL 2 added SDL_Texture so now we normally pass SDL_Renderer to the drawing functions instead which is able to handle both textures and surfaces (use SDL_CreateSoftwareRenderer to create a renderer to a surface).

Isn’t SDL_RenderDrawPoint essentially a “set pixel” function?

I guess you might be able to use SDL_RenderReadPixels to read a single pixel but it’s not as convenient as you might like.

There is SDL_RenderDrawLine that you can use to draw lines but perhaps it’s a bit too simplistic? I can’t seem to find a way to adjust the thickness.

SDL_FillRect is the same as it was in SDL 1.2 and only works on surfaces. If you want to use SDL_Renderer (like the rest of the functions above) then you can use SDL_RenderFillRect or SDL_RenderDrawRect.

That’s interesting, so would SDL_RenderDrawLine draw a line ontop of say an OpenGL render surface, because I know traditionally it’s not officially supported to render 2D directly to a 3D graphics context in SDL.

Is that what SDL_RenderFlush is for?

Sorry, I really don’t know. Hopefully someone else can answer your question.