[SDL] Window/surface dimensions mismatch problem

Daniel Phillips phillips at arcor.de
Sun Jan 12 19:44:01 PST 2003

On Monday 13 January 2003 04:15, Glenn Maynard wrote:
> On Mon, Jan 13, 2003 at 03:59:15AM +0100, Daniel Phillips wrote:
> > An SDL app with a resizable window doesn't play nicely with this KDE
> > feature, in that it will go ahead and create the surface at the size it
> > thinks is right.  This may not be the size of the window that the window
> > manager actually created, which results in a nasty mismatch that doesn't
> > go away until a window resize event is received, probably generated by an
> > irritated user.
> SDL_SetVideoMode returns an SDL_Surface; the height and width values in
> it should be the real dimensions of the window, which might be different
> than requested.  Are they being set?  Use them instead of the values you
> gave to SDL.

I'm glad to here it's supposed to work that way.  Unfortunately, it doesn't.
Here's my code:

errcode set_videosize(unsigned  xpix, unsigned ypix, unsigned flags)
	const SDL_VideoInfo *video;
	SDL_Surface *surface;

	if (!(video = SDL_GetVideoInfo())) return -1; // ??? need this or SetVideoMode doesn't work
	surface = SDL_SetVideoMode(xpix, ypix, video->vfmt->BitsPerPixel, flags);
	if (!(video = SDL_GetVideoInfo())) return -2;

	xpix = surface->w;
	ypix = surface->h;
	glViewport(0, 0, xpix, ypix);

I'd expect xpix and ypix to be updated to the actual window size, but this
does not happen.  Now that I know it's supposed to, I can investigate why.

> Aside:
> Be careful not to actually change what you request.  One bug I
> encountered was that I was overwriting the "desired" resolution/dimensions
> with those returned by SDL_SetVideoMode.  With my 1024x768 screen, I
> often get screens around 1024x760 in a window, since SDL makes it a
> little smaller in Windows (to keep the titlebar on screen), then when
> switching to fullscreen I was asking for 1024x760, which failed, of
> course.  Oops.

I use the fullscreen dimensions as returned by SDL_ListModes.  In that case,
the non-fullscreen dimensions need to be remembered, as this isn't just a
toggle any more.  On that note, it seems to me that SDL_ToggleFullscreen has
got a pretty big disconnect in that it tries to use the windowed dimensions
of the surface in fullscreen mode.

> > What to do about this?  I don't know, this seems a little messy, and I'm
> > not prepared to make a concrete suggestion or offer a patch at this
> > point.  Have I missed something obvious?
> Check the above.  If the values returned in the SDL_Surface aren't the
> actual active window dimensions, there's probably a bug somewhere.

They aren't, and yup, it smells like a bug.  I'm glad it's that and not a
design problem.



More information about the SDL mailing list