SDL中文论坛
标题:
SDL_RenderReadPixels
[打印本页]
作者:
ancientcc
时间:
2016-7-14 10:35
标题:
SDL_RenderReadPixels
本帖最后由 ancientcc 于 2016-7-14 10:45 编辑
从当前帧缓冲区读像素数据
语法
int SDL_RenderReadPixels(SDL_Renderer* renderer, const SDL_Rect* rect, Uint32 format, void* pixels, int pitch)
复制代码
参数
renderer
要操作的渲染器
rect
位在帧缓冲区的矩形,函数目标就是取该矩形块内的像素
format
生成的像素数据的格式
pixels
app须预分配、用于存放生成的像素数据的存储区
pitch
生成的像素块的行跨距。
不是帧缓冲区的行跨距。
返回值
0表示成功。否则是一个负值,调用SDL_GetError可获得错误的更多信息。
范例
surface dst = create_neutral_surface(area.w, area.h);
{
surface_lock dst_lock(dst);
uint32_t format = get_neutral_pixel_format().format;
SDL_RenderReadPixels(get_renderer(), &area, format, dst->pixels, SDL_BYTESPERPIXEL(format) * area.w);
}
复制代码
读当前帧缓冲区,把area块内像素搬到dst->pixels。dst->pixels中的像素格式是get_neutral_pixel_format().format。
注释
这是个非常慢的函数,不要经常调用。
怎么个慢法,参考这贴子:
SDL_UpdateTexture、SDL_RenderCopy、SDL_RenderReadPixels的花费时间
窗口帧缓冲区和目标帧缓冲区
SDL_RenderReadPixels支持从两种帧缓冲区读取数据,渲染器的target变量控制了要读取是哪一种。当是目标帧缓冲区时,有一些特殊限定。
目标帧缓冲区对应纹理的像素格式须是4分量、4字节。
SDL_RenderReadPixels不会改变像素格式,它直接以纹理格存放在pixels。因为这个原因,参数format其实只要表示这是“4分量、4字节”就行,而pitch总是要等于w*4。
相关类、函数
<Relative class, function>
欢迎光临 SDL中文论坛 (http://www.libsdl.cn/bbs/)
Powered by Discuz! X3.3