annotate src/video/wincommon/SDL_wingl.c @ 566:d6e7d7006062

Enable the glXGetProcAddressARB code (fixes problems with NVidia drivers)
author Sam Lantinga <slouken@libsdl.org>
date Mon, 20 Jan 2003 00:25:28 +0000
parents a6fa62b1be09
children 9c42ee1b7d77
rev   line source
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1 /*
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2 SDL - Simple DirectMedia Layer
297
f6ffac90895c Updated copyright information for 2002
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
3 Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002 Sam Lantinga
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
4
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
5 This library is free software; you can redistribute it and/or
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
6 modify it under the terms of the GNU Library General Public
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
7 License as published by the Free Software Foundation; either
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
8 version 2 of the License, or (at your option) any later version.
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
9
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
10 This library is distributed in the hope that it will be useful,
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
13 Library General Public License for more details.
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
14
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
15 You should have received a copy of the GNU Library General Public
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
16 License along with this library; if not, write to the Free
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
18
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
19 Sam Lantinga
252
e8157fcb3114 Updated the source with the correct e-mail address
Sam Lantinga <slouken@libsdl.org>
parents: 0
diff changeset
20 slouken@libsdl.org
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
21 */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
22
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
23 #ifdef SAVE_RCSID
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
24 static char rcsid =
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
25 "@(#) $Id$";
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
26 #endif
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
27
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
28 /* WGL implementation of SDL OpenGL support */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
29
453
a6fa62b1be09 Updated for embedded Visual C++ 4.0
Sam Lantinga <slouken@libsdl.org>
parents: 450
diff changeset
30 #ifdef HAVE_OPENGL
327
13fc64213765 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
31 #include "SDL_opengl.h"
453
a6fa62b1be09 Updated for embedded Visual C++ 4.0
Sam Lantinga <slouken@libsdl.org>
parents: 450
diff changeset
32 #endif
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
33 #include "SDL_error.h"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
34 #include "SDL_lowvideo.h"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
35 #include "SDL_wingl_c.h"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
36
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
37 #ifdef HAVE_OPENGL
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
38 #define DEFAULT_GL_DRIVER_PATH "OPENGL32.DLL"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
39 #endif
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
40
373
c638fde8a824 Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 327
diff changeset
41 /* If setting the HDC fails, we may need to recreate the window (MSDN) */
c638fde8a824 Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 327
diff changeset
42 static int WIN_GL_ResetWindow(_THIS)
c638fde8a824 Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 327
diff changeset
43 {
c638fde8a824 Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 327
diff changeset
44 int status = 0;
c638fde8a824 Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 327
diff changeset
45 int can_reset = 1;
c638fde8a824 Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 327
diff changeset
46
c638fde8a824 Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 327
diff changeset
47 /* If we were passed a window, then we can't create a new one */
c638fde8a824 Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 327
diff changeset
48 if ( SDL_windowid ) {
c638fde8a824 Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 327
diff changeset
49 can_reset = 0;
c638fde8a824 Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 327
diff changeset
50 }
c638fde8a824 Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 327
diff changeset
51 #ifndef _WIN32_WCE /* FIXME WinCE needs the UNICODE version of CreateWindow() */
c638fde8a824 Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 327
diff changeset
52 if ( can_reset ) {
c638fde8a824 Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 327
diff changeset
53 /* Save the existing window attributes */
c638fde8a824 Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 327
diff changeset
54 LONG style;
c638fde8a824 Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 327
diff changeset
55 RECT rect = { 0, 0, 0, 0 };
c638fde8a824 Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 327
diff changeset
56 style = GetWindowLong(SDL_Window, GWL_STYLE);
c638fde8a824 Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 327
diff changeset
57 GetWindowRect(SDL_Window, &rect);
c638fde8a824 Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 327
diff changeset
58 DestroyWindow(SDL_Window);
c638fde8a824 Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 327
diff changeset
59 SDL_Window = CreateWindow(SDL_Appname, SDL_Appname,
c638fde8a824 Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 327
diff changeset
60 style,
c638fde8a824 Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 327
diff changeset
61 rect.left, rect.top,
c638fde8a824 Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 327
diff changeset
62 (rect.right-rect.left)+1,
c638fde8a824 Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 327
diff changeset
63 (rect.top-rect.bottom)+1,
c638fde8a824 Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 327
diff changeset
64 NULL, NULL, SDL_Instance, NULL);
c638fde8a824 Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 327
diff changeset
65 if ( SDL_Window ) {
c638fde8a824 Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 327
diff changeset
66 this->SetCaption(this, this->wm_title, this->wm_icon);
c638fde8a824 Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 327
diff changeset
67 } else {
c638fde8a824 Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 327
diff changeset
68 SDL_SetError("Couldn't create window");
c638fde8a824 Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 327
diff changeset
69 status = -1;
c638fde8a824 Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 327
diff changeset
70 }
c638fde8a824 Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 327
diff changeset
71 } else
c638fde8a824 Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 327
diff changeset
72 #endif /* !_WIN32_WCE */
c638fde8a824 Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 327
diff changeset
73 {
c638fde8a824 Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 327
diff changeset
74 SDL_SetError("Unable to reset window for OpenGL context");
c638fde8a824 Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 327
diff changeset
75 status = -1;
c638fde8a824 Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 327
diff changeset
76 }
c638fde8a824 Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 327
diff changeset
77 return(status);
c638fde8a824 Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 327
diff changeset
78 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
79
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
80 int WIN_GL_SetupWindow(_THIS)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
81 {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
82 int retval;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
83 #ifdef HAVE_OPENGL
373
c638fde8a824 Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 327
diff changeset
84 int i;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
85 int pixel_format;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
86
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
87 /* load the gl driver from a default path */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
88 if ( ! this->gl_config.driver_loaded ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
89 /* no driver has been loaded, use default (ourselves) */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
90 if ( WIN_GL_LoadLibrary(this, NULL) < 0 ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
91 return(-1);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
92 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
93 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
94
373
c638fde8a824 Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 327
diff changeset
95 for ( i=0; ; ++i ) {
c638fde8a824 Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 327
diff changeset
96 /* Get the window device context for our OpenGL drawing */
c638fde8a824 Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 327
diff changeset
97 GL_hdc = GetDC(SDL_Window);
c638fde8a824 Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 327
diff changeset
98 if ( GL_hdc == NULL ) {
c638fde8a824 Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 327
diff changeset
99 SDL_SetError("Unable to get DC for SDL_Window");
c638fde8a824 Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 327
diff changeset
100 return(-1);
c638fde8a824 Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 327
diff changeset
101 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
102
373
c638fde8a824 Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 327
diff changeset
103 /* Set up the pixel format descriptor with our needed format */
c638fde8a824 Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 327
diff changeset
104 memset(&GL_pfd, 0, sizeof(GL_pfd));
c638fde8a824 Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 327
diff changeset
105 GL_pfd.nSize = sizeof(GL_pfd);
c638fde8a824 Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 327
diff changeset
106 GL_pfd.nVersion = 1;
c638fde8a824 Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 327
diff changeset
107 GL_pfd.dwFlags = (PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL);
c638fde8a824 Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 327
diff changeset
108 if ( this->gl_config.double_buffer ) {
c638fde8a824 Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 327
diff changeset
109 GL_pfd.dwFlags |= PFD_DOUBLEBUFFER;
c638fde8a824 Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 327
diff changeset
110 }
450
8a43e0cbf02f Added SDL_GL_STEREO for stereoscopic OpenGL contexts
Sam Lantinga <slouken@libsdl.org>
parents: 373
diff changeset
111 if ( this->gl_config.stereo ) {
8a43e0cbf02f Added SDL_GL_STEREO for stereoscopic OpenGL contexts
Sam Lantinga <slouken@libsdl.org>
parents: 373
diff changeset
112 GL_pfd.dwFlags |= PFD_STEREO;
8a43e0cbf02f Added SDL_GL_STEREO for stereoscopic OpenGL contexts
Sam Lantinga <slouken@libsdl.org>
parents: 373
diff changeset
113 }
373
c638fde8a824 Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 327
diff changeset
114 GL_pfd.iPixelType = PFD_TYPE_RGBA;
c638fde8a824 Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 327
diff changeset
115 GL_pfd.cColorBits = this->gl_config.buffer_size;
c638fde8a824 Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 327
diff changeset
116 GL_pfd.cRedBits = this->gl_config.red_size;
c638fde8a824 Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 327
diff changeset
117 GL_pfd.cGreenBits = this->gl_config.green_size;
c638fde8a824 Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 327
diff changeset
118 GL_pfd.cBlueBits = this->gl_config.blue_size;
c638fde8a824 Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 327
diff changeset
119 GL_pfd.cAlphaBits = this->gl_config.alpha_size;
c638fde8a824 Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 327
diff changeset
120 GL_pfd.cAccumRedBits = this->gl_config.accum_red_size;
c638fde8a824 Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 327
diff changeset
121 GL_pfd.cAccumGreenBits = this->gl_config.accum_green_size;
c638fde8a824 Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 327
diff changeset
122 GL_pfd.cAccumBlueBits = this->gl_config.accum_blue_size;
c638fde8a824 Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 327
diff changeset
123 GL_pfd.cAccumAlphaBits = this->gl_config.accum_alpha_size;
c638fde8a824 Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 327
diff changeset
124 GL_pfd.cAccumBits =
c638fde8a824 Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 327
diff changeset
125 (GL_pfd.cAccumRedBits + GL_pfd.cAccumGreenBits +
c638fde8a824 Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 327
diff changeset
126 GL_pfd.cAccumBlueBits + GL_pfd.cAccumAlphaBits);
c638fde8a824 Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 327
diff changeset
127 GL_pfd.cDepthBits = this->gl_config.depth_size;
c638fde8a824 Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 327
diff changeset
128 GL_pfd.cStencilBits = this->gl_config.stencil_size;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
129
373
c638fde8a824 Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 327
diff changeset
130 /* Choose and set the closest available pixel format */
c638fde8a824 Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 327
diff changeset
131 pixel_format = ChoosePixelFormat(GL_hdc, &GL_pfd);
c638fde8a824 Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 327
diff changeset
132 if ( !pixel_format ) {
c638fde8a824 Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 327
diff changeset
133 SDL_SetError("No matching GL pixel format available");
c638fde8a824 Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 327
diff changeset
134 return(-1);
c638fde8a824 Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 327
diff changeset
135 }
c638fde8a824 Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 327
diff changeset
136 if( !SetPixelFormat(GL_hdc, pixel_format, &GL_pfd) ) {
c638fde8a824 Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 327
diff changeset
137 if ( i == 0 ) {
c638fde8a824 Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 327
diff changeset
138 /* First time through, try resetting the window */
c638fde8a824 Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 327
diff changeset
139 if ( WIN_GL_ResetWindow(this) < 0 ) {
c638fde8a824 Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 327
diff changeset
140 return(-1);
c638fde8a824 Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 327
diff changeset
141 }
c638fde8a824 Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 327
diff changeset
142 continue;
c638fde8a824 Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 327
diff changeset
143 }
c638fde8a824 Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 327
diff changeset
144 SDL_SetError("Unable to set HDC pixel format");
c638fde8a824 Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 327
diff changeset
145 return(-1);
c638fde8a824 Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 327
diff changeset
146 }
c638fde8a824 Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 327
diff changeset
147 /* We either succeeded or failed by this point */
c638fde8a824 Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 327
diff changeset
148 break;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
149 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
150 DescribePixelFormat(GL_hdc, pixel_format, sizeof(GL_pfd), &GL_pfd);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
151
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
152 GL_hrc = this->gl_data->wglCreateContext(GL_hdc);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
153 if( GL_hrc == NULL ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
154 SDL_SetError("Unable to create GL context");
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
155 return(-1);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
156 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
157 gl_active = 1;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
158 #else
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
159 SDL_SetError("WIN driver not configured with OpenGL");
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
160 #endif
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
161 if ( gl_active ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
162 retval = 0;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
163 } else {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
164 retval = -1;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
165 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
166 return(retval);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
167 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
168
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
169 void WIN_GL_ShutDown(_THIS)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
170 {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
171 #ifdef HAVE_OPENGL
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
172 /* Clean up OpenGL */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
173 if ( GL_hrc ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
174 this->gl_data->wglMakeCurrent(NULL, NULL);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
175 this->gl_data->wglDeleteContext(GL_hrc);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
176 GL_hrc = NULL;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
177 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
178 if ( GL_hdc ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
179 ReleaseDC(SDL_Window, GL_hdc);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
180 GL_hdc = NULL;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
181 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
182 gl_active = 0;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
183
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
184 WIN_GL_UnloadLibrary(this);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
185 #endif /* HAVE_OPENGL */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
186 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
187
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
188 #ifdef HAVE_OPENGL
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
189
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
190 /* Make the current context active */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
191 int WIN_GL_MakeCurrent(_THIS)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
192 {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
193 int retval;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
194
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
195 retval = 0;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
196 if ( ! this->gl_data->wglMakeCurrent(GL_hdc, GL_hrc) ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
197 SDL_SetError("Unable to make GL context current");
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
198 retval = -1;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
199 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
200 return(retval);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
201 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
202
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
203 /* Get attribute data from glX. */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
204 int WIN_GL_GetAttribute(_THIS, SDL_GLattr attrib, int* value)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
205 {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
206 int retval;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
207
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
208 retval = 0;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
209 switch( attrib ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
210 case SDL_GL_RED_SIZE:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
211 *value = GL_pfd.cRedBits;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
212 break;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
213 case SDL_GL_GREEN_SIZE:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
214 *value = GL_pfd.cGreenBits;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
215 break;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
216 case SDL_GL_BLUE_SIZE:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
217 *value = GL_pfd.cBlueBits;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
218 break;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
219 case SDL_GL_ALPHA_SIZE:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
220 *value = GL_pfd.cAlphaBits;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
221 break;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
222 case SDL_GL_DOUBLEBUFFER:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
223 if ( GL_pfd.dwFlags & PFD_DOUBLEBUFFER ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
224 *value = 1;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
225 } else {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
226 *value = 0;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
227 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
228 break;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
229 case SDL_GL_BUFFER_SIZE:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
230 *value = GL_pfd.cColorBits;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
231 break;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
232 case SDL_GL_DEPTH_SIZE:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
233 *value = GL_pfd.cDepthBits;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
234 break;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
235 case SDL_GL_STENCIL_SIZE:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
236 *value = GL_pfd.cStencilBits;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
237 break;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
238 case SDL_GL_ACCUM_RED_SIZE:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
239 *value = GL_pfd.cAccumRedBits;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
240 break;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
241 case SDL_GL_ACCUM_GREEN_SIZE:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
242 *value = GL_pfd.cAccumGreenBits;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
243 break;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
244 case SDL_GL_ACCUM_BLUE_SIZE:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
245 *value = GL_pfd.cAccumBlueBits;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
246 break;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
247 case SDL_GL_ACCUM_ALPHA_SIZE:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
248 *value = GL_pfd.cAccumAlphaBits;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
249 break;
450
8a43e0cbf02f Added SDL_GL_STEREO for stereoscopic OpenGL contexts
Sam Lantinga <slouken@libsdl.org>
parents: 373
diff changeset
250 case SDL_GL_STEREO:
8a43e0cbf02f Added SDL_GL_STEREO for stereoscopic OpenGL contexts
Sam Lantinga <slouken@libsdl.org>
parents: 373
diff changeset
251 if ( GL_pfd.dwFlags & PFD_STEREO ) {
8a43e0cbf02f Added SDL_GL_STEREO for stereoscopic OpenGL contexts
Sam Lantinga <slouken@libsdl.org>
parents: 373
diff changeset
252 *value = 1;
8a43e0cbf02f Added SDL_GL_STEREO for stereoscopic OpenGL contexts
Sam Lantinga <slouken@libsdl.org>
parents: 373
diff changeset
253 } else {
8a43e0cbf02f Added SDL_GL_STEREO for stereoscopic OpenGL contexts
Sam Lantinga <slouken@libsdl.org>
parents: 373
diff changeset
254 *value = 0;
8a43e0cbf02f Added SDL_GL_STEREO for stereoscopic OpenGL contexts
Sam Lantinga <slouken@libsdl.org>
parents: 373
diff changeset
255 }
8a43e0cbf02f Added SDL_GL_STEREO for stereoscopic OpenGL contexts
Sam Lantinga <slouken@libsdl.org>
parents: 373
diff changeset
256 break;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
257 default:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
258 retval = -1;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
259 break;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
260 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
261 return retval;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
262 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
263
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
264 void WIN_GL_SwapBuffers(_THIS)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
265 {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
266 SwapBuffers(GL_hdc);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
267 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
268
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
269 void WIN_GL_UnloadLibrary(_THIS)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
270 {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
271 if ( this->gl_config.driver_loaded ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
272 FreeLibrary((HMODULE)this->gl_config.dll_handle);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
273
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
274 this->gl_data->wglGetProcAddress = NULL;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
275 this->gl_data->wglCreateContext = NULL;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
276 this->gl_data->wglDeleteContext = NULL;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
277 this->gl_data->wglMakeCurrent = NULL;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
278
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
279 this->gl_config.dll_handle = NULL;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
280 this->gl_config.driver_loaded = 0;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
281 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
282 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
283
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
284 /* Passing a NULL path means load pointers from the application */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
285 int WIN_GL_LoadLibrary(_THIS, const char* path)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
286 {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
287 HMODULE handle;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
288
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
289 if ( gl_active ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
290 SDL_SetError("OpenGL context already created");
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
291 return -1;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
292 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
293
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
294 if ( path == NULL ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
295 path = DEFAULT_GL_DRIVER_PATH;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
296 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
297 handle = LoadLibrary(path);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
298 if ( handle == NULL ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
299 SDL_SetError("Could not load OpenGL library");
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
300 return -1;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
301 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
302
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
303 /* Unload the old driver and reset the pointers */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
304 WIN_GL_UnloadLibrary(this);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
305
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
306 /* Load new function pointers */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
307 this->gl_data->wglGetProcAddress = (void * (WINAPI *)(const char *))
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
308 GetProcAddress(handle, "wglGetProcAddress");
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
309 this->gl_data->wglCreateContext = (HGLRC (WINAPI *)(HDC))
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
310 GetProcAddress(handle, "wglCreateContext");
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
311 this->gl_data->wglDeleteContext = (BOOL (WINAPI *)(HGLRC))
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
312 GetProcAddress(handle, "wglDeleteContext");
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
313 this->gl_data->wglMakeCurrent = (BOOL (WINAPI *)(HDC, HGLRC))
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
314 GetProcAddress(handle, "wglMakeCurrent");
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
315
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
316 if ( (this->gl_data->wglGetProcAddress == NULL) ||
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
317 (this->gl_data->wglCreateContext == NULL) ||
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
318 (this->gl_data->wglDeleteContext == NULL) ||
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
319 (this->gl_data->wglMakeCurrent == NULL) ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
320 SDL_SetError("Could not retrieve OpenGL functions");
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
321 FreeLibrary(handle);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
322 return -1;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
323 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
324
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
325 this->gl_config.dll_handle = handle;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
326 strcpy(this->gl_config.driver_path, path);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
327 this->gl_config.driver_loaded = 1;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
328 return 0;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
329 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
330
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
331 void *WIN_GL_GetProcAddress(_THIS, const char* proc)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
332 {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
333 void *func;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
334
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
335 /* This is to pick up extensions */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
336 func = this->gl_data->wglGetProcAddress(proc);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
337 if ( ! func ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
338 /* This is probably a normal GL function */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
339 func = GetProcAddress(this->gl_config.dll_handle, proc);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
340 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
341 return func;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
342 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
343
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
344 #endif /* HAVE_OPENGL */