Setting up VSYNC with SDL_CreateWindowAndRenderer

Hello,

I’m running my game full screen using the desktop resolution with SDL_CreateWindowAndRenderer. This all works fine.

I would like to add a VSYNC option, so that the players can turn it on if they desire. However, the docs for SDL_CreateWindowAndRenderer show that only Window flags can be supplied.

How can I create a fullscreen game with VSYNC turned on?

Thanks.------------------------
bigosaur.com

You can use SDL_CreateWindow() and SDL_CreateRenderer() to archive the same thing.

Code:
window = SDL_CreateWindow(
“An SDL2 window”, // window title
SDL_WINDOWPOS_UNDEFINED, // initial x position
SDL_WINDOWPOS_UNDEFINED, // initial y position
640, // width, in pixels
480, // height, in pixels
SDL_WINDOW_FULLSCREEN // flags - see below
);

renderer = SDL_CreateRenderer(window , -1, SDL_RENDERER_PRESENTVSYNC);

mr_tawan wrote:

You can use SDL_CreateWindow() and SDL_CreateRenderer() to archive the same thing.

Code:
window = SDL_CreateWindow(
“An SDL2 window”, // window title
SDL_WINDOWPOS_UNDEFINED, // initial x position
SDL_WINDOWPOS_UNDEFINED, // initial y position
640, // width, in pixels
480, // height, in pixels
SDL_WINDOW_FULLSCREEN // flags - see below
);

renderer = SDL_CreateRenderer(window , -1, SDL_RENDERER_PRESENTVSYNC);

That code creates a 640x480 pixel window. I want to run the game in fullscreen.

Thanks.------------------------
bigosaur.com

mr_tawan wrote:

You can use SDL_CreateWindow() and SDL_CreateRenderer() to archive the same thing.

Code:
window = SDL_CreateWindow(
“An SDL2 window”, // window title
SDL_WINDOWPOS_UNDEFINED, // initial x position
SDL_WINDOWPOS_UNDEFINED, // initial y position
640, // width, in pixels
480, // height, in pixels
SDL_WINDOW_FULLSCREEN // flags - see below
);

renderer = SDL_CreateRenderer(window , -1, SDL_RENDERER_PRESENTVSYNC);

I just discovered that you cannot edit forum posts, so I’ll be more careful.

That code makes the game run at 640x480 resolution. I want to keep the native desktop resolution. How can I achieve that?------------------------
bigosaur.com

I supposed you already have the code that use SDL_CreateWindowAndRenderer() already. You can use the same w, h, and Window flag parameters with the SDL_CreateWindow(). Then create the renderer with SDL_CreateRenderer().

mr_tawan wrote:

I supposed you already have the code that use SDL_CreateWindowAndRenderer() already. You can use the same w, h, and Window flag parameters with the SDL_CreateWindow(). Then create the renderer with SDL_CreateRenderer().

The whole point was that I did not know what to use for X and Y values because I wanted current desktop resolution. I could get it with SDL_GetDesktopDisplayMode, but if user has multiple monitors I don’t know on which monitor will the game show up.

However, I discovered SDL_WINDOW_FULLSCREEN_DESKTOP which actually does what I want. So, problem is solved.------------------------
bigosaur.com