Getting screen dimensions

Once I’ve init’ed SDL, I can enumerate the available display modes, but is
there a way to get the CURRENT display mode (without having set it myself)
from within SDL? I would rather go down this road than use native OS calls.

Thanks,
Jeff Schiller_________________________________________________________________
Get rid of annoying pop-up ads with the new MSN Toolbar ? FREE!
http://toolbar.msn.com/go/onm00200414ave/direct/01/

If I get your question, see documentation about SDL_GetVideoInfo.

/Olof

Jeff Schiller: “[SDL] getting screen dimensions” (2004-04-23 08:50)

#Once I’ve init’ed SDL, I can enumerate the available display modes, but is
#there a way to get the CURRENT display mode (without having set it myself)
#from within SDL? I would rather go down this road than use native OS calls.#
#Thanks,
#Jeff Schiller

#_________________________________________________________________
#Get rid of annoying pop-up ads with the new MSN Toolbar ? FREE!
#http://toolbar.msn.com/go/onm00200414ave/direct/01/

#_______________________________________________
#SDL mailing list
#SDL at libsdl.org
#http://www.libsdl.org/mailman/listinfo/sdl

Jeff Schiller wrote:

Once I’ve init’ed SDL, I can enumerate the available display modes, but
is there a way to get the CURRENT display mode (without having set it
myself) from within SDL? I would rather go down this road than use
native OS calls.
no but SDL helps
i currently have implemented it for win and linux/X

works like this:
(based on a example somewhere on the libsdl.org
and a post by
Stephan Ferraro
http://www.libsdl.org/pipermail/sdl/2003-December/058783.html

#include <SDL_syswm.h>

// Determine type of window manager we are probably using
#if defined(unix)
#define WM_X11
#elif defined(WIN32)
#define WM_WIN
#else
#error Unknown window manager for default desktop resolution handling
#endif

[…]

// try to use current resolution
SDL_SysWMinfo         info;

SDL_VERSION(&info.version);

if (SDL_GetWMInfo(&info)) {

#if defined(WM_X11)
if ( info.subsystem == SDL_SYSWM_X11 ) {
width = DisplayWidth(info.info.x11.display, 0);
height = DisplayHeight(info.info.x11.display, 0);
}else{
JGACHINE_WARN(“using unknown subsystem:”<<info.subsystem);
}
#elif defined (WM_WIN)
width=GetSystemMetrics(SM_CXSCREEN);
height=GetSystemMetrics(SM_CYSCREEN);
#else
#error implement it
#endif
}else
JGACHINE_WARN(“could not get window manager information”);
}

createWindow(width,height);

greetings karme

PS: the full code though a bit ugly is here:
http://cvs.berlios.de/cgi-bin/viewcvs.cgi/egachine/egachine/src/client/video/sdlopengl/video.cpp?rev=HEAD&content-type=text/vnd.viewcvs-markup

PPS: the homepage of the project i am working on:
http://egachine.berlios.de :wink:

What I’m after is SDL code that can give me the screen dimensions and pixel
format prior to having set the video mode via SDL. I feel this is a very
useful piece to put into SDL because most applications at least need to know
the size of the screen so that the window they create is not too large.
This is also useful for correctly sized splash screens.

If anyone can think of a good way to add this functionality into
SDL_GetVideoInfo() I think it makes sense there, i.e. add the following
items to the SDL_VideoInfo struct?

typedef struct{
Uint32 hw_available;
/* … others … */
SDL_PixelFormat vfmt; / Best pixel format if called before
SDL_SetVideoMode or current video mode */

/* Proposed new fields /
Uint8 current_screen_width; /
Actual screen width in pixels, regardless
of whether SDL_SetVideoMode has been called */

Uint8 current_screen_height; /* Actual screen height in pixels, regardless
of whether SDL_SetVideoMode has been called */

SDL_PixelFormat* actual_vfmt; /* Current Video mode, regardless of whether
SDL_SetVideoMode has been called */

} SDL_VideoInfo;

If people don’t like that because of the overlap between vfmt and
actual_vfmt, then I propose a couple new functions:

SDL_PixelFormat* SDL_GetCurrentPixelFormat();

  • if SetVideoMode has been called, returns SDL_GetVideoSurface()->format
  • if SetVideoMode has not yet been called, returns the current pixel format

SDL_Rect* SDL_GetCurrentMode();

  • if SetVideoMode has been called, returns (0, 0, SDL_GetVideoSurface()->w,
    SDL_GetVideoSurface()->h)
  • if SetVideoMode has not yet been called, returns the screen dimensions

Any comments/suggestions?

Thanks,
Jeff Schiller_________________________________________________________________
Stop worrying about overloading your inbox - get MSN Hotmail Extra Storage!
http://join.msn.com/?pgmarket=en-us&page=hotmail/es2&ST=1/go/onm00200362ave/direct/01/

What I’m after is SDL code that can give me the screen dimensions and pixel
format prior to having set the video mode via SDL. I feel this is a very
useful piece to put into SDL because most applications at least need to know
the size of the screen so that the window they create is not too large.
This is also useful for correctly sized splash screens.

Is there a reason why you can’t use SDL_ListModes() to get the
information you want?

		Bob PendletonOn Sat, 2004-04-24 at 15:51, Jeff Schiller wrote:

If anyone can think of a good way to add this functionality into
SDL_GetVideoInfo() I think it makes sense there, i.e. add the following
items to the SDL_VideoInfo struct?

typedef struct{
Uint32 hw_available;
/* … others … */
SDL_PixelFormat vfmt; / Best pixel format if called before
SDL_SetVideoMode or current video mode */

/* Proposed new fields /
Uint8 current_screen_width; /
Actual screen width in pixels, regardless
of whether SDL_SetVideoMode has been called */

Uint8 current_screen_height; /* Actual screen height in pixels, regardless
of whether SDL_SetVideoMode has been called */

SDL_PixelFormat* actual_vfmt; /* Current Video mode, regardless of whether
SDL_SetVideoMode has been called */

} SDL_VideoInfo;

If people don’t like that because of the overlap between vfmt and
actual_vfmt, then I propose a couple new functions:

SDL_PixelFormat* SDL_GetCurrentPixelFormat();

  • if SetVideoMode has been called, returns SDL_GetVideoSurface()->format
  • if SetVideoMode has not yet been called, returns the current pixel format

SDL_Rect* SDL_GetCurrentMode();

  • if SetVideoMode has been called, returns (0, 0, SDL_GetVideoSurface()->w,
    SDL_GetVideoSurface()->h)
  • if SetVideoMode has not yet been called, returns the screen dimensions

Any comments/suggestions?

Thanks,
Jeff Schiller


Stop worrying about overloading your inbox - get MSN Hotmail Extra Storage!
http://join.msn.com/?pgmarket=en-us&page=hotmail/es2&ST=1/go/onm00200362ave/direct/01/


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

±--------------------------------------+