C++ 如何从原始位图数据转换为SDL曲面或纹理?
我正在使用一个名为Awesomium的库,它具有以下功能:C++ 如何从原始位图数据转换为SDL曲面或纹理?,c++,bitmap,textures,sdl,surface,C++,Bitmap,Textures,Sdl,Surface,我正在使用一个名为Awesomium的库,它具有以下功能: void Awesomium::BitmapSurface::CopyTo ( unsigned char * dest_buffer, // output int dest_row_span, // input that I can select int dest_depth, // input that I can select bool convert_to_rgba, // input th
void Awesomium::BitmapSurface::CopyTo ( unsigned char * dest_buffer, // output
int dest_row_span, // input that I can select
int dest_depth, // input that I can select
bool convert_to_rgba, // input that I can select
bool flip_y // input that I can select
) const
Copy this bitmap to a certain destination. Will also set the dirty bit to False.
Parameters
dest_buffer A pointer to the destination pixel buffer.
dest_row_span The number of bytes per-row of the destination.
dest_depth The depth (number of bytes per pixel, is usually 4 for BGRA surfaces and 3 for BGR surfaces).
convert_to_rgba Whether or not we should convert BGRA to RGBA.
flip_y Whether or not we should invert the bitmap vertically.
这很好,因为它给了我一个
无符号字符*dest_缓冲区
,其中包含原始位图数据。我已经尝试了几个小时,试图将这个原始位图数据转换成某种可以在SDL中使用的可用格式,但我遇到了麻烦=[是否有任何方法可以将其加载到SDL纹理或曲面中?最好两个都有示例,但如果我只得到一个示例(纹理或曲面),这就足够了,我将非常感激。:)我尝试使用SDL_LoadBMP_RW,但失败了。我甚至不确定是否应该使用该方法。SDL_LoadBMP_RW
用于加载BMP文件格式的图像。它需要一个SDL_RWops*
,这是一个文件流,而不是一个像素缓冲区。您想要的功能是。我相信这通电话对您的目的是有效的:
SDL_Surface* surface =
SDL_CreateRGBSurfaceFrom(
pixels, // dest_buffer from CopyTo
width, // in pixels
height, // in pixels
depth, // in bits, so should be dest_depth * 8
pitch, // dest_row_span from CopyTo
Rmask, // RGBA masks, see docs
Gmask,
Bmask,
Amask
);