[SDL] How to get resolution of my SDL window?

David Olsen jolynsbass at gmail.com
Wed Dec 5 09:03:51 PST 2007


No need to use windows-specific functions...
Just use the SDL_GetVideoSurface() function. It returns a pointer to the 
current display surface. you can even use it directly:
int screen_width = SDL_GetVideoSurface()->w; // this gives surface width
int screen_height = SDL_GetVideoSurface()->h; // this gives surface height

if you assign it to an existing pointer (screen = SDL_GetVideoSurface();) it 
will only work until the screen is resized, at which point you must reassign 
the pointer to the changed video surface. (similar, if not identical, to 
what you have been describing.)

I hope that helps.
-Dave

----- Original Message ----- 
From: "voidstar" <voidstar at tin.it>
To: <sdl at libsdl.org>
Sent: Wednesday, December 05, 2007 6:34 AM
Subject: Re: [SDL] How to get resolution of my SDL window?


>> width=screen->w;
>>
>> height=screen->h;
>
> Yes, but in this way I can't get the correct window resolution if I've
> resized the window while the SDL_VIDEORESIZE was disabled.
>
> In this case, if I resize the window, for SDL the window is not resized,
> so screen->w e screen->h are unchanged... but the window is resized (not
> SDL updated, but resized).
>
> I need this check because i want to restore window resolution if the user
> try to resize the window while the SDL_VIDEORESIZE event is disabled.
>
> However, I've found this way to do it:
>
>  RECT windowRect;
>  GetClientRect(hWnd, &windowRect);
>  int real_w = windowRect.right-windowRect.left;
>  int real_h = windowRect.bottom-windowRect.top;
>
> I think this is the only way to do it... or not?
> What do you think?
>
> Thank you for your help!
>
>
> _______________________________________________
> SDL mailing list
> SDL at lists.libsdl.org
> http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org 



More information about the SDL mailing list