annotate src/video/wincommon/SDL_wingl.c @ 4249:429c8dd3175d SDL-1.2

Fixed bug #713 Don't clamp the mouse coordinates to the video surface size, instead clamp them to the last known window size. This allows users to get the correct mouse coordinates even if they don't call SDL_SetVideoMode() in response to an SDL_VIDEORESIZE event (used as a hack to retain the OpenGL context on Windows and Linux after a window resize)
author Sam Lantinga <slouken@libsdl.org>
date Sun, 27 Sep 2009 05:18:43 +0000
parents a1b03ba2fcd0
children
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
4159
a1b03ba2fcd0 Updated copyright date
Sam Lantinga <slouken@libsdl.org>
parents: 4082
diff changeset
3 Copyright (C) 1997-2009 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
1312
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 1280
diff changeset
6 modify it under the terms of the GNU Lesser General Public
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
7 License as published by the Free Software Foundation; either
1312
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 1280
diff changeset
8 version 2.1 of the License, or (at your option) any later version.
0
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
1312
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 1280
diff changeset
13 Lesser General Public License for more details.
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
14
1312
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 1280
diff changeset
15 You should have received a copy of the GNU Lesser General Public
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 1280
diff changeset
16 License along with this library; if not, write to the Free Software
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 1280
diff changeset
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
0
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 */
1402
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents: 1379
diff changeset
22 #include "SDL_config.h"
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
23
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
24 /* WGL implementation of SDL OpenGL support */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
25
1361
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents: 1358
diff changeset
26 #if SDL_VIDEO_OPENGL
327
13fc64213765 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
27 #include "SDL_opengl.h"
453
a6fa62b1be09 Updated for embedded Visual C++ 4.0
Sam Lantinga <slouken@libsdl.org>
parents: 450
diff changeset
28 #endif
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
29 #include "SDL_lowvideo.h"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
30 #include "SDL_wingl_c.h"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
31
1361
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents: 1358
diff changeset
32 #if SDL_VIDEO_OPENGL
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
33 #define DEFAULT_GL_DRIVER_PATH "OPENGL32.DLL"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
34 #endif
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
35
373
c638fde8a824 Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 327
diff changeset
36 /* 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
37 static int WIN_GL_ResetWindow(_THIS)
c638fde8a824 Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 327
diff changeset
38 {
c638fde8a824 Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 327
diff changeset
39 int status = 0;
c638fde8a824 Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 327
diff changeset
40
c638fde8a824 Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 327
diff changeset
41 #ifndef _WIN32_WCE /* FIXME WinCE needs the UNICODE version of CreateWindow() */
1527
ce84e28c2c07 Fixed bug #67
Sam Lantinga <slouken@libsdl.org>
parents: 1523
diff changeset
42 /* This doesn't work with DirectX code (see CVS comments) */
1280
f61f045343d3 Re-query the SDL_WINDOWID each time we initialize the video
Sam Lantinga <slouken@libsdl.org>
parents: 1261
diff changeset
43 /* If we were passed a window, then we can't create a new one */
1527
ce84e28c2c07 Fixed bug #67
Sam Lantinga <slouken@libsdl.org>
parents: 1523
diff changeset
44 if ( !SDL_windowid && SDL_strcmp(this->name, "windib") == 0 ) {
373
c638fde8a824 Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 327
diff changeset
45 /* Save the existing window attributes */
c638fde8a824 Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 327
diff changeset
46 LONG style;
c638fde8a824 Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 327
diff changeset
47 RECT rect = { 0, 0, 0, 0 };
1480
0a2bd6507477 More Win64 updates
Sam Lantinga <slouken@libsdl.org>
parents: 1472
diff changeset
48 style = GetWindowLong(SDL_Window, GWL_STYLE);
373
c638fde8a824 Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 327
diff changeset
49 GetWindowRect(SDL_Window, &rect);
c638fde8a824 Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 327
diff changeset
50 DestroyWindow(SDL_Window);
1523
21b1fbb53f4a (patch tweaked a bit)
Sam Lantinga <slouken@libsdl.org>
parents: 1480
diff changeset
51 WIN_FlushMessageQueue();
21b1fbb53f4a (patch tweaked a bit)
Sam Lantinga <slouken@libsdl.org>
parents: 1480
diff changeset
52
4082
01dbf7134045 Fixed bug #461
Sam Lantinga <slouken@libsdl.org>
parents: 4043
diff changeset
53 SDL_resizing = 1;
373
c638fde8a824 Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 327
diff changeset
54 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
55 style,
1316
0781906086fa *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 1315
diff changeset
56 rect.left, rect.top,
0781906086fa *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 1315
diff changeset
57 (rect.right-rect.left)+1,
4082
01dbf7134045 Fixed bug #461
Sam Lantinga <slouken@libsdl.org>
parents: 4043
diff changeset
58 (rect.bottom-rect.top)+1,
373
c638fde8a824 Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 327
diff changeset
59 NULL, NULL, SDL_Instance, NULL);
1523
21b1fbb53f4a (patch tweaked a bit)
Sam Lantinga <slouken@libsdl.org>
parents: 1480
diff changeset
60 WIN_FlushMessageQueue();
4082
01dbf7134045 Fixed bug #461
Sam Lantinga <slouken@libsdl.org>
parents: 4043
diff changeset
61 SDL_resizing = 0;
1523
21b1fbb53f4a (patch tweaked a bit)
Sam Lantinga <slouken@libsdl.org>
parents: 1480
diff changeset
62
373
c638fde8a824 Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 327
diff changeset
63 if ( SDL_Window ) {
c638fde8a824 Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 327
diff changeset
64 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
65 } else {
c638fde8a824 Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 327
diff changeset
66 SDL_SetError("Couldn't create window");
c638fde8a824 Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 327
diff changeset
67 status = -1;
c638fde8a824 Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 327
diff changeset
68 }
c638fde8a824 Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 327
diff changeset
69 } else
c638fde8a824 Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 327
diff changeset
70 #endif /* !_WIN32_WCE */
c638fde8a824 Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 327
diff changeset
71 {
c638fde8a824 Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 327
diff changeset
72 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
73 status = -1;
c638fde8a824 Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 327
diff changeset
74 }
c638fde8a824 Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 327
diff changeset
75 return(status);
c638fde8a824 Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 327
diff changeset
76 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
77
1361
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents: 1358
diff changeset
78 #if SDL_VIDEO_OPENGL
1315
e94b0d7c33bc Merged useful fixes from 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
79
e94b0d7c33bc Merged useful fixes from 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
80 static int ExtensionSupported(const char *extension, const char *extensions)
e94b0d7c33bc Merged useful fixes from 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
81 {
e94b0d7c33bc Merged useful fixes from 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
82 const char *start;
e94b0d7c33bc Merged useful fixes from 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
83 const char *where, *terminator;
e94b0d7c33bc Merged useful fixes from 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
84
e94b0d7c33bc Merged useful fixes from 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
85 /* Extension names should not have spaces. */
1336
3692456e7b0f Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents: 1330
diff changeset
86 where = SDL_strchr(extension, ' ');
1315
e94b0d7c33bc Merged useful fixes from 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
87 if ( where || *extension == '\0' )
e94b0d7c33bc Merged useful fixes from 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
88 return 0;
e94b0d7c33bc Merged useful fixes from 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
89
e94b0d7c33bc Merged useful fixes from 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
90 if ( ! extensions )
e94b0d7c33bc Merged useful fixes from 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
91 return 0;
e94b0d7c33bc Merged useful fixes from 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
92
e94b0d7c33bc Merged useful fixes from 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
93 /* It takes a bit of care to be fool-proof about parsing the
e94b0d7c33bc Merged useful fixes from 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
94 * OpenGL extensions string. Don't be fooled by sub-strings,
e94b0d7c33bc Merged useful fixes from 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
95 * etc. */
e94b0d7c33bc Merged useful fixes from 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
96
e94b0d7c33bc Merged useful fixes from 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
97 start = extensions;
e94b0d7c33bc Merged useful fixes from 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
98
e94b0d7c33bc Merged useful fixes from 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
99 for (;;)
e94b0d7c33bc Merged useful fixes from 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
100 {
1336
3692456e7b0f Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents: 1330
diff changeset
101 where = SDL_strstr(start, extension);
1315
e94b0d7c33bc Merged useful fixes from 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
102 if (!where) break;
e94b0d7c33bc Merged useful fixes from 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
103
1336
3692456e7b0f Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents: 1330
diff changeset
104 terminator = where + SDL_strlen(extension);
1315
e94b0d7c33bc Merged useful fixes from 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
105 if (where == start || *(where - 1) == ' ')
e94b0d7c33bc Merged useful fixes from 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
106 if (*terminator == ' ' || *terminator == '\0') return 1;
e94b0d7c33bc Merged useful fixes from 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
107
e94b0d7c33bc Merged useful fixes from 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
108 start = terminator;
e94b0d7c33bc Merged useful fixes from 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
109 }
e94b0d7c33bc Merged useful fixes from 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
110
e94b0d7c33bc Merged useful fixes from 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
111 return 0;
e94b0d7c33bc Merged useful fixes from 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
112 }
e94b0d7c33bc Merged useful fixes from 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
113
4042
f9d0b64cc7b9 I think this fixes bug #261
Sam Lantinga <slouken@libsdl.org>
parents: 3937
diff changeset
114 static int ChoosePixelFormatARB(_THIS, const int *iAttribs, const FLOAT *fAttribs)
655
9c42ee1b7d77 Date: Thu, 24 Apr 2003 15:13:47 -0400
Sam Lantinga <slouken@libsdl.org>
parents: 453
diff changeset
115 {
9c42ee1b7d77 Date: Thu, 24 Apr 2003 15:13:47 -0400
Sam Lantinga <slouken@libsdl.org>
parents: 453
diff changeset
116 HWND hwnd;
9c42ee1b7d77 Date: Thu, 24 Apr 2003 15:13:47 -0400
Sam Lantinga <slouken@libsdl.org>
parents: 453
diff changeset
117 HDC hdc;
9c42ee1b7d77 Date: Thu, 24 Apr 2003 15:13:47 -0400
Sam Lantinga <slouken@libsdl.org>
parents: 453
diff changeset
118 HGLRC hglrc;
9c42ee1b7d77 Date: Thu, 24 Apr 2003 15:13:47 -0400
Sam Lantinga <slouken@libsdl.org>
parents: 453
diff changeset
119 const char * (WINAPI *wglGetExtensionsStringARB)(HDC) = 0;
1315
e94b0d7c33bc Merged useful fixes from 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
120 const char *extensions;
4042
f9d0b64cc7b9 I think this fixes bug #261
Sam Lantinga <slouken@libsdl.org>
parents: 3937
diff changeset
121 int pformat = 0;
f9d0b64cc7b9 I think this fixes bug #261
Sam Lantinga <slouken@libsdl.org>
parents: 3937
diff changeset
122 UINT matches = 0;
f9d0b64cc7b9 I think this fixes bug #261
Sam Lantinga <slouken@libsdl.org>
parents: 3937
diff changeset
123
671
338a62f9a528 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 656
diff changeset
124 hwnd = CreateWindow(SDL_Appname, SDL_Appname, WS_POPUP | WS_DISABLED,
655
9c42ee1b7d77 Date: Thu, 24 Apr 2003 15:13:47 -0400
Sam Lantinga <slouken@libsdl.org>
parents: 453
diff changeset
125 0, 0, 10, 10,
1315
e94b0d7c33bc Merged useful fixes from 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
126 NULL, NULL, SDL_Instance, NULL);
1523
21b1fbb53f4a (patch tweaked a bit)
Sam Lantinga <slouken@libsdl.org>
parents: 1480
diff changeset
127 WIN_FlushMessageQueue();
21b1fbb53f4a (patch tweaked a bit)
Sam Lantinga <slouken@libsdl.org>
parents: 1480
diff changeset
128
655
9c42ee1b7d77 Date: Thu, 24 Apr 2003 15:13:47 -0400
Sam Lantinga <slouken@libsdl.org>
parents: 453
diff changeset
129 hdc = GetDC(hwnd);
9c42ee1b7d77 Date: Thu, 24 Apr 2003 15:13:47 -0400
Sam Lantinga <slouken@libsdl.org>
parents: 453
diff changeset
130
4042
f9d0b64cc7b9 I think this fixes bug #261
Sam Lantinga <slouken@libsdl.org>
parents: 3937
diff changeset
131 SetPixelFormat(hdc, ChoosePixelFormat(hdc, &GL_pfd), &GL_pfd);
655
9c42ee1b7d77 Date: Thu, 24 Apr 2003 15:13:47 -0400
Sam Lantinga <slouken@libsdl.org>
parents: 453
diff changeset
132
9c42ee1b7d77 Date: Thu, 24 Apr 2003 15:13:47 -0400
Sam Lantinga <slouken@libsdl.org>
parents: 453
diff changeset
133 hglrc = this->gl_data->wglCreateContext(hdc);
671
338a62f9a528 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 656
diff changeset
134 if ( hglrc ) {
338a62f9a528 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 656
diff changeset
135 this->gl_data->wglMakeCurrent(hdc, hglrc);
338a62f9a528 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 656
diff changeset
136 }
655
9c42ee1b7d77 Date: Thu, 24 Apr 2003 15:13:47 -0400
Sam Lantinga <slouken@libsdl.org>
parents: 453
diff changeset
137
9c42ee1b7d77 Date: Thu, 24 Apr 2003 15:13:47 -0400
Sam Lantinga <slouken@libsdl.org>
parents: 453
diff changeset
138 wglGetExtensionsStringARB = (const char * (WINAPI *)(HDC))
9c42ee1b7d77 Date: Thu, 24 Apr 2003 15:13:47 -0400
Sam Lantinga <slouken@libsdl.org>
parents: 453
diff changeset
139 this->gl_data->wglGetProcAddress("wglGetExtensionsStringARB");
9c42ee1b7d77 Date: Thu, 24 Apr 2003 15:13:47 -0400
Sam Lantinga <slouken@libsdl.org>
parents: 453
diff changeset
140
1315
e94b0d7c33bc Merged useful fixes from 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
141 if( wglGetExtensionsStringARB ) {
e94b0d7c33bc Merged useful fixes from 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
142 extensions = wglGetExtensionsStringARB(hdc);
e94b0d7c33bc Merged useful fixes from 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
143 } else {
e94b0d7c33bc Merged useful fixes from 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
144 extensions = NULL;
e94b0d7c33bc Merged useful fixes from 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
145 }
e94b0d7c33bc Merged useful fixes from 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
146
e94b0d7c33bc Merged useful fixes from 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
147 this->gl_data->WGL_ARB_pixel_format = 0;
e94b0d7c33bc Merged useful fixes from 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
148 if( ExtensionSupported("WGL_ARB_pixel_format", extensions) ) {
4042
f9d0b64cc7b9 I think this fixes bug #261
Sam Lantinga <slouken@libsdl.org>
parents: 3937
diff changeset
149 BOOL (WINAPI *wglChoosePixelFormatARB)(HDC hdc, const int *piAttribIList, const FLOAT *pfAttribFList, UINT nMaxFormats, int *piFormats, UINT *nNumFormats);
f9d0b64cc7b9 I think this fixes bug #261
Sam Lantinga <slouken@libsdl.org>
parents: 3937
diff changeset
150 wglChoosePixelFormatARB =
655
9c42ee1b7d77 Date: Thu, 24 Apr 2003 15:13:47 -0400
Sam Lantinga <slouken@libsdl.org>
parents: 453
diff changeset
151 (BOOL (WINAPI *)(HDC, const int *, const FLOAT *, UINT, int *, UINT *))
9c42ee1b7d77 Date: Thu, 24 Apr 2003 15:13:47 -0400
Sam Lantinga <slouken@libsdl.org>
parents: 453
diff changeset
152 this->gl_data->wglGetProcAddress("wglChoosePixelFormatARB");
4042
f9d0b64cc7b9 I think this fixes bug #261
Sam Lantinga <slouken@libsdl.org>
parents: 3937
diff changeset
153 if( wglChoosePixelFormatARB &&
f9d0b64cc7b9 I think this fixes bug #261
Sam Lantinga <slouken@libsdl.org>
parents: 3937
diff changeset
154 wglChoosePixelFormatARB(hdc, iAttribs, fAttribs, 1, &pformat, &matches) && pformat ) {
1315
e94b0d7c33bc Merged useful fixes from 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
155 this->gl_data->WGL_ARB_pixel_format = 1;
e94b0d7c33bc Merged useful fixes from 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
156 }
655
9c42ee1b7d77 Date: Thu, 24 Apr 2003 15:13:47 -0400
Sam Lantinga <slouken@libsdl.org>
parents: 453
diff changeset
157 }
9c42ee1b7d77 Date: Thu, 24 Apr 2003 15:13:47 -0400
Sam Lantinga <slouken@libsdl.org>
parents: 453
diff changeset
158
671
338a62f9a528 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 656
diff changeset
159 if ( hglrc ) {
338a62f9a528 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 656
diff changeset
160 this->gl_data->wglMakeCurrent(NULL, NULL);
338a62f9a528 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 656
diff changeset
161 this->gl_data->wglDeleteContext(hglrc);
338a62f9a528 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 656
diff changeset
162 }
655
9c42ee1b7d77 Date: Thu, 24 Apr 2003 15:13:47 -0400
Sam Lantinga <slouken@libsdl.org>
parents: 453
diff changeset
163 ReleaseDC(hwnd, hdc);
9c42ee1b7d77 Date: Thu, 24 Apr 2003 15:13:47 -0400
Sam Lantinga <slouken@libsdl.org>
parents: 453
diff changeset
164 DestroyWindow(hwnd);
1523
21b1fbb53f4a (patch tweaked a bit)
Sam Lantinga <slouken@libsdl.org>
parents: 1480
diff changeset
165 WIN_FlushMessageQueue();
4042
f9d0b64cc7b9 I think this fixes bug #261
Sam Lantinga <slouken@libsdl.org>
parents: 3937
diff changeset
166
f9d0b64cc7b9 I think this fixes bug #261
Sam Lantinga <slouken@libsdl.org>
parents: 3937
diff changeset
167 return pformat;
655
9c42ee1b7d77 Date: Thu, 24 Apr 2003 15:13:47 -0400
Sam Lantinga <slouken@libsdl.org>
parents: 453
diff changeset
168 }
1315
e94b0d7c33bc Merged useful fixes from 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
169
1361
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents: 1358
diff changeset
170 #endif /* SDL_VIDEO_OPENGL */
655
9c42ee1b7d77 Date: Thu, 24 Apr 2003 15:13:47 -0400
Sam Lantinga <slouken@libsdl.org>
parents: 453
diff changeset
171
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
172 int WIN_GL_SetupWindow(_THIS)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
173 {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
174 int retval;
1361
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents: 1358
diff changeset
175 #if SDL_VIDEO_OPENGL
373
c638fde8a824 Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 327
diff changeset
176 int i;
655
9c42ee1b7d77 Date: Thu, 24 Apr 2003 15:13:47 -0400
Sam Lantinga <slouken@libsdl.org>
parents: 453
diff changeset
177 int iAttribs[64];
9c42ee1b7d77 Date: Thu, 24 Apr 2003 15:13:47 -0400
Sam Lantinga <slouken@libsdl.org>
parents: 453
diff changeset
178 int *iAttr;
9c42ee1b7d77 Date: Thu, 24 Apr 2003 15:13:47 -0400
Sam Lantinga <slouken@libsdl.org>
parents: 453
diff changeset
179 float fAttribs[1] = { 0 };
1769
290b5baf2fca Fixed bug #215
Sam Lantinga <slouken@libsdl.org>
parents: 1757
diff changeset
180 const GLubyte *(WINAPI *glGetStringFunc)(GLenum);
1736
3b2a92126f4d Implemented bug #2, 117:
Sam Lantinga <slouken@libsdl.org>
parents: 1527
diff changeset
181 const char *wglext;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
182
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
183 /* load the gl driver from a default path */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
184 if ( ! this->gl_config.driver_loaded ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
185 /* no driver has been loaded, use default (ourselves) */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
186 if ( WIN_GL_LoadLibrary(this, NULL) < 0 ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
187 return(-1);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
188 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
189 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
190
4042
f9d0b64cc7b9 I think this fixes bug #261
Sam Lantinga <slouken@libsdl.org>
parents: 3937
diff changeset
191 /* Set up the pixel format descriptor with our needed format */
f9d0b64cc7b9 I think this fixes bug #261
Sam Lantinga <slouken@libsdl.org>
parents: 3937
diff changeset
192 SDL_memset(&GL_pfd, 0, sizeof(GL_pfd));
f9d0b64cc7b9 I think this fixes bug #261
Sam Lantinga <slouken@libsdl.org>
parents: 3937
diff changeset
193 GL_pfd.nSize = sizeof(GL_pfd);
f9d0b64cc7b9 I think this fixes bug #261
Sam Lantinga <slouken@libsdl.org>
parents: 3937
diff changeset
194 GL_pfd.nVersion = 1;
f9d0b64cc7b9 I think this fixes bug #261
Sam Lantinga <slouken@libsdl.org>
parents: 3937
diff changeset
195 GL_pfd.dwFlags = (PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL);
f9d0b64cc7b9 I think this fixes bug #261
Sam Lantinga <slouken@libsdl.org>
parents: 3937
diff changeset
196 if ( this->gl_config.double_buffer ) {
f9d0b64cc7b9 I think this fixes bug #261
Sam Lantinga <slouken@libsdl.org>
parents: 3937
diff changeset
197 GL_pfd.dwFlags |= PFD_DOUBLEBUFFER;
f9d0b64cc7b9 I think this fixes bug #261
Sam Lantinga <slouken@libsdl.org>
parents: 3937
diff changeset
198 }
f9d0b64cc7b9 I think this fixes bug #261
Sam Lantinga <slouken@libsdl.org>
parents: 3937
diff changeset
199 if ( this->gl_config.stereo ) {
f9d0b64cc7b9 I think this fixes bug #261
Sam Lantinga <slouken@libsdl.org>
parents: 3937
diff changeset
200 GL_pfd.dwFlags |= PFD_STEREO;
f9d0b64cc7b9 I think this fixes bug #261
Sam Lantinga <slouken@libsdl.org>
parents: 3937
diff changeset
201 }
f9d0b64cc7b9 I think this fixes bug #261
Sam Lantinga <slouken@libsdl.org>
parents: 3937
diff changeset
202 GL_pfd.iPixelType = PFD_TYPE_RGBA;
f9d0b64cc7b9 I think this fixes bug #261
Sam Lantinga <slouken@libsdl.org>
parents: 3937
diff changeset
203 GL_pfd.cColorBits = this->gl_config.buffer_size;
f9d0b64cc7b9 I think this fixes bug #261
Sam Lantinga <slouken@libsdl.org>
parents: 3937
diff changeset
204 GL_pfd.cRedBits = this->gl_config.red_size;
f9d0b64cc7b9 I think this fixes bug #261
Sam Lantinga <slouken@libsdl.org>
parents: 3937
diff changeset
205 GL_pfd.cGreenBits = this->gl_config.green_size;
f9d0b64cc7b9 I think this fixes bug #261
Sam Lantinga <slouken@libsdl.org>
parents: 3937
diff changeset
206 GL_pfd.cBlueBits = this->gl_config.blue_size;
f9d0b64cc7b9 I think this fixes bug #261
Sam Lantinga <slouken@libsdl.org>
parents: 3937
diff changeset
207 GL_pfd.cAlphaBits = this->gl_config.alpha_size;
f9d0b64cc7b9 I think this fixes bug #261
Sam Lantinga <slouken@libsdl.org>
parents: 3937
diff changeset
208 GL_pfd.cAccumRedBits = this->gl_config.accum_red_size;
f9d0b64cc7b9 I think this fixes bug #261
Sam Lantinga <slouken@libsdl.org>
parents: 3937
diff changeset
209 GL_pfd.cAccumGreenBits = this->gl_config.accum_green_size;
f9d0b64cc7b9 I think this fixes bug #261
Sam Lantinga <slouken@libsdl.org>
parents: 3937
diff changeset
210 GL_pfd.cAccumBlueBits = this->gl_config.accum_blue_size;
f9d0b64cc7b9 I think this fixes bug #261
Sam Lantinga <slouken@libsdl.org>
parents: 3937
diff changeset
211 GL_pfd.cAccumAlphaBits = this->gl_config.accum_alpha_size;
f9d0b64cc7b9 I think this fixes bug #261
Sam Lantinga <slouken@libsdl.org>
parents: 3937
diff changeset
212 GL_pfd.cAccumBits =
f9d0b64cc7b9 I think this fixes bug #261
Sam Lantinga <slouken@libsdl.org>
parents: 3937
diff changeset
213 (GL_pfd.cAccumRedBits + GL_pfd.cAccumGreenBits +
f9d0b64cc7b9 I think this fixes bug #261
Sam Lantinga <slouken@libsdl.org>
parents: 3937
diff changeset
214 GL_pfd.cAccumBlueBits + GL_pfd.cAccumAlphaBits);
f9d0b64cc7b9 I think this fixes bug #261
Sam Lantinga <slouken@libsdl.org>
parents: 3937
diff changeset
215 GL_pfd.cDepthBits = this->gl_config.depth_size;
f9d0b64cc7b9 I think this fixes bug #261
Sam Lantinga <slouken@libsdl.org>
parents: 3937
diff changeset
216 GL_pfd.cStencilBits = this->gl_config.stencil_size;
f9d0b64cc7b9 I think this fixes bug #261
Sam Lantinga <slouken@libsdl.org>
parents: 3937
diff changeset
217
f9d0b64cc7b9 I think this fixes bug #261
Sam Lantinga <slouken@libsdl.org>
parents: 3937
diff changeset
218 /* setup WGL_ARB_pixel_format attribs */
f9d0b64cc7b9 I think this fixes bug #261
Sam Lantinga <slouken@libsdl.org>
parents: 3937
diff changeset
219 iAttr = &iAttribs[0];
f9d0b64cc7b9 I think this fixes bug #261
Sam Lantinga <slouken@libsdl.org>
parents: 3937
diff changeset
220
f9d0b64cc7b9 I think this fixes bug #261
Sam Lantinga <slouken@libsdl.org>
parents: 3937
diff changeset
221 *iAttr++ = WGL_DRAW_TO_WINDOW_ARB;
f9d0b64cc7b9 I think this fixes bug #261
Sam Lantinga <slouken@libsdl.org>
parents: 3937
diff changeset
222 *iAttr++ = GL_TRUE;
f9d0b64cc7b9 I think this fixes bug #261
Sam Lantinga <slouken@libsdl.org>
parents: 3937
diff changeset
223 *iAttr++ = WGL_ACCELERATION_ARB;
f9d0b64cc7b9 I think this fixes bug #261
Sam Lantinga <slouken@libsdl.org>
parents: 3937
diff changeset
224 *iAttr++ = WGL_FULL_ACCELERATION_ARB;
f9d0b64cc7b9 I think this fixes bug #261
Sam Lantinga <slouken@libsdl.org>
parents: 3937
diff changeset
225 *iAttr++ = WGL_RED_BITS_ARB;
f9d0b64cc7b9 I think this fixes bug #261
Sam Lantinga <slouken@libsdl.org>
parents: 3937
diff changeset
226 *iAttr++ = this->gl_config.red_size;
f9d0b64cc7b9 I think this fixes bug #261
Sam Lantinga <slouken@libsdl.org>
parents: 3937
diff changeset
227 *iAttr++ = WGL_GREEN_BITS_ARB;
f9d0b64cc7b9 I think this fixes bug #261
Sam Lantinga <slouken@libsdl.org>
parents: 3937
diff changeset
228 *iAttr++ = this->gl_config.green_size;
f9d0b64cc7b9 I think this fixes bug #261
Sam Lantinga <slouken@libsdl.org>
parents: 3937
diff changeset
229 *iAttr++ = WGL_BLUE_BITS_ARB;
f9d0b64cc7b9 I think this fixes bug #261
Sam Lantinga <slouken@libsdl.org>
parents: 3937
diff changeset
230 *iAttr++ = this->gl_config.blue_size;
f9d0b64cc7b9 I think this fixes bug #261
Sam Lantinga <slouken@libsdl.org>
parents: 3937
diff changeset
231
f9d0b64cc7b9 I think this fixes bug #261
Sam Lantinga <slouken@libsdl.org>
parents: 3937
diff changeset
232 if ( this->gl_config.alpha_size ) {
f9d0b64cc7b9 I think this fixes bug #261
Sam Lantinga <slouken@libsdl.org>
parents: 3937
diff changeset
233 *iAttr++ = WGL_ALPHA_BITS_ARB;
f9d0b64cc7b9 I think this fixes bug #261
Sam Lantinga <slouken@libsdl.org>
parents: 3937
diff changeset
234 *iAttr++ = this->gl_config.alpha_size;
f9d0b64cc7b9 I think this fixes bug #261
Sam Lantinga <slouken@libsdl.org>
parents: 3937
diff changeset
235 }
f9d0b64cc7b9 I think this fixes bug #261
Sam Lantinga <slouken@libsdl.org>
parents: 3937
diff changeset
236
f9d0b64cc7b9 I think this fixes bug #261
Sam Lantinga <slouken@libsdl.org>
parents: 3937
diff changeset
237 *iAttr++ = WGL_DOUBLE_BUFFER_ARB;
f9d0b64cc7b9 I think this fixes bug #261
Sam Lantinga <slouken@libsdl.org>
parents: 3937
diff changeset
238 *iAttr++ = this->gl_config.double_buffer;
f9d0b64cc7b9 I think this fixes bug #261
Sam Lantinga <slouken@libsdl.org>
parents: 3937
diff changeset
239
f9d0b64cc7b9 I think this fixes bug #261
Sam Lantinga <slouken@libsdl.org>
parents: 3937
diff changeset
240 *iAttr++ = WGL_DEPTH_BITS_ARB;
f9d0b64cc7b9 I think this fixes bug #261
Sam Lantinga <slouken@libsdl.org>
parents: 3937
diff changeset
241 *iAttr++ = this->gl_config.depth_size;
f9d0b64cc7b9 I think this fixes bug #261
Sam Lantinga <slouken@libsdl.org>
parents: 3937
diff changeset
242
f9d0b64cc7b9 I think this fixes bug #261
Sam Lantinga <slouken@libsdl.org>
parents: 3937
diff changeset
243 if ( this->gl_config.stencil_size ) {
f9d0b64cc7b9 I think this fixes bug #261
Sam Lantinga <slouken@libsdl.org>
parents: 3937
diff changeset
244 *iAttr++ = WGL_STENCIL_BITS_ARB;
f9d0b64cc7b9 I think this fixes bug #261
Sam Lantinga <slouken@libsdl.org>
parents: 3937
diff changeset
245 *iAttr++ = this->gl_config.stencil_size;
f9d0b64cc7b9 I think this fixes bug #261
Sam Lantinga <slouken@libsdl.org>
parents: 3937
diff changeset
246 }
f9d0b64cc7b9 I think this fixes bug #261
Sam Lantinga <slouken@libsdl.org>
parents: 3937
diff changeset
247
f9d0b64cc7b9 I think this fixes bug #261
Sam Lantinga <slouken@libsdl.org>
parents: 3937
diff changeset
248 if ( this->gl_config.accum_red_size ) {
f9d0b64cc7b9 I think this fixes bug #261
Sam Lantinga <slouken@libsdl.org>
parents: 3937
diff changeset
249 *iAttr++ = WGL_ACCUM_RED_BITS_ARB;
f9d0b64cc7b9 I think this fixes bug #261
Sam Lantinga <slouken@libsdl.org>
parents: 3937
diff changeset
250 *iAttr++ = this->gl_config.accum_red_size;
f9d0b64cc7b9 I think this fixes bug #261
Sam Lantinga <slouken@libsdl.org>
parents: 3937
diff changeset
251 }
f9d0b64cc7b9 I think this fixes bug #261
Sam Lantinga <slouken@libsdl.org>
parents: 3937
diff changeset
252
f9d0b64cc7b9 I think this fixes bug #261
Sam Lantinga <slouken@libsdl.org>
parents: 3937
diff changeset
253 if ( this->gl_config.accum_green_size ) {
f9d0b64cc7b9 I think this fixes bug #261
Sam Lantinga <slouken@libsdl.org>
parents: 3937
diff changeset
254 *iAttr++ = WGL_ACCUM_GREEN_BITS_ARB;
f9d0b64cc7b9 I think this fixes bug #261
Sam Lantinga <slouken@libsdl.org>
parents: 3937
diff changeset
255 *iAttr++ = this->gl_config.accum_green_size;
f9d0b64cc7b9 I think this fixes bug #261
Sam Lantinga <slouken@libsdl.org>
parents: 3937
diff changeset
256 }
f9d0b64cc7b9 I think this fixes bug #261
Sam Lantinga <slouken@libsdl.org>
parents: 3937
diff changeset
257
f9d0b64cc7b9 I think this fixes bug #261
Sam Lantinga <slouken@libsdl.org>
parents: 3937
diff changeset
258 if ( this->gl_config.accum_blue_size ) {
f9d0b64cc7b9 I think this fixes bug #261
Sam Lantinga <slouken@libsdl.org>
parents: 3937
diff changeset
259 *iAttr++ = WGL_ACCUM_BLUE_BITS_ARB;
f9d0b64cc7b9 I think this fixes bug #261
Sam Lantinga <slouken@libsdl.org>
parents: 3937
diff changeset
260 *iAttr++ = this->gl_config.accum_blue_size;
f9d0b64cc7b9 I think this fixes bug #261
Sam Lantinga <slouken@libsdl.org>
parents: 3937
diff changeset
261 }
f9d0b64cc7b9 I think this fixes bug #261
Sam Lantinga <slouken@libsdl.org>
parents: 3937
diff changeset
262
f9d0b64cc7b9 I think this fixes bug #261
Sam Lantinga <slouken@libsdl.org>
parents: 3937
diff changeset
263 if ( this->gl_config.accum_alpha_size ) {
f9d0b64cc7b9 I think this fixes bug #261
Sam Lantinga <slouken@libsdl.org>
parents: 3937
diff changeset
264 *iAttr++ = WGL_ACCUM_ALPHA_BITS_ARB;
f9d0b64cc7b9 I think this fixes bug #261
Sam Lantinga <slouken@libsdl.org>
parents: 3937
diff changeset
265 *iAttr++ = this->gl_config.accum_alpha_size;
f9d0b64cc7b9 I think this fixes bug #261
Sam Lantinga <slouken@libsdl.org>
parents: 3937
diff changeset
266 }
f9d0b64cc7b9 I think this fixes bug #261
Sam Lantinga <slouken@libsdl.org>
parents: 3937
diff changeset
267
f9d0b64cc7b9 I think this fixes bug #261
Sam Lantinga <slouken@libsdl.org>
parents: 3937
diff changeset
268 if ( this->gl_config.stereo ) {
f9d0b64cc7b9 I think this fixes bug #261
Sam Lantinga <slouken@libsdl.org>
parents: 3937
diff changeset
269 *iAttr++ = WGL_STEREO_ARB;
f9d0b64cc7b9 I think this fixes bug #261
Sam Lantinga <slouken@libsdl.org>
parents: 3937
diff changeset
270 *iAttr++ = GL_TRUE;
f9d0b64cc7b9 I think this fixes bug #261
Sam Lantinga <slouken@libsdl.org>
parents: 3937
diff changeset
271 }
f9d0b64cc7b9 I think this fixes bug #261
Sam Lantinga <slouken@libsdl.org>
parents: 3937
diff changeset
272
f9d0b64cc7b9 I think this fixes bug #261
Sam Lantinga <slouken@libsdl.org>
parents: 3937
diff changeset
273 if ( this->gl_config.multisamplebuffers ) {
f9d0b64cc7b9 I think this fixes bug #261
Sam Lantinga <slouken@libsdl.org>
parents: 3937
diff changeset
274 *iAttr++ = WGL_SAMPLE_BUFFERS_ARB;
f9d0b64cc7b9 I think this fixes bug #261
Sam Lantinga <slouken@libsdl.org>
parents: 3937
diff changeset
275 *iAttr++ = this->gl_config.multisamplebuffers;
f9d0b64cc7b9 I think this fixes bug #261
Sam Lantinga <slouken@libsdl.org>
parents: 3937
diff changeset
276 }
f9d0b64cc7b9 I think this fixes bug #261
Sam Lantinga <slouken@libsdl.org>
parents: 3937
diff changeset
277
f9d0b64cc7b9 I think this fixes bug #261
Sam Lantinga <slouken@libsdl.org>
parents: 3937
diff changeset
278 if ( this->gl_config.multisamplesamples ) {
f9d0b64cc7b9 I think this fixes bug #261
Sam Lantinga <slouken@libsdl.org>
parents: 3937
diff changeset
279 *iAttr++ = WGL_SAMPLES_ARB;
f9d0b64cc7b9 I think this fixes bug #261
Sam Lantinga <slouken@libsdl.org>
parents: 3937
diff changeset
280 *iAttr++ = this->gl_config.multisamplesamples;
f9d0b64cc7b9 I think this fixes bug #261
Sam Lantinga <slouken@libsdl.org>
parents: 3937
diff changeset
281 }
f9d0b64cc7b9 I think this fixes bug #261
Sam Lantinga <slouken@libsdl.org>
parents: 3937
diff changeset
282
f9d0b64cc7b9 I think this fixes bug #261
Sam Lantinga <slouken@libsdl.org>
parents: 3937
diff changeset
283 if ( this->gl_config.accelerated >= 0 ) {
f9d0b64cc7b9 I think this fixes bug #261
Sam Lantinga <slouken@libsdl.org>
parents: 3937
diff changeset
284 *iAttr++ = WGL_ACCELERATION_ARB;
f9d0b64cc7b9 I think this fixes bug #261
Sam Lantinga <slouken@libsdl.org>
parents: 3937
diff changeset
285 *iAttr++ = (this->gl_config.accelerated ? WGL_GENERIC_ACCELERATION_ARB : WGL_NO_ACCELERATION_ARB);
f9d0b64cc7b9 I think this fixes bug #261
Sam Lantinga <slouken@libsdl.org>
parents: 3937
diff changeset
286 }
f9d0b64cc7b9 I think this fixes bug #261
Sam Lantinga <slouken@libsdl.org>
parents: 3937
diff changeset
287
f9d0b64cc7b9 I think this fixes bug #261
Sam Lantinga <slouken@libsdl.org>
parents: 3937
diff changeset
288 *iAttr = 0;
f9d0b64cc7b9 I think this fixes bug #261
Sam Lantinga <slouken@libsdl.org>
parents: 3937
diff changeset
289
373
c638fde8a824 Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 327
diff changeset
290 for ( i=0; ; ++i ) {
c638fde8a824 Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 327
diff changeset
291 /* 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
292 GL_hdc = GetDC(SDL_Window);
c638fde8a824 Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 327
diff changeset
293 if ( GL_hdc == NULL ) {
c638fde8a824 Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 327
diff changeset
294 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
295 return(-1);
c638fde8a824 Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 327
diff changeset
296 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
297
373
c638fde8a824 Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 327
diff changeset
298 /* Choose and set the closest available pixel format */
4042
f9d0b64cc7b9 I think this fixes bug #261
Sam Lantinga <slouken@libsdl.org>
parents: 3937
diff changeset
299 pixel_format = ChoosePixelFormatARB(this, iAttribs, fAttribs);
f9d0b64cc7b9 I think this fixes bug #261
Sam Lantinga <slouken@libsdl.org>
parents: 3937
diff changeset
300 if ( !pixel_format ) {
655
9c42ee1b7d77 Date: Thu, 24 Apr 2003 15:13:47 -0400
Sam Lantinga <slouken@libsdl.org>
parents: 453
diff changeset
301 pixel_format = ChoosePixelFormat(GL_hdc, &GL_pfd);
9c42ee1b7d77 Date: Thu, 24 Apr 2003 15:13:47 -0400
Sam Lantinga <slouken@libsdl.org>
parents: 453
diff changeset
302 }
373
c638fde8a824 Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 327
diff changeset
303 if ( !pixel_format ) {
c638fde8a824 Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 327
diff changeset
304 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
305 return(-1);
c638fde8a824 Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 327
diff changeset
306 }
655
9c42ee1b7d77 Date: Thu, 24 Apr 2003 15:13:47 -0400
Sam Lantinga <slouken@libsdl.org>
parents: 453
diff changeset
307 if ( !SetPixelFormat(GL_hdc, pixel_format, &GL_pfd) ) {
373
c638fde8a824 Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 327
diff changeset
308 if ( i == 0 ) {
c638fde8a824 Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 327
diff changeset
309 /* 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
310 if ( WIN_GL_ResetWindow(this) < 0 ) {
c638fde8a824 Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 327
diff changeset
311 return(-1);
c638fde8a824 Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 327
diff changeset
312 }
c638fde8a824 Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 327
diff changeset
313 continue;
c638fde8a824 Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 327
diff changeset
314 }
c638fde8a824 Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 327
diff changeset
315 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
316 return(-1);
c638fde8a824 Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 327
diff changeset
317 }
c638fde8a824 Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 327
diff changeset
318 /* 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
319 break;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
320 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
321 DescribePixelFormat(GL_hdc, pixel_format, sizeof(GL_pfd), &GL_pfd);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
322
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
323 GL_hrc = this->gl_data->wglCreateContext(GL_hdc);
655
9c42ee1b7d77 Date: Thu, 24 Apr 2003 15:13:47 -0400
Sam Lantinga <slouken@libsdl.org>
parents: 453
diff changeset
324 if ( GL_hrc == NULL ) {
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
325 SDL_SetError("Unable to create GL context");
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
326 return(-1);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
327 }
1736
3b2a92126f4d Implemented bug #2, 117:
Sam Lantinga <slouken@libsdl.org>
parents: 1527
diff changeset
328 if ( WIN_GL_MakeCurrent(this) < 0 ) {
3b2a92126f4d Implemented bug #2, 117:
Sam Lantinga <slouken@libsdl.org>
parents: 1527
diff changeset
329 return(-1);
3b2a92126f4d Implemented bug #2, 117:
Sam Lantinga <slouken@libsdl.org>
parents: 1527
diff changeset
330 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
331 gl_active = 1;
1736
3b2a92126f4d Implemented bug #2, 117:
Sam Lantinga <slouken@libsdl.org>
parents: 1527
diff changeset
332
4042
f9d0b64cc7b9 I think this fixes bug #261
Sam Lantinga <slouken@libsdl.org>
parents: 3937
diff changeset
333 /* Get the wglGetPixelFormatAttribivARB pointer for the context */
f9d0b64cc7b9 I think this fixes bug #261
Sam Lantinga <slouken@libsdl.org>
parents: 3937
diff changeset
334 if ( this->gl_data->WGL_ARB_pixel_format ) {
f9d0b64cc7b9 I think this fixes bug #261
Sam Lantinga <slouken@libsdl.org>
parents: 3937
diff changeset
335 this->gl_data->wglGetPixelFormatAttribivARB =
f9d0b64cc7b9 I think this fixes bug #261
Sam Lantinga <slouken@libsdl.org>
parents: 3937
diff changeset
336 (BOOL (WINAPI *)(HDC, int, int, UINT, const int *, int *))
f9d0b64cc7b9 I think this fixes bug #261
Sam Lantinga <slouken@libsdl.org>
parents: 3937
diff changeset
337 this->gl_data->wglGetProcAddress("wglGetPixelFormatAttribivARB");
f9d0b64cc7b9 I think this fixes bug #261
Sam Lantinga <slouken@libsdl.org>
parents: 3937
diff changeset
338 } else {
f9d0b64cc7b9 I think this fixes bug #261
Sam Lantinga <slouken@libsdl.org>
parents: 3937
diff changeset
339 this->gl_data->wglGetPixelFormatAttribivARB = NULL;
f9d0b64cc7b9 I think this fixes bug #261
Sam Lantinga <slouken@libsdl.org>
parents: 3937
diff changeset
340 }
f9d0b64cc7b9 I think this fixes bug #261
Sam Lantinga <slouken@libsdl.org>
parents: 3937
diff changeset
341
1736
3b2a92126f4d Implemented bug #2, 117:
Sam Lantinga <slouken@libsdl.org>
parents: 1527
diff changeset
342 /* Vsync control under Windows. Checking glGetString here is
3b2a92126f4d Implemented bug #2, 117:
Sam Lantinga <slouken@libsdl.org>
parents: 1527
diff changeset
343 * somewhat a documented and reliable hack - it was originally
3b2a92126f4d Implemented bug #2, 117:
Sam Lantinga <slouken@libsdl.org>
parents: 1527
diff changeset
344 * as a feature added by mistake, but since so many people rely
3b2a92126f4d Implemented bug #2, 117:
Sam Lantinga <slouken@libsdl.org>
parents: 1527
diff changeset
345 * on it, it will not be removed. strstr should be safe here.*/
1754
c67921b517c3 Date: Sun, 30 Apr 2006 14:20:05 +1000
Sam Lantinga <slouken@libsdl.org>
parents: 1737
diff changeset
346 glGetStringFunc = WIN_GL_GetProcAddress(this, "glGetString");
c67921b517c3 Date: Sun, 30 Apr 2006 14:20:05 +1000
Sam Lantinga <slouken@libsdl.org>
parents: 1737
diff changeset
347 if ( glGetStringFunc ) {
1757
ac282d472a2e Yeah, that's what I meant. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1754
diff changeset
348 wglext = (const char *)glGetStringFunc(GL_EXTENSIONS);
1754
c67921b517c3 Date: Sun, 30 Apr 2006 14:20:05 +1000
Sam Lantinga <slouken@libsdl.org>
parents: 1737
diff changeset
349 } else {
c67921b517c3 Date: Sun, 30 Apr 2006 14:20:05 +1000
Sam Lantinga <slouken@libsdl.org>
parents: 1737
diff changeset
350 /* Uh oh, something is seriously wrong here... */
c67921b517c3 Date: Sun, 30 Apr 2006 14:20:05 +1000
Sam Lantinga <slouken@libsdl.org>
parents: 1737
diff changeset
351 wglext = NULL;
c67921b517c3 Date: Sun, 30 Apr 2006 14:20:05 +1000
Sam Lantinga <slouken@libsdl.org>
parents: 1737
diff changeset
352 }
1880
9d940db55a91 Fixed bug #260
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
353 if ( wglext && SDL_strstr(wglext, "WGL_EXT_swap_control") ) {
9d940db55a91 Fixed bug #260
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
354 this->gl_data->wglSwapIntervalEXT = WIN_GL_GetProcAddress(this, "wglSwapIntervalEXT");
9d940db55a91 Fixed bug #260
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
355 this->gl_data->wglGetSwapIntervalEXT = WIN_GL_GetProcAddress(this, "wglGetSwapIntervalEXT");
9d940db55a91 Fixed bug #260
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
356 } else {
1736
3b2a92126f4d Implemented bug #2, 117:
Sam Lantinga <slouken@libsdl.org>
parents: 1527
diff changeset
357 this->gl_data->wglSwapIntervalEXT = NULL;
3b2a92126f4d Implemented bug #2, 117:
Sam Lantinga <slouken@libsdl.org>
parents: 1527
diff changeset
358 this->gl_data->wglGetSwapIntervalEXT = NULL;
3b2a92126f4d Implemented bug #2, 117:
Sam Lantinga <slouken@libsdl.org>
parents: 1527
diff changeset
359 }
3b2a92126f4d Implemented bug #2, 117:
Sam Lantinga <slouken@libsdl.org>
parents: 1527
diff changeset
360 if ( this->gl_config.swap_control >= 0 ) {
3b2a92126f4d Implemented bug #2, 117:
Sam Lantinga <slouken@libsdl.org>
parents: 1527
diff changeset
361 if ( this->gl_data->wglSwapIntervalEXT ) {
3b2a92126f4d Implemented bug #2, 117:
Sam Lantinga <slouken@libsdl.org>
parents: 1527
diff changeset
362 this->gl_data->wglSwapIntervalEXT(this->gl_config.swap_control);
3b2a92126f4d Implemented bug #2, 117:
Sam Lantinga <slouken@libsdl.org>
parents: 1527
diff changeset
363 }
3b2a92126f4d Implemented bug #2, 117:
Sam Lantinga <slouken@libsdl.org>
parents: 1527
diff changeset
364 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
365 #else
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
366 SDL_SetError("WIN driver not configured with OpenGL");
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
367 #endif
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
368 if ( gl_active ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
369 retval = 0;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
370 } else {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
371 retval = -1;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
372 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
373 return(retval);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
374 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
375
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
376 void WIN_GL_ShutDown(_THIS)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
377 {
1361
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents: 1358
diff changeset
378 #if SDL_VIDEO_OPENGL
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
379 /* Clean up OpenGL */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
380 if ( GL_hrc ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
381 this->gl_data->wglMakeCurrent(NULL, NULL);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
382 this->gl_data->wglDeleteContext(GL_hrc);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
383 GL_hrc = NULL;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
384 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
385 if ( GL_hdc ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
386 ReleaseDC(SDL_Window, GL_hdc);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
387 GL_hdc = NULL;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
388 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
389 gl_active = 0;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
390
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
391 WIN_GL_UnloadLibrary(this);
1361
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents: 1358
diff changeset
392 #endif /* SDL_VIDEO_OPENGL */
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
393 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
394
1361
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents: 1358
diff changeset
395 #if SDL_VIDEO_OPENGL
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
396
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
397 /* Make the current context active */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
398 int WIN_GL_MakeCurrent(_THIS)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
399 {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
400 int retval;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
401
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
402 retval = 0;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
403 if ( ! this->gl_data->wglMakeCurrent(GL_hdc, GL_hrc) ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
404 SDL_SetError("Unable to make GL context current");
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
405 retval = -1;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
406 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
407 return(retval);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
408 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
409
3937
5c6e937518c6 Let Windows OpenGL users use SDL_GL_SWAP_CONTROL even if WGL_ARB_pixel_format
Ryan C. Gordon <icculus@icculus.org>
parents: 1880
diff changeset
410 /* Get attribute data from wgl. */
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
411 int WIN_GL_GetAttribute(_THIS, SDL_GLattr attrib, int* value)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
412 {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
413 int retval;
3937
5c6e937518c6 Let Windows OpenGL users use SDL_GL_SWAP_CONTROL even if WGL_ARB_pixel_format
Ryan C. Gordon <icculus@icculus.org>
parents: 1880
diff changeset
414
5c6e937518c6 Let Windows OpenGL users use SDL_GL_SWAP_CONTROL even if WGL_ARB_pixel_format
Ryan C. Gordon <icculus@icculus.org>
parents: 1880
diff changeset
415 if (attrib == SDL_GL_SWAP_CONTROL) {
5c6e937518c6 Let Windows OpenGL users use SDL_GL_SWAP_CONTROL even if WGL_ARB_pixel_format
Ryan C. Gordon <icculus@icculus.org>
parents: 1880
diff changeset
416 if ( this->gl_data->wglGetSwapIntervalEXT ) {
5c6e937518c6 Let Windows OpenGL users use SDL_GL_SWAP_CONTROL even if WGL_ARB_pixel_format
Ryan C. Gordon <icculus@icculus.org>
parents: 1880
diff changeset
417 *value = this->gl_data->wglGetSwapIntervalEXT();
5c6e937518c6 Let Windows OpenGL users use SDL_GL_SWAP_CONTROL even if WGL_ARB_pixel_format
Ryan C. Gordon <icculus@icculus.org>
parents: 1880
diff changeset
418 return 0;
5c6e937518c6 Let Windows OpenGL users use SDL_GL_SWAP_CONTROL even if WGL_ARB_pixel_format
Ryan C. Gordon <icculus@icculus.org>
parents: 1880
diff changeset
419 }
5c6e937518c6 Let Windows OpenGL users use SDL_GL_SWAP_CONTROL even if WGL_ARB_pixel_format
Ryan C. Gordon <icculus@icculus.org>
parents: 1880
diff changeset
420 return -1;
5c6e937518c6 Let Windows OpenGL users use SDL_GL_SWAP_CONTROL even if WGL_ARB_pixel_format
Ryan C. Gordon <icculus@icculus.org>
parents: 1880
diff changeset
421 }
5c6e937518c6 Let Windows OpenGL users use SDL_GL_SWAP_CONTROL even if WGL_ARB_pixel_format
Ryan C. Gordon <icculus@icculus.org>
parents: 1880
diff changeset
422
4042
f9d0b64cc7b9 I think this fixes bug #261
Sam Lantinga <slouken@libsdl.org>
parents: 3937
diff changeset
423 if ( this->gl_data->wglGetPixelFormatAttribivARB ) {
655
9c42ee1b7d77 Date: Thu, 24 Apr 2003 15:13:47 -0400
Sam Lantinga <slouken@libsdl.org>
parents: 453
diff changeset
424 int wgl_attrib;
9c42ee1b7d77 Date: Thu, 24 Apr 2003 15:13:47 -0400
Sam Lantinga <slouken@libsdl.org>
parents: 453
diff changeset
425
9c42ee1b7d77 Date: Thu, 24 Apr 2003 15:13:47 -0400
Sam Lantinga <slouken@libsdl.org>
parents: 453
diff changeset
426 switch(attrib) {
9c42ee1b7d77 Date: Thu, 24 Apr 2003 15:13:47 -0400
Sam Lantinga <slouken@libsdl.org>
parents: 453
diff changeset
427 case SDL_GL_RED_SIZE:
9c42ee1b7d77 Date: Thu, 24 Apr 2003 15:13:47 -0400
Sam Lantinga <slouken@libsdl.org>
parents: 453
diff changeset
428 wgl_attrib = WGL_RED_BITS_ARB;
9c42ee1b7d77 Date: Thu, 24 Apr 2003 15:13:47 -0400
Sam Lantinga <slouken@libsdl.org>
parents: 453
diff changeset
429 break;
9c42ee1b7d77 Date: Thu, 24 Apr 2003 15:13:47 -0400
Sam Lantinga <slouken@libsdl.org>
parents: 453
diff changeset
430 case SDL_GL_GREEN_SIZE:
9c42ee1b7d77 Date: Thu, 24 Apr 2003 15:13:47 -0400
Sam Lantinga <slouken@libsdl.org>
parents: 453
diff changeset
431 wgl_attrib = WGL_GREEN_BITS_ARB;
9c42ee1b7d77 Date: Thu, 24 Apr 2003 15:13:47 -0400
Sam Lantinga <slouken@libsdl.org>
parents: 453
diff changeset
432 break;
9c42ee1b7d77 Date: Thu, 24 Apr 2003 15:13:47 -0400
Sam Lantinga <slouken@libsdl.org>
parents: 453
diff changeset
433 case SDL_GL_BLUE_SIZE:
9c42ee1b7d77 Date: Thu, 24 Apr 2003 15:13:47 -0400
Sam Lantinga <slouken@libsdl.org>
parents: 453
diff changeset
434 wgl_attrib = WGL_BLUE_BITS_ARB;
9c42ee1b7d77 Date: Thu, 24 Apr 2003 15:13:47 -0400
Sam Lantinga <slouken@libsdl.org>
parents: 453
diff changeset
435 break;
9c42ee1b7d77 Date: Thu, 24 Apr 2003 15:13:47 -0400
Sam Lantinga <slouken@libsdl.org>
parents: 453
diff changeset
436 case SDL_GL_ALPHA_SIZE:
9c42ee1b7d77 Date: Thu, 24 Apr 2003 15:13:47 -0400
Sam Lantinga <slouken@libsdl.org>
parents: 453
diff changeset
437 wgl_attrib = WGL_ALPHA_BITS_ARB;
9c42ee1b7d77 Date: Thu, 24 Apr 2003 15:13:47 -0400
Sam Lantinga <slouken@libsdl.org>
parents: 453
diff changeset
438 break;
9c42ee1b7d77 Date: Thu, 24 Apr 2003 15:13:47 -0400
Sam Lantinga <slouken@libsdl.org>
parents: 453
diff changeset
439 case SDL_GL_DOUBLEBUFFER:
9c42ee1b7d77 Date: Thu, 24 Apr 2003 15:13:47 -0400
Sam Lantinga <slouken@libsdl.org>
parents: 453
diff changeset
440 wgl_attrib = WGL_DOUBLE_BUFFER_ARB;
9c42ee1b7d77 Date: Thu, 24 Apr 2003 15:13:47 -0400
Sam Lantinga <slouken@libsdl.org>
parents: 453
diff changeset
441 break;
9c42ee1b7d77 Date: Thu, 24 Apr 2003 15:13:47 -0400
Sam Lantinga <slouken@libsdl.org>
parents: 453
diff changeset
442 case SDL_GL_BUFFER_SIZE:
9c42ee1b7d77 Date: Thu, 24 Apr 2003 15:13:47 -0400
Sam Lantinga <slouken@libsdl.org>
parents: 453
diff changeset
443 wgl_attrib = WGL_COLOR_BITS_ARB;
9c42ee1b7d77 Date: Thu, 24 Apr 2003 15:13:47 -0400
Sam Lantinga <slouken@libsdl.org>
parents: 453
diff changeset
444 break;
9c42ee1b7d77 Date: Thu, 24 Apr 2003 15:13:47 -0400
Sam Lantinga <slouken@libsdl.org>
parents: 453
diff changeset
445 case SDL_GL_DEPTH_SIZE:
9c42ee1b7d77 Date: Thu, 24 Apr 2003 15:13:47 -0400
Sam Lantinga <slouken@libsdl.org>
parents: 453
diff changeset
446 wgl_attrib = WGL_DEPTH_BITS_ARB;
9c42ee1b7d77 Date: Thu, 24 Apr 2003 15:13:47 -0400
Sam Lantinga <slouken@libsdl.org>
parents: 453
diff changeset
447 break;
9c42ee1b7d77 Date: Thu, 24 Apr 2003 15:13:47 -0400
Sam Lantinga <slouken@libsdl.org>
parents: 453
diff changeset
448 case SDL_GL_STENCIL_SIZE:
9c42ee1b7d77 Date: Thu, 24 Apr 2003 15:13:47 -0400
Sam Lantinga <slouken@libsdl.org>
parents: 453
diff changeset
449 wgl_attrib = WGL_STENCIL_BITS_ARB;
9c42ee1b7d77 Date: Thu, 24 Apr 2003 15:13:47 -0400
Sam Lantinga <slouken@libsdl.org>
parents: 453
diff changeset
450 break;
9c42ee1b7d77 Date: Thu, 24 Apr 2003 15:13:47 -0400
Sam Lantinga <slouken@libsdl.org>
parents: 453
diff changeset
451 case SDL_GL_ACCUM_RED_SIZE:
9c42ee1b7d77 Date: Thu, 24 Apr 2003 15:13:47 -0400
Sam Lantinga <slouken@libsdl.org>
parents: 453
diff changeset
452 wgl_attrib = WGL_ACCUM_RED_BITS_ARB;
9c42ee1b7d77 Date: Thu, 24 Apr 2003 15:13:47 -0400
Sam Lantinga <slouken@libsdl.org>
parents: 453
diff changeset
453 break;
9c42ee1b7d77 Date: Thu, 24 Apr 2003 15:13:47 -0400
Sam Lantinga <slouken@libsdl.org>
parents: 453
diff changeset
454 case SDL_GL_ACCUM_GREEN_SIZE:
9c42ee1b7d77 Date: Thu, 24 Apr 2003 15:13:47 -0400
Sam Lantinga <slouken@libsdl.org>
parents: 453
diff changeset
455 wgl_attrib = WGL_ACCUM_GREEN_BITS_ARB;
9c42ee1b7d77 Date: Thu, 24 Apr 2003 15:13:47 -0400
Sam Lantinga <slouken@libsdl.org>
parents: 453
diff changeset
456 break;
9c42ee1b7d77 Date: Thu, 24 Apr 2003 15:13:47 -0400
Sam Lantinga <slouken@libsdl.org>
parents: 453
diff changeset
457 case SDL_GL_ACCUM_BLUE_SIZE:
9c42ee1b7d77 Date: Thu, 24 Apr 2003 15:13:47 -0400
Sam Lantinga <slouken@libsdl.org>
parents: 453
diff changeset
458 wgl_attrib = WGL_ACCUM_BLUE_BITS_ARB;
9c42ee1b7d77 Date: Thu, 24 Apr 2003 15:13:47 -0400
Sam Lantinga <slouken@libsdl.org>
parents: 453
diff changeset
459 break;
9c42ee1b7d77 Date: Thu, 24 Apr 2003 15:13:47 -0400
Sam Lantinga <slouken@libsdl.org>
parents: 453
diff changeset
460 case SDL_GL_ACCUM_ALPHA_SIZE:
9c42ee1b7d77 Date: Thu, 24 Apr 2003 15:13:47 -0400
Sam Lantinga <slouken@libsdl.org>
parents: 453
diff changeset
461 wgl_attrib = WGL_ACCUM_ALPHA_BITS_ARB;
9c42ee1b7d77 Date: Thu, 24 Apr 2003 15:13:47 -0400
Sam Lantinga <slouken@libsdl.org>
parents: 453
diff changeset
462 break;
9c42ee1b7d77 Date: Thu, 24 Apr 2003 15:13:47 -0400
Sam Lantinga <slouken@libsdl.org>
parents: 453
diff changeset
463 case SDL_GL_STEREO:
9c42ee1b7d77 Date: Thu, 24 Apr 2003 15:13:47 -0400
Sam Lantinga <slouken@libsdl.org>
parents: 453
diff changeset
464 wgl_attrib = WGL_STEREO_ARB;
9c42ee1b7d77 Date: Thu, 24 Apr 2003 15:13:47 -0400
Sam Lantinga <slouken@libsdl.org>
parents: 453
diff changeset
465 break;
656
864e2d2a9a55 Merged in Ryan's multisample code for MacOS, and changed the constants to match.
Sam Lantinga <slouken@libsdl.org>
parents: 655
diff changeset
466 case SDL_GL_MULTISAMPLEBUFFERS:
655
9c42ee1b7d77 Date: Thu, 24 Apr 2003 15:13:47 -0400
Sam Lantinga <slouken@libsdl.org>
parents: 453
diff changeset
467 wgl_attrib = WGL_SAMPLE_BUFFERS_ARB;
9c42ee1b7d77 Date: Thu, 24 Apr 2003 15:13:47 -0400
Sam Lantinga <slouken@libsdl.org>
parents: 453
diff changeset
468 break;
656
864e2d2a9a55 Merged in Ryan's multisample code for MacOS, and changed the constants to match.
Sam Lantinga <slouken@libsdl.org>
parents: 655
diff changeset
469 case SDL_GL_MULTISAMPLESAMPLES:
655
9c42ee1b7d77 Date: Thu, 24 Apr 2003 15:13:47 -0400
Sam Lantinga <slouken@libsdl.org>
parents: 453
diff changeset
470 wgl_attrib = WGL_SAMPLES_ARB;
9c42ee1b7d77 Date: Thu, 24 Apr 2003 15:13:47 -0400
Sam Lantinga <slouken@libsdl.org>
parents: 453
diff changeset
471 break;
1737
eacc5bc01d1c Implemented bug #5
Sam Lantinga <slouken@libsdl.org>
parents: 1736
diff changeset
472 case SDL_GL_ACCELERATED_VISUAL:
eacc5bc01d1c Implemented bug #5
Sam Lantinga <slouken@libsdl.org>
parents: 1736
diff changeset
473 wgl_attrib = WGL_ACCELERATION_ARB;
eacc5bc01d1c Implemented bug #5
Sam Lantinga <slouken@libsdl.org>
parents: 1736
diff changeset
474 this->gl_data->wglGetPixelFormatAttribivARB(GL_hdc, pixel_format, 0, 1, &wgl_attrib, value);
eacc5bc01d1c Implemented bug #5
Sam Lantinga <slouken@libsdl.org>
parents: 1736
diff changeset
475 if ( *value == WGL_NO_ACCELERATION_ARB ) {
eacc5bc01d1c Implemented bug #5
Sam Lantinga <slouken@libsdl.org>
parents: 1736
diff changeset
476 *value = SDL_FALSE;
eacc5bc01d1c Implemented bug #5
Sam Lantinga <slouken@libsdl.org>
parents: 1736
diff changeset
477 } else {
eacc5bc01d1c Implemented bug #5
Sam Lantinga <slouken@libsdl.org>
parents: 1736
diff changeset
478 *value = SDL_TRUE;
eacc5bc01d1c Implemented bug #5
Sam Lantinga <slouken@libsdl.org>
parents: 1736
diff changeset
479 }
eacc5bc01d1c Implemented bug #5
Sam Lantinga <slouken@libsdl.org>
parents: 1736
diff changeset
480 return 0;
655
9c42ee1b7d77 Date: Thu, 24 Apr 2003 15:13:47 -0400
Sam Lantinga <slouken@libsdl.org>
parents: 453
diff changeset
481 default:
9c42ee1b7d77 Date: Thu, 24 Apr 2003 15:13:47 -0400
Sam Lantinga <slouken@libsdl.org>
parents: 453
diff changeset
482 return(-1);
9c42ee1b7d77 Date: Thu, 24 Apr 2003 15:13:47 -0400
Sam Lantinga <slouken@libsdl.org>
parents: 453
diff changeset
483 }
9c42ee1b7d77 Date: Thu, 24 Apr 2003 15:13:47 -0400
Sam Lantinga <slouken@libsdl.org>
parents: 453
diff changeset
484 this->gl_data->wglGetPixelFormatAttribivARB(GL_hdc, pixel_format, 0, 1, &wgl_attrib, value);
9c42ee1b7d77 Date: Thu, 24 Apr 2003 15:13:47 -0400
Sam Lantinga <slouken@libsdl.org>
parents: 453
diff changeset
485
9c42ee1b7d77 Date: Thu, 24 Apr 2003 15:13:47 -0400
Sam Lantinga <slouken@libsdl.org>
parents: 453
diff changeset
486 return 0;
9c42ee1b7d77 Date: Thu, 24 Apr 2003 15:13:47 -0400
Sam Lantinga <slouken@libsdl.org>
parents: 453
diff changeset
487 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
488
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
489 retval = 0;
655
9c42ee1b7d77 Date: Thu, 24 Apr 2003 15:13:47 -0400
Sam Lantinga <slouken@libsdl.org>
parents: 453
diff changeset
490 switch ( attrib ) {
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
491 case SDL_GL_RED_SIZE:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
492 *value = GL_pfd.cRedBits;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
493 break;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
494 case SDL_GL_GREEN_SIZE:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
495 *value = GL_pfd.cGreenBits;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
496 break;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
497 case SDL_GL_BLUE_SIZE:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
498 *value = GL_pfd.cBlueBits;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
499 break;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
500 case SDL_GL_ALPHA_SIZE:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
501 *value = GL_pfd.cAlphaBits;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
502 break;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
503 case SDL_GL_DOUBLEBUFFER:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
504 if ( GL_pfd.dwFlags & PFD_DOUBLEBUFFER ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
505 *value = 1;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
506 } else {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
507 *value = 0;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
508 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
509 break;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
510 case SDL_GL_BUFFER_SIZE:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
511 *value = GL_pfd.cColorBits;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
512 break;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
513 case SDL_GL_DEPTH_SIZE:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
514 *value = GL_pfd.cDepthBits;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
515 break;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
516 case SDL_GL_STENCIL_SIZE:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
517 *value = GL_pfd.cStencilBits;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
518 break;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
519 case SDL_GL_ACCUM_RED_SIZE:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
520 *value = GL_pfd.cAccumRedBits;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
521 break;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
522 case SDL_GL_ACCUM_GREEN_SIZE:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
523 *value = GL_pfd.cAccumGreenBits;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
524 break;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
525 case SDL_GL_ACCUM_BLUE_SIZE:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
526 *value = GL_pfd.cAccumBlueBits;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
527 break;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
528 case SDL_GL_ACCUM_ALPHA_SIZE:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
529 *value = GL_pfd.cAccumAlphaBits;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
530 break;
450
8a43e0cbf02f Added SDL_GL_STEREO for stereoscopic OpenGL contexts
Sam Lantinga <slouken@libsdl.org>
parents: 373
diff changeset
531 case SDL_GL_STEREO:
8a43e0cbf02f Added SDL_GL_STEREO for stereoscopic OpenGL contexts
Sam Lantinga <slouken@libsdl.org>
parents: 373
diff changeset
532 if ( GL_pfd.dwFlags & PFD_STEREO ) {
8a43e0cbf02f Added SDL_GL_STEREO for stereoscopic OpenGL contexts
Sam Lantinga <slouken@libsdl.org>
parents: 373
diff changeset
533 *value = 1;
8a43e0cbf02f Added SDL_GL_STEREO for stereoscopic OpenGL contexts
Sam Lantinga <slouken@libsdl.org>
parents: 373
diff changeset
534 } else {
8a43e0cbf02f Added SDL_GL_STEREO for stereoscopic OpenGL contexts
Sam Lantinga <slouken@libsdl.org>
parents: 373
diff changeset
535 *value = 0;
8a43e0cbf02f Added SDL_GL_STEREO for stereoscopic OpenGL contexts
Sam Lantinga <slouken@libsdl.org>
parents: 373
diff changeset
536 }
8a43e0cbf02f Added SDL_GL_STEREO for stereoscopic OpenGL contexts
Sam Lantinga <slouken@libsdl.org>
parents: 373
diff changeset
537 break;
1261
031e093ba2a5 Date: Thu, 04 Sep 2003 02:12:35 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 889
diff changeset
538 case SDL_GL_MULTISAMPLEBUFFERS:
031e093ba2a5 Date: Thu, 04 Sep 2003 02:12:35 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 889
diff changeset
539 *value = 0;
031e093ba2a5 Date: Thu, 04 Sep 2003 02:12:35 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 889
diff changeset
540 break;
031e093ba2a5 Date: Thu, 04 Sep 2003 02:12:35 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 889
diff changeset
541 case SDL_GL_MULTISAMPLESAMPLES:
031e093ba2a5 Date: Thu, 04 Sep 2003 02:12:35 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 889
diff changeset
542 *value = 1;
031e093ba2a5 Date: Thu, 04 Sep 2003 02:12:35 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 889
diff changeset
543 break;
1880
9d940db55a91 Fixed bug #260
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
544 case SDL_GL_SWAP_CONTROL:
9d940db55a91 Fixed bug #260
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
545 if ( this->gl_data->wglGetSwapIntervalEXT ) {
9d940db55a91 Fixed bug #260
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
546 *value = this->gl_data->wglGetSwapIntervalEXT();
9d940db55a91 Fixed bug #260
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
547 return 0;
9d940db55a91 Fixed bug #260
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
548 } else {
9d940db55a91 Fixed bug #260
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
549 return -1;
9d940db55a91 Fixed bug #260
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
550 }
9d940db55a91 Fixed bug #260
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
551 break;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
552 default:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
553 retval = -1;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
554 break;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
555 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
556 return retval;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
557 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
558
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
559 void WIN_GL_SwapBuffers(_THIS)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
560 {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
561 SwapBuffers(GL_hdc);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
562 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
563
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
564 void WIN_GL_UnloadLibrary(_THIS)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
565 {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
566 if ( this->gl_config.driver_loaded ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
567 FreeLibrary((HMODULE)this->gl_config.dll_handle);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
568
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
569 this->gl_data->wglGetProcAddress = NULL;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
570 this->gl_data->wglCreateContext = NULL;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
571 this->gl_data->wglDeleteContext = NULL;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
572 this->gl_data->wglMakeCurrent = NULL;
655
9c42ee1b7d77 Date: Thu, 24 Apr 2003 15:13:47 -0400
Sam Lantinga <slouken@libsdl.org>
parents: 453
diff changeset
573 this->gl_data->wglGetPixelFormatAttribivARB = NULL;
1736
3b2a92126f4d Implemented bug #2, 117:
Sam Lantinga <slouken@libsdl.org>
parents: 1527
diff changeset
574 this->gl_data->wglSwapIntervalEXT = NULL;
3b2a92126f4d Implemented bug #2, 117:
Sam Lantinga <slouken@libsdl.org>
parents: 1527
diff changeset
575 this->gl_data->wglGetSwapIntervalEXT = NULL;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
576
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
577 this->gl_config.dll_handle = NULL;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
578 this->gl_config.driver_loaded = 0;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
579 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
580 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
581
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
582 /* Passing a NULL path means load pointers from the application */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
583 int WIN_GL_LoadLibrary(_THIS, const char* path)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
584 {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
585 HMODULE handle;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
586
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
587 if ( gl_active ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
588 SDL_SetError("OpenGL context already created");
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
589 return -1;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
590 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
591
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
592 if ( path == NULL ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
593 path = DEFAULT_GL_DRIVER_PATH;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
594 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
595 handle = LoadLibrary(path);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
596 if ( handle == NULL ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
597 SDL_SetError("Could not load OpenGL library");
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
598 return -1;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
599 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
600
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
601 /* Unload the old driver and reset the pointers */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
602 WIN_GL_UnloadLibrary(this);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
603
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
604 /* Load new function pointers */
1336
3692456e7b0f Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents: 1330
diff changeset
605 SDL_memset(this->gl_data, 0, sizeof(*this->gl_data));
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
606 this->gl_data->wglGetProcAddress = (void * (WINAPI *)(const char *))
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
607 GetProcAddress(handle, "wglGetProcAddress");
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
608 this->gl_data->wglCreateContext = (HGLRC (WINAPI *)(HDC))
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
609 GetProcAddress(handle, "wglCreateContext");
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
610 this->gl_data->wglDeleteContext = (BOOL (WINAPI *)(HGLRC))
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
611 GetProcAddress(handle, "wglDeleteContext");
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
612 this->gl_data->wglMakeCurrent = (BOOL (WINAPI *)(HDC, HGLRC))
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
613 GetProcAddress(handle, "wglMakeCurrent");
1736
3b2a92126f4d Implemented bug #2, 117:
Sam Lantinga <slouken@libsdl.org>
parents: 1527
diff changeset
614 this->gl_data->wglSwapIntervalEXT = (void (WINAPI *)(int))
3b2a92126f4d Implemented bug #2, 117:
Sam Lantinga <slouken@libsdl.org>
parents: 1527
diff changeset
615 GetProcAddress(handle, "wglSwapIntervalEXT");
3b2a92126f4d Implemented bug #2, 117:
Sam Lantinga <slouken@libsdl.org>
parents: 1527
diff changeset
616 this->gl_data->wglGetSwapIntervalEXT = (int (WINAPI *)(void))
3b2a92126f4d Implemented bug #2, 117:
Sam Lantinga <slouken@libsdl.org>
parents: 1527
diff changeset
617 GetProcAddress(handle, "wglGetSwapIntervalEXT");
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
618
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
619 if ( (this->gl_data->wglGetProcAddress == NULL) ||
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
620 (this->gl_data->wglCreateContext == NULL) ||
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
621 (this->gl_data->wglDeleteContext == NULL) ||
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
622 (this->gl_data->wglMakeCurrent == NULL) ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
623 SDL_SetError("Could not retrieve OpenGL functions");
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
624 FreeLibrary(handle);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
625 return -1;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
626 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
627
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
628 this->gl_config.dll_handle = handle;
1379
c0a74f199ecf Use only safe string functions
Sam Lantinga <slouken@libsdl.org>
parents: 1361
diff changeset
629 SDL_strlcpy(this->gl_config.driver_path, path, SDL_arraysize(this->gl_config.driver_path));
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
630 this->gl_config.driver_loaded = 1;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
631 return 0;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
632 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
633
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
634 void *WIN_GL_GetProcAddress(_THIS, const char* proc)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
635 {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
636 void *func;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
637
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
638 /* This is to pick up extensions */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
639 func = this->gl_data->wglGetProcAddress(proc);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
640 if ( ! func ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
641 /* This is probably a normal GL function */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
642 func = GetProcAddress(this->gl_config.dll_handle, proc);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
643 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
644 return func;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
645 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
646
1361
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents: 1358
diff changeset
647 #endif /* SDL_VIDEO_OPENGL */