Rendering pixels from array of RGB values in SDL 1.2?

最后都变了- 提交于 2019-11-29 15:12:27

You need to store the data as an unidimensional char array:

int channels = 3; // for a RGB image
char* pixels = new char[img_width * img_height * channels];

// populate pixels with real data ...

SDL_Surface *surface = SDL_CreateRGBSurfaceFrom((void*)pixels,
                img_width,
                img_height,
                channels * 8,          // bits per pixel = 24
                img_width * channels,  // pitch
                0x0000FF,              // red mask
                0x00FF00,              // green mask
                0xFF0000,              // blue mask
                0);                    // alpha mask (none)
Ciro Santilli 新疆改造中心996ICU六四事件

In 2.0, use SDL_Texture + SDL_TEXTUREACCESS_STREAMING + SDL_RenderCopy, it's faster than SDL_RenderPoint.

See:

Related: Why do I get bad performance with SDL2 and SDL_RenderCopy inside a double for loop over all pixels?

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