Several SDL2 question

Hi!

I’m a guy from Hungary who would like to use SDL2, but I have some
questions.

1.) SDL_Surface is the 2D bitmap in the system memory, processed by the
CPU; and SDL_Texture is basically the same, but on the GPU and processed by
the GPU (if there’s any).
But if there is no graphical unit, what does SDL_Texture do? Does it became
SDL_Surface eventually, in the background?

2.) I would like to draw filled 2D triangles and I’m looking for the
fastest way possible. With SDL1.2 it was easy, because I only had to modify
the pixel data of a SDL_Surface, but with SDL2 I’m confused. Since it does
have some nice OpenGL context setup functions, I think the fastest way
would be to use the immediate, legacy OpenGL functions, like glBegin(),
glVertex3f(), etc; but I don’t want to implement 2 different code for
triangle drawing based on SDL_Surface and OpenGL context. My main problem
is that I don’t know how to draw on an SDL_Texture that works everywhere
and is fast.
What does the SDL_RenderFillRect() do in the background? glBegin() and so
on?
Is SDL2 going to have a built-in filled triangle drawing method sometime?

Thanks in advance,
Laszlo Boros

L??szl?? Boros wrote:

1.) SDL_Surface is the 2D bitmap in the system memory, processed by the CPU; and SDL_Texture is basically the same, but on the GPU and processed by the GPU (if there’s any).

But if there is no graphical unit, what does SDL_Texture do? Does it became SDL_Surface eventually, in the background?

I believe that they would be pretty close to each other, but the interface would be different. Even if it’s the case, I wouldn’t assume that it would be SDL_Surface in the background.

L??szl?? Boros wrote:

2.) I would like to draw filled 2D triangles and I’m looking for the fastest way possible. With SDL1.2 it was easy, because I only had to modify the pixel data of a SDL_Surface, but with SDL2 I’m confused. Since it does have some nice OpenGL context setup functions, I think the fastest way would be to use the immediate, legacy OpenGL functions, like glBegin(), glVertex3f(), etc; but I don’t want to implement 2 different code for triangle drawing based on SDL_Surface and OpenGL context. My main problem is that I don’t know how to draw on an SDL_Texture that works everywhere and is fast.

What does the SDL_RenderFillRect() do in the background? glBegin() and so on?
Is SDL2 going to have a built-in filled triangle drawing method sometime?

Hmm… I believe that in no time there would be someone suggesting SDL_gpu. You could go completely software route by manipulating SDL_Surface the way you like then convert it to SDL_Texture (using SDL_CreateTextureFromSurface()), or using SDL_DrawLine() and some scanline algorithms that could draw filled triangles and stuffs (I do this in my font rendering code and the performance is not too bad). I can not say that they are good methods to archive that, but well at least they are doable.

Remember, SDL is open-source. You could dive into the source code and see for yourself what is used under those API (the code looks pretty good, it won’t confuse you :)).

Thanks!