Beginner question: can't enter to fullscreen mode

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;===================================================================

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?

Thanks to all.

Ferran Ferri Perez
Software Engineer

RedSauce S.L.


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

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

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.
  1. 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.

  1. 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.On Sun, Jun 26, 2005 at 11:50:13PM +0200, Ferran Ferri wrote:


Petri Latvala
-------------- next part --------------
A non-text attachment was scrubbed…
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20050627/072a216f/attachment.pgp

Ferran Ferri wrote:

void CGameEngine::toggleToFullScreenMode()
{
if (SDL_WM_ToggleFullScreen(m_mainScreen) == 0){
printf(“Unable to go to full sreen: %s
\n”,SDL_GetError());
}
}

SDL_WM_ToggleFullScreen only works in X11. Not in windows.
You have to use SDL_SetVideoMode again with the SDL_FULLSCREEN flag set.

Going off-topic for a moment,

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.

Under what circumstances will the OGL context be destroyed? Always? I
have a perfectly working (as far as I can tell… :-)) piece of code that
will:

  1. Set video mode,
  2. Reset and recalculate viewport & perspective,
    and nothing else. I can call this as many times as I like, yet my OGL
    context seems fine (tested only on Linux/X11). Perhaps this is platform
    dependant?

Thanks,
– Aaron

Sorry, I should have included this info: This happens only on Win32.On Mon, Jun 27, 2005 at 10:27:21AM +1000, Aaron C. wrote:

Going off-topic for a moment,

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.

Under what circumstances will the OGL context be destroyed? Always? I
have a perfectly working (as far as I can tell… :-)) piece of code that
will:

  1. Set video mode,
  2. Reset and recalculate viewport & perspective,
    and nothing else. I can call this as many times as I like, yet my OGL
    context seems fine (tested only on Linux/X11). Perhaps this is platform
    dependant?


Petri Latvala
-------------- next part --------------
A non-text attachment was scrubbed…
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20050627/c2f822c4/attachment.pgp

Under Windows you always lose the context whenever you change
resolutions and/or switch between window and fullscreen. This is a
well-known limitation of WGL. Under X11 (and OS X ??) this is never a
problem. Basically the real portable way of dealing with that is to
just go ahead and recreate the whole damn context every time you mess
up with the display.

It would be nice if SDL could let the app know when the context is
lost, but so far it’s not possible. There has been lots of talk about
this lately. Check the archives.On 6/26/05, Aaron C. wrote:

Going off-topic for a moment,

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.

Under what circumstances will the OGL context be destroyed? Always? I
have a perfectly working (as far as I can tell… :-)) piece of code that
will:

  1. Set video mode,
  2. Reset and recalculate viewport & perspective,
    and nothing else. I can call this as many times as I like, yet my OGL
    context seems fine (tested only on Linux/X11). Perhaps this is platform
    dependant?

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.
  1. 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.

  1. 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