I have an array of pixels that I display to the screen. To do that I use an SDL_Texture object that gets updated using SDL_UpdateTexture like this:
SDL_UpdateTexture(frame_buffer_texture, nullptr, &frame_buffer_pixels, screen_res_x);
In the documentation it says the the third argument is a pointer to an array of pixels however it doesn't specify if the pixels are copied or not.
Is it okay to use a local variable with the pixels that goes out of scope after SDL_UpdateTexutre like this:
void function()
{
uint32_t pixels[screen_res_x * screen_res_y] = { /* pixel data here */ }
SDL_UpdateTexture(texture, nullptr, &pixels, screen_res_x);
}
or do I have to allocate memory for the pixels on the stack like this:
void function()
{
delete pixels; // Delete old pixels
pixels = new uint32_t[screen_res_x * screen_res_y];
// Set pixels values here..
SDL_UpdateTexture(texture, nullptr, pixels, screen_res_x);
}
Not sure if this matters but here is how I render the texture to the screen:
SDL_RenderClear(renderer);
SDL_RenderCopy(renderer, texture, nullptr, nullptr);
SDL_RenderPresent(renderer);
and here is how it is created:
SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_STATIC, screen_res_x * screen_res_y)