My Question is how to get the current window size?
It needs to be able to get the window size, both fullscreen or windowed.
I am using SDL2, Glad, OpenGL #ver 130. On Window 10 with scaling.
I initialized the window to be 1280x720.
SDL_CreateWindow(window, title.c_str(), SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
1280, 720, SDL_WINDOW_ALLOW_HIGHDPI | SDL_WINDOW_SHOWN | SDL_WINDOW_OPENGL |
SDL_WINDOW_RESIZABLE);
It is an OpenGL context enable window.
SDL_GL_CreateContext
gladLoadGL
All I want is the get the current window size. I expected it to be 1280x720.
SDL_DisplayMode dm;
if( SDL_GetCurrentDisplayMode( 0, &dm ) != 0 ) {
//save log
}
printf("%dx%d\n", dm.h, dm.w);
The terminal output.
960x1707
And yet I am getting an odd number, 1707x960. I don't think this is correct.
SDL_GetCurrentDisplayMode()
returns the current resolution of the given display/monitor, not the size of a window.You want
SDL_GetWindowSize()
for the window size andSDL_GL_GetDrawableSize()
for un-HiDPI-scaled dimensions to pass intoglViewport()
.