Reputation: 2898
In the program below, SDL_SetWindowSize
does make the window itself bigger... but it doesn't let SDL_RenderClear
(or other functions) display anything in that new area.
The platform is CentOS running on VMWare. I don't get this problem in my Visual Studio version, FWIW.
In this screenshot, the window with the grey top bar is the new window created by the resize; it's cleared to red, but only in the area delimited by the old size.
I know I could create the window the right size from the beginning, but I really do need the ability to resize later.
#include <SDL.h>
#include <SDL_ttf.h>
#include <SDL_image.h>
SDL_Window* sdlWindow;
SDL_Renderer* sdlRenderer;
class myException {};
void initialize ()
{
if (SDL_Init (SDL_INIT_EVERYTHING) < 0)
throw myException ();
sdlWindow = SDL_CreateWindow ("",
SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
640, 480,
0);
if (! sdlWindow) throw myException ();
int rendererIndex = -1, rendererFlags = 0;
sdlRenderer = SDL_CreateRenderer (sdlWindow, rendererIndex, rendererFlags);
if (! sdlRenderer) throw myException ();
SDL_ClearError ();
}
int main (int argc, char** argv)
{
initialize ();
SDL_SetWindowSize (sdlWindow, 800, 400);
SDL_SetRenderDrawColor (sdlRenderer, 255, 0, 0, 255); //now we'll clear to red
SDL_RenderClear (sdlRenderer);
SDL_RenderPresent (sdlRenderer); //update screen now
SDL_Delay (2000); //Delay, then quit
SDL_Quit ();
return 0;
}
Upvotes: 1
Views: 1154
Reputation: 35255
The rendering surface is invalidated on windows resize, quote from SDL wiki on SDL_GetWindowSurface:
This surface will be invalidated if the window is resized. After resizing a window this function must be called again to return a valid surface.
So you must get window surface again after resizing window, in general.
Upvotes: 1