How choose between two sizes of windows?

I have the code below which would choose different size windows based on a keyboard input. The compiler says: error: ?win1? was not declared in this scope. If I declare a single window and get rid of the IF statement there is no error. I see the problem: Ignoring the IF, there could be two different values of win1, therefore there is none. Can you tell me what SDL statements I can use to choose one or another size of window?
TIA. Bill S.

if (mode == 1)
SDL_Window *win1 = SDL_CreateWindow("", 0, 0, 640, 480, SDL_WINDOW_SHOWN);
if (mode == 2)
SDL_Window *win1 = SDL_CreateWindow("", 0, 0, maxx, maxy, SDL_WINDOW_SHOWN);
SDL_Renderer *ren = SDL_CreateRenderer( win1, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);

Try something like this:

SDL_Window *win1 = NULL;
if (mode == 1) win1 = SDL_CreateWindow("", 0, 0, 640, 480,
SDL_WINDOW_SHOWN);
if (mode == 2) win1 = SDL_CreateWindow("", 0, 0, maxx, maxy,
SDL_WINDOW_SHOWN);
SDL_Renderer *ren = SDL_CreateRenderer( win1, -1, SDL_RENDERER_ACCELERATED
| SDL_RENDERER_PRESENTVSYNC);

The main issue was you were defining win1 inside an if block, which is
scoped.On Thu, Mar 12, 2015 at 7:33 AM, bilsch01 wrote:

I have the code below which would choose different size windows based on
a keyboard input. The compiler says: error: ?win1? was not declared in this
scope. If I declare a single window and get rid of the IF statement there
is no error. I see the problem: Ignoring the IF, there could be two
different values of win1, therefore there is none. Can you tell me what SDL
statements I can use to choose one or another size of window?
TIA. Bill S.

if (mode == 1)
SDL_Window *win1 = SDL_CreateWindow("", 0, 0, 640, 480, SDL_WINDOW_SHOWN);
if (mode == 2)
SDL_Window *win1 = SDL_CreateWindow("", 0, 0, maxx, maxy,
SDL_WINDOW_SHOWN);
SDL_Renderer *ren = SDL_CreateRenderer( win1, -1, SDL_RENDERER_ACCELERATED
| SDL_RENDERER_PRESENTVSYNC);


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Just be aware that if there is a case where mode is not 1 or 2, win1 will
be NULL, and cause you some problems. You may want to use a switch
structure here:

switch(mode) {
case 1: win1 = SDL_CreateWindow( … ); break;
case 2: win1 = SDL_CreateWindow( … ); break;
default: printf(“Mode was not 1 or 2, what should I do?\n”); exit(1);
break;
}On Thu, Mar 12, 2015 at 7:47 AM, Alex Barry <@Alex_Barry> wrote:

Try something like this:

SDL_Window *win1 = NULL;
if (mode == 1) win1 = SDL_CreateWindow("", 0, 0, 640, 480,
SDL_WINDOW_SHOWN);
if (mode == 2) win1 = SDL_CreateWindow("", 0, 0, maxx, maxy,
SDL_WINDOW_SHOWN);
SDL_Renderer *ren = SDL_CreateRenderer( win1, -1, SDL_RENDERER_ACCELERATED
| SDL_RENDERER_PRESENTVSYNC);

The main issue was you were defining win1 inside an if block, which is
scoped.

On Thu, Mar 12, 2015 at 7:33 AM, bilsch01 wrote:

I have the code below which would choose different size windows based
on a keyboard input. The compiler says: error: ?win1? was not declared in
this scope. If I declare a single window and get rid of the IF statement
there is no error. I see the problem: Ignoring the IF, there could be two
different values of win1, therefore there is none. Can you tell me what SDL
statements I can use to choose one or another size of window?
TIA. Bill S.

if (mode == 1)
SDL_Window *win1 = SDL_CreateWindow("", 0, 0, 640, 480, SDL_WINDOW_SHOWN);
if (mode == 2)
SDL_Window *win1 = SDL_CreateWindow("", 0, 0, maxx, maxy,
SDL_WINDOW_SHOWN);
SDL_Renderer *ren = SDL_CreateRenderer( win1, -1,
SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org