Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is SDL_Surface? [closed]

Tags:

c++

sdl

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?

like image 544
GLD Avatar asked Oct 12 '25 03:10

GLD


1 Answers

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.

like image 70
olevegard Avatar answered Oct 14 '25 19:10

olevegard



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!