Skip to content
This repository has been archived by the owner. It is now read-only.
Browse files

Workaround some Windows OpenGL drivers mishandling wglMakeCurrent().

You should be able to do wglMakeCurrent(NULL, NULL), according to MSDN, since
the first parameter is ignored if the second is NULL, but this causes problems
on some drivers, so make sure we always have a valid HDC in the first
parameter (and exit early if we already have no current context in the
NULL, NULL case).
  • Loading branch information
icculus committed Jul 31, 2013
1 parent ce3a539 commit 7e681bd491c6acaee5e6ab04f5119bce6a32fef8
Showing with 17 additions and 5 deletions.
  1. +17 −5 src/video/windows/SDL_windowsopengl.c
@@ -22,6 +22,7 @@


#include "SDL_assert.h"
#include "SDL_windowsvideo.h"

/* WGL implementation of SDL OpenGL support */
@@ -407,7 +408,7 @@ WIN_GL_ChoosePixelFormatARB(_THIS, int *iAttribs, float *fAttribs)

_this->gl_data->wglMakeCurrent(NULL, NULL);
_this->gl_data->wglMakeCurrent(hdc, NULL);
ReleaseDC(hwnd, hdc);
@@ -622,11 +623,22 @@ WIN_GL_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context)
return SDL_SetError("OpenGL not initialized");

if (window) {
hdc = ((SDL_WindowData *) window->driverdata)->hdc;
} else {
hdc = NULL;
/* sanity check that higher level handled this. */
SDL_assert(window || (!window && !context));

/* Some Windows drivers freak out if hdc is NULL, even when context is
NULL, against spec. Since hdc is _supposed_ to be ignored if context
is NULL, we either use the current GL window, or do nothing if we
already have no current context. */
if (!window) {
window = SDL_GL_GetCurrentWindow();
if (!window) {
SDL_assert(SDL_GL_GetCurrentContext() == NULL);
return 0; /* already done. */

hdc = ((SDL_WindowData *) window->driverdata)->hdc;
if (!_this->gl_data->wglMakeCurrent(hdc, (HGLRC) context)) {
return WIN_SetError("wglMakeCurrent()");

0 comments on commit 7e681bd

Please sign in to comment.