Building SDL project with .bat-file

If you want specific surface format, then yes - you'll need to create new surface, render into it, and then blit to window surface.

You don't need to destroy window surface. It belongs to window, it has owership of its surface. You need to destroy only surfaces you create (like with ConvertSurfaceFormat or CreateRGBSurface).

Doing surface2 = ConvertSurfaceFromat(surface1, ...) won't make pixels apear on surface1 when you write to surface2. Because that's completely separate memory. You'll need to do a blit: https://wiki.libsdl.org/SDL_BlitSurface

You can "optimize" a bit by blitting only when needed:
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
window_surface = GetWindowSurface(window);
bool need_blit;
if (window_surface is in format I like)
{
  surface = window_surface;
  need_blit = false;
}
else
{
  surface = CreateNewSurface with format I want;
  need_blit = true;
}

... // render to surface

if (need_blit)
{
  BlitSurface(from surface to window_surface);
}

Edited by Mārtiņš Možeiko on