Commit e88f3165 authored by Sam Lantinga's avatar Sam Lantinga

Fixed setting OpenGL mode multiple times on Windows

--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%40374
parent e9af4165
...@@ -16,6 +16,7 @@ be found at the <A HREF="http://www.libsdl.org/"> main SDL page</A>. ...@@ -16,6 +16,7 @@ be found at the <A HREF="http://www.libsdl.org/"> main SDL page</A>.
Major changes since SDL 1.0.0: Major changes since SDL 1.0.0:
</H2> </H2>
<UL> <UL>
<LI> 1.2.5: Fixed setting OpenGL mode multiple times on Windows
<LI> 1.2.5: Added support for Qtopia on embedded systems (thanks David!) <LI> 1.2.5: Added support for Qtopia on embedded systems (thanks David!)
<LI> 1.2.4: Added initial support for Atari (thanks Patrice!) <LI> 1.2.4: Added initial support for Atari (thanks Patrice!)
<LI> 1.2.4: Added support for building SDL for EPOC/SymbianOS 6.0 <LI> 1.2.4: Added support for building SDL for EPOC/SymbianOS 6.0
......
...@@ -36,11 +36,50 @@ static char rcsid = ...@@ -36,11 +36,50 @@ static char rcsid =
#define DEFAULT_GL_DRIVER_PATH "OPENGL32.DLL" #define DEFAULT_GL_DRIVER_PATH "OPENGL32.DLL"
#endif #endif
/* If setting the HDC fails, we may need to recreate the window (MSDN) */
static int WIN_GL_ResetWindow(_THIS)
{
int status = 0;
int can_reset = 1;
/* If we were passed a window, then we can't create a new one */
if ( SDL_windowid ) {
can_reset = 0;
}
#ifndef _WIN32_WCE /* FIXME WinCE needs the UNICODE version of CreateWindow() */
if ( can_reset ) {
/* Save the existing window attributes */
LONG style;
RECT rect = { 0, 0, 0, 0 };
style = GetWindowLong(SDL_Window, GWL_STYLE);
GetWindowRect(SDL_Window, &rect);
DestroyWindow(SDL_Window);
SDL_Window = CreateWindow(SDL_Appname, SDL_Appname,
style,
rect.left, rect.top,
(rect.right-rect.left)+1,
(rect.top-rect.bottom)+1,
NULL, NULL, SDL_Instance, NULL);
if ( SDL_Window ) {
this->SetCaption(this, this->wm_title, this->wm_icon);
} else {
SDL_SetError("Couldn't create window");
status = -1;
}
} else
#endif /* !_WIN32_WCE */
{
SDL_SetError("Unable to reset window for OpenGL context");
status = -1;
}
return(status);
}
int WIN_GL_SetupWindow(_THIS) int WIN_GL_SetupWindow(_THIS)
{ {
int retval; int retval;
#ifdef HAVE_OPENGL #ifdef HAVE_OPENGL
int i;
int pixel_format; int pixel_format;
/* load the gl driver from a default path */ /* load the gl driver from a default path */
...@@ -51,6 +90,7 @@ int WIN_GL_SetupWindow(_THIS) ...@@ -51,6 +90,7 @@ int WIN_GL_SetupWindow(_THIS)
} }
} }
for ( i=0; ; ++i ) {
/* Get the window device context for our OpenGL drawing */ /* Get the window device context for our OpenGL drawing */
GL_hdc = GetDC(SDL_Window); GL_hdc = GetDC(SDL_Window);
if ( GL_hdc == NULL ) { if ( GL_hdc == NULL ) {
...@@ -89,9 +129,19 @@ int WIN_GL_SetupWindow(_THIS) ...@@ -89,9 +129,19 @@ int WIN_GL_SetupWindow(_THIS)
return(-1); return(-1);
} }
if( !SetPixelFormat(GL_hdc, pixel_format, &GL_pfd) ) { if( !SetPixelFormat(GL_hdc, pixel_format, &GL_pfd) ) {
if ( i == 0 ) {
/* First time through, try resetting the window */
if ( WIN_GL_ResetWindow(this) < 0 ) {
return(-1);
}
continue;
}
SDL_SetError("Unable to set HDC pixel format"); SDL_SetError("Unable to set HDC pixel format");
return(-1); return(-1);
} }
/* We either succeeded or failed by this point */
break;
}
DescribePixelFormat(GL_hdc, pixel_format, sizeof(GL_pfd), &GL_pfd); DescribePixelFormat(GL_hdc, pixel_format, sizeof(GL_pfd), &GL_pfd);
GL_hrc = this->gl_data->wglCreateContext(GL_hdc); GL_hrc = this->gl_data->wglCreateContext(GL_hdc);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment