什么是SDL_Surface? [英] What is SDL_Surface?

查看:376
本文介绍了什么是SDL_Surface?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遵循lazyfoo的教程 http://lazyfoo.net/tutorials/SDL /01_hello_SDL/index2.php
,当绘制到屏幕时使用'surface'。它是什么,是否类似于SDL_Texture?这是与缓冲区?

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 在SDL2.0中引入并启用硬件渲染。呈现 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
)

你应该尝试只使用 SDL_Texture ,因为它们被优化用于渲染,与 SDL_Surface

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


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.

SDL2.0的某些部分仍然使用 SDL_Texture (如图片加载或文字渲染)

Some parts of SDL2.0 still uses SDL_Texture ( like image loading or text rendering )

幸运的是,只需将 SDL_Surface 转换为 SDL_Texture 即可使用

Luckily, you can simply convert an SDL_Surface to SDL_Texture using

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


$ b b




有关SDL2以及如何使用它制作游戏的更多信息,您可以查看我的 blog。

这篇关于什么是SDL_Surface?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆