create new surface with RGBA32 format and pixels as data
| 116 | |
| 117 | // create new surface with RGBA32 format and pixels as data |
| 118 | SDL_Surface* create_texture(std::vector<uint32_t>& pixels, int texture_px_w, int texture_px_h) { |
| 119 | auto surface = DFSDL_CreateRGBSurfaceWithFormat(0, texture_px_w, texture_px_h, 32, |
| 120 | SDL_PixelFormatEnum::SDL_PIXELFORMAT_RGBA32); |
| 121 | auto canvas_length = static_cast<size_t>(texture_px_w * texture_px_h); |
| 122 | for (size_t i = 0; i < pixels.size() && i < canvas_length; i++) { |
| 123 | uint32_t* p = (uint32_t*)surface->pixels + i; |
| 124 | *p = pixels[i]; |
| 125 | } |
| 126 | return surface; |
| 127 | } |
| 128 | |
| 129 | // convert single surface into tiles according w/h |
| 130 | // register tiles in texture raws and return handles |
no test coverage detected