What is SDL_Surface?

I follow the lazyfoo manual http://lazyfoo.net/tutorials/SDL/01_hello_SDL/index2.php and the "surface" is used to draw on the screen. What is it, is it like SDL_Texture? Is this related to buffers?

-3
c ++ sdl
source share
1 answer

This question can be easily answered by looking at the documentation.

SDL_Texture


SDL_Texture contains an efficient / optimized representation of pixel data. SDL_Texture was introduced in SDL2.0 and includes hardware rendering. Visualization Method SDL_Texture -

 void SDL_RenderPresent ( SDL_Renderer* renderer ) 

You should try to use only SDL_Texture , as they are optimized for rendering, unlike SDL_Surface


SDL_Surface


SDL_Surface is basically a structure that contains all the raw pixel data along with some meta-information, such as the size and format of the pixels. Since SDL_Surface is only the original pixel data, it is not optimized in any way and should be avoided when rendering.

Some parts of SDL2.0 still use SDL_Texture (for example, loading an image or rendering text)

Fortunately, you can simply convert SDL_Surface to SDL_Texture with

 SDL_Texture* SDL_CreateTextureFromSurface ( SDL_Renderer* renderer, SDL_Surface* surface ) 

You can learn more about SDL2 and how to use it to create games on the blog.

+7
source share

All Articles