I am following a tutorial by lazyfoo http://lazyfoo.net/tutorials/SDL/01_hello_SDL/index2.php and when drawing to the screen a 'surface is used. What is it, is it the similar to SDL_Texture? Is it to do with buffers?
This question is easily answered by looking at the documentation.
SDL_Texture
SDL_Texture contains an efficient / optimized representation of the pixel data. SDL_Texture
was introduced in SDL2.0 and enables hardware rendering. The way to render a SDL_Texture
is
void SDL_RenderPresent
(
SDL_Renderer* renderer
)
You should try to use only SDL_Texture
as they are optimized for rendering, contrary to SDL_Surface
SDL_Surface
An SDL_Surface is basically a struct that contains all the raw pixel data along with some meta-information like size and pixel format. Since SDL_Surface
is just the raw pixel data, it is not optimized in any way and should be avoided when rendering.
Some parts of SDL2.0 still uses SDL_Texture
( like image loading or text rendering )
Luckily, you can simply convert an SDL_Surface
to SDL_Texture
using
SDL_Texture* SDL_CreateTextureFromSurface
(
SDL_Renderer* renderer,
SDL_Surface* surface
)
For more information about SDL2 and how to use it to make games, you can check out my blog.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With