[SDL] Beginner question: can't enter to fullscreen mode

Ferran Ferri ferranferri at yahoo.es
Mon Jun 27 09:49:50 PDT 2005


Well, well. I'm new in this list, and I'm so surprised by the activity
of the list and the skill in general.

The code now works fine!!!

The new procedure to go to fullscreen mode is:
========================================================================
==
bool CGameEngine::reinitGraphicContext(int width, int height, int
colorDepth, bool fullScreen)
{
	//To use OpenGL, you need to get some information first,
	const SDL_VideoInfo *info = SDL_GetVideoInfo();
	
	if(!info) {
		/* This should never happen, if it does PANIC! */
		fprintf(stderr, "Video query failed: %s\n",
SDL_GetError());
	    return false;
	}

	int bpp = info->vfmt->BitsPerPixel;

	/* the flags to pass to SDL_SetVideoMode */
    m_nVideoFlags  = SDL_OPENGL;          /* Enable OpenGL in SDL */
    m_nVideoFlags |= SDL_HWPALETTE;       /* Store the palette in
hardware */
    m_nVideoFlags |= SDL_RESIZABLE;       /* Enable window resizing */

    /* This checks to see if surfaces can be stored in memory */
    if ( info->hw_available )
	m_nVideoFlags |= SDL_HWSURFACE;
    else
	m_nVideoFlags |= SDL_SWSURFACE;
	
	/* enable full scren ? */
	if (fullScreen)
		m_nVideoFlags |= SDL_FULLSCREEN;

    
	// set bits for red: (5 = 5bits for red channel)
    SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5);
	// set bits for green:
    SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 5);
	// set bits for blue:
    SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5);
	// colour depth:
    SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
	// You want it double buffered?
    SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, true);

	//screen is no longer used, as openGL does all the drawing now!
	if (SDL_SetVideoMode(width, height, bpp, m_nVideoFlags) == 0) {
		fprintf(stderr, "Unable to set video mode: %s\n",
SDL_GetError());
		return false;
	}
	return true;
}

========================================================================
==== 

And when I call this function I call also to initGL and resizeGL to
adjust the values.

About the mistaken code and our mistaken flags, is in part the port to
SDL of the nehe.gamedev.net tutorials. 

Thanks for all

Ferran Ferri Perez
Software Engineer

RedSauce S.L.
 

-----Mensaje original-----
De: sdl-bounces+ferranferri=yahoo.es at libsdl.org
[mailto:sdl-bounces+ferranferri=yahoo.es at libsdl.org] En nombre de Petri
Latvala
Enviado el: lunes, 27 de junio de 2005 1:15
Para: sdl at libsdl.org
Asunto: Re: [SDL] Beginner question: can't enter to fullscreen mode

On Sun, Jun 26, 2005 at 11:50:13PM +0200, Ferran Ferri  wrote:
> ===================================================================
> 
> the procedure to enter to the full screen mode is:
> 
> void CGameEngine::toggleToFullScreenMode()
> {
> 		if (SDL_WM_ToggleFullScreen(m_mainScreen) == 0){
> 			printf("Unable to go to full sreen: %s
> \n",SDL_GetError());
> 		}
> }
> 
> And the project is a console project. Some ideas? 

SDL_WM_ToggleFullscreen is a glorious example of a misdesign. It
cannot be implemented anywhere except on X11. And I hear BeOS might
have it too. In any case, Win32 doesn't have it, it does nothing
there.

The correct and always working way to switch to fullscreen is to call
SDL_SetVideoMode again with SDL_FULLSCREEN in the flags. It will
destroy the OpenGL context, though, so you have to reload textures and
display lists.

And then an unrelated issue:


> Hi all, I'm programming with MSVC++ 7.1 (a.k.a VC++.NET). I created a
> SDL project with and I can't enter in full screen mode. When I
configure
> the video mode I give the following flags to the SDL:
> 
> /* the flags to pass to SDL_SetVideoMode */
>     m_nVideoFlags  = SDL_OPENGL;          /* Enable OpenGL in SDL */
>     m_nVideoFlags |= SDL_GL_DOUBLEBUFFER; /* Enable double buffering
*/
>     m_nVideoFlags |= SDL_HWPALETTE;       /* Store the palette in
> hardware */
>     m_nVideoFlags |= SDL_RESIZABLE;       /* Enable window resizing */
> 
>     /* This checks to see if surfaces can be stored in memory */
>     if ( info->hw_available )
> 	m_nVideoFlags |= SDL_HWSURFACE;
>     else
> 	m_nVideoFlags |= SDL_SWSURFACE;
> 
>     /* This checks if hardware blits can be done */
>     if ( info->blit_hw )
> 	m_nVideoFlags |= SDL_HWACCEL;

This is a common error and I've been hunting down the source for
this. In short: THE FLAGS ARE WRONG! Where did you get this code?

1) SDL_GL_DOUBLEBUFFER

Double buffering for OpenGL is set up with the call to

 SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1)

before calling SDL_SetVideoMode. SDL_GL_DOUBLEBUFFER as a flag to
SDL_SetVideoMode is wrong. And it does "bad things" too: The value of
SDL_GL_DOUBLEBUFFER is 5, that is, 0x05 = 0x01 + 0x04 = SDL_HWSURFACE
+ SDL_ASYNCBLIT.

2) SDL_OPENGL is special

A surface can in effect be one of three modes: SDL_SWSURFACE,
SDL_HWSURFACE or SDL_OPENGL. When using OpenGL, a lot of SDL
functionality for graphics make no sense. This means SDL_HWSURFACE and
SDL_SWSURFACE are meaningless, and so is SDL_HWPALETTE.

3) SDL_HWACCEL is plain wrong

This isn't a flag you can give to SDL_SetVideoMode: See
SDL_SetVideoMode docs at
http://www.libsdl.org/cgi/docwiki.cgi/SDL_5fSetVideoMode

SDL_HWACCEL does _not_ mean hardware-accelerated OpenGL, which is a
common interpretation. From your comments in the code I see you don't
think that, but they hint at another possible error. Blits? You can't
blit (SDL_BlitSurface) when using OpenGL.

SDL_HWACCEL is a read-only _internal_ flag on created surfaces that
SDL uses itself to determine whether blits are hardware accelerated.

"Fortunately" this flag should do nothing when given to
SDL_SetVideoMode, as it doesn't overlap with any values.


-- 
Petri Latvala


		
______________________________________________ 
Renovamos el Correo Yahoo! 
Nuevos servicios, más seguridad 
http://correo.yahoo.es





More information about the SDL mailing list