What is SDL_Surface? [closed]

老子叫甜甜 提交于 2019-12-13 08:19:40

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/24170028/what-is-sdl-surface

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!