2 * freeglut_state_mswin.c
4 * The Windows-specific state query methods.
6 * Copyright (c) 2012 Stephen J. Baker. All Rights Reserved.
7 * Written by John F. Fay, <fayjf@sourceforge.net>
8 * Creation date: Sun Jan 22, 2012
10 * Permission is hereby granted, free of charge, to any person obtaining a
11 * copy of this software and associated documentation files (the "Software"),
12 * to deal in the Software without restriction, including without limitation
13 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
14 * and/or sell copies of the Software, and to permit persons to whom the
15 * Software is furnished to do so, subject to the following conditions:
17 * The above copyright notice and this permission notice shall be included
18 * in all copies or substantial portions of the Software.
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
23 * PAWEL W. OLSZTA BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
24 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
25 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 #include <GL/freeglut.h>
29 #include "../fg_internal.h"
32 extern GLboolean fgSetupPixelFormat( SFG_Window* window, GLboolean checkOnly,
33 unsigned char layer_type );
36 * Helper functions for getting client area from the window rect
37 * and the window rect from the client area given the style of the window
38 * (or a valid window pointer from which the style can be queried).
40 extern RECT fghGetClientArea( const SFG_Window *window, BOOL wantPosOutside );
41 extern void fghGetBorderWidth(const DWORD windowStyle, int* xBorderWidth, int* yBorderWidth);
44 /* The following include file is available from SGI but is not standard:
45 * #include <GL/wglext.h>
46 * So we copy the necessary parts out of it to support the multisampling query
48 #define WGL_SAMPLES_ARB 0x2042
50 #if defined(_WIN32_WCE)
51 # include <Aygshell.h>
52 # ifdef FREEGLUT_LIB_PRAGMAS
53 # pragma comment( lib, "Aygshell.lib" )
55 #endif /* defined(_WIN32_WCE) */
59 int fgPlatformGlutGet ( GLenum eWhat )
68 case GLUT_WINDOW_NUM_SAMPLES:
69 glGetIntegerv(WGL_SAMPLES_ARB, &nsamples);
72 /* Handle the OpenGL inquiries */
73 case GLUT_WINDOW_RGBA:
74 #if defined(_WIN32_WCE)
75 boolValue = (GLboolean)0; /* WinCE doesn't support this feature */
77 glGetBooleanv ( GL_RGBA_MODE, &boolValue );
78 returnValue = boolValue ? 1 : 0;
81 case GLUT_WINDOW_DOUBLEBUFFER:
82 #if defined(_WIN32_WCE)
83 boolValue = (GLboolean)0; /* WinCE doesn't support this feature */
85 glGetBooleanv ( GL_DOUBLEBUFFER, &boolValue );
86 returnValue = boolValue ? 1 : 0;
89 case GLUT_WINDOW_STEREO:
90 #if defined(_WIN32_WCE)
91 boolValue = (GLboolean)0; /* WinCE doesn't support this feature */
93 glGetBooleanv ( GL_STEREO, &boolValue );
94 returnValue = boolValue ? 1 : 0;
98 case GLUT_WINDOW_RED_SIZE:
99 glGetIntegerv ( GL_RED_BITS, &returnValue );
101 case GLUT_WINDOW_GREEN_SIZE:
102 glGetIntegerv ( GL_GREEN_BITS, &returnValue );
104 case GLUT_WINDOW_BLUE_SIZE:
105 glGetIntegerv ( GL_BLUE_BITS, &returnValue );
107 case GLUT_WINDOW_ALPHA_SIZE:
108 glGetIntegerv ( GL_ALPHA_BITS, &returnValue );
110 case GLUT_WINDOW_ACCUM_RED_SIZE:
111 #if defined(_WIN32_WCE)
112 returnValue = 0; /* WinCE doesn't support this feature */
114 glGetIntegerv ( GL_ACCUM_RED_BITS, &returnValue );
117 case GLUT_WINDOW_ACCUM_GREEN_SIZE:
118 #if defined(_WIN32_WCE)
119 returnValue = 0; /* WinCE doesn't support this feature */
121 glGetIntegerv ( GL_ACCUM_GREEN_BITS, &returnValue );
124 case GLUT_WINDOW_ACCUM_BLUE_SIZE:
125 #if defined(_WIN32_WCE)
126 returnValue = 0; /* WinCE doesn't support this feature */
128 glGetIntegerv ( GL_ACCUM_BLUE_BITS, &returnValue );
131 case GLUT_WINDOW_ACCUM_ALPHA_SIZE:
132 #if defined(_WIN32_WCE)
133 returnValue = 0; /* WinCE doesn't support this feature */
135 glGetIntegerv ( GL_ACCUM_ALPHA_BITS, &returnValue );
138 case GLUT_WINDOW_DEPTH_SIZE:
139 glGetIntegerv ( GL_DEPTH_BITS, &returnValue );
142 case GLUT_WINDOW_BUFFER_SIZE:
143 returnValue = 1 ; /* TODO????? */
145 case GLUT_WINDOW_STENCIL_SIZE:
146 returnValue = 0 ; /* TODO????? */
151 case GLUT_WINDOW_WIDTH:
152 case GLUT_WINDOW_HEIGHT:
155 * There is considerable confusion about the "right thing to
156 * do" concerning window size and position. GLUT itself is
157 * not consistent between Windows and UNIX/X11; since
158 * platform independence is a virtue for "freeglut", we
159 * decided to break with GLUT's behaviour.
161 * Under UNIX/X11, it is apparently not possible to get the
162 * window border sizes in order to subtract them off the
163 * window's initial position until some time after the window
164 * has been created. Therefore we decided on the following
165 * behaviour, both under Windows and under UNIX/X11:
166 * - When you create a window with position (x,y) and size
167 * (w,h), the upper left hand corner of the outside of the
168 * window is at (x,y) and the size of the drawable area is
170 * - When you query the size and position of the window--as
171 * is happening here for Windows--"freeglut" will return
172 * the size of the drawable area--the (w,h) that you
173 * specified when you created the window--and the coordinates
174 * of the upper left hand corner of the drawable
175 * area--which is NOT the (x,y) you specified.
180 freeglut_return_val_if_fail( fgStructure.CurrentWindow != NULL, 0 );
182 #if defined(_WIN32_WCE)
183 GetWindowRect( fgStructure.CurrentWindow->Window.Handle, &winRect );
185 winRect = fghGetClientArea(fgStructure.CurrentWindow, FALSE);
186 if (fgStructure.CurrentWindow->Parent && (eWhat==GLUT_WINDOW_X || eWhat==GLUT_WINDOW_Y))
188 /* For child window, we should return relative to upper-left
189 * of parent's client area.
192 topleft.x = winRect.left;
193 topleft.y = winRect.top;
195 ScreenToClient(fgStructure.CurrentWindow->Parent->Window.Handle,&topleft);
196 winRect.left = topleft.x;
197 winRect.top = topleft.y;
199 #endif /* defined(_WIN32_WCE) */
203 case GLUT_WINDOW_X: return winRect.left ;
204 case GLUT_WINDOW_Y: return winRect.top ;
205 case GLUT_WINDOW_WIDTH: return winRect.right - winRect.left;
206 case GLUT_WINDOW_HEIGHT: return winRect.bottom - winRect.top;
211 case GLUT_WINDOW_BORDER_WIDTH :
212 case GLUT_WINDOW_HEADER_HEIGHT :
213 #if defined(_WIN32_WCE)
219 if (fgStructure.CurrentWindow && fgStructure.CurrentWindow->Window.Handle)
220 windowStyle = GetWindowLong(fgStructure.CurrentWindow->Window.Handle, GWL_STYLE);
222 /* If no window, return sizes for a default window with title bar and border */
223 windowStyle = WS_OVERLAPPEDWINDOW;
227 case GLUT_WINDOW_BORDER_WIDTH:
229 int xBorderWidth, yBorderWidth;
230 fghGetBorderWidth(windowStyle, &xBorderWidth, &yBorderWidth);
233 case GLUT_WINDOW_HEADER_HEIGHT:
234 /* Need to query for WS_MAXIMIZEBOX to see if we have a title bar, the WS_CAPTION query is also true for a WS_DLGFRAME only... */
235 return (windowStyle & WS_MAXIMIZEBOX)? GetSystemMetrics( SM_CYCAPTION ) : 0;
238 #endif /* defined(_WIN32_WCE) */
240 case GLUT_DISPLAY_MODE_POSSIBLE:
241 #if defined(_WIN32_WCE)
244 return fgSetupPixelFormat( fgStructure.CurrentWindow, GL_TRUE,
246 #endif /* defined(_WIN32_WCE) */
249 case GLUT_WINDOW_FORMAT_ID:
250 #if !defined(_WIN32_WCE)
251 if( fgStructure.CurrentWindow != NULL )
252 return GetPixelFormat( fgStructure.CurrentWindow->Window.pContext.Device );
253 #endif /* defined(_WIN32_WCE) */
257 fgWarning( "glutGet(): missing enum handle %d", eWhat );
265 int fgPlatformGlutDeviceGet ( GLenum eWhat )
269 case GLUT_HAS_KEYBOARD:
271 * Win32 is assumed a keyboard, and this cannot be queried,
272 * except for WindowsCE.
274 #if defined(_WIN32_CE)
275 return ( GetKeyboardStatus() & KBDI_KEYBOARD_PRESENT ) ? 1 : 0;
276 # if FREEGLUT_LIB_PRAGMAS
277 # pragma comment (lib,"Kbdui.lib")
286 * MS Windows can be booted without a mouse.
288 return GetSystemMetrics( SM_MOUSEPRESENT );
290 case GLUT_NUM_MOUSE_BUTTONS:
291 # if defined(_WIN32_WCE)
294 return GetSystemMetrics( SM_CMOUSEBUTTONS );
298 fgWarning( "glutDeviceGet(): missing enum handle %d", eWhat );
302 /* And now -- the failure. */
307 * This is for querying the number of supported auxiliary or multisample
308 * buffers for a (the current?) display mode.
309 * see http://old.nabble.com/-GLX--glutGetModeValues-to13514723.html#a13514723
310 * Not currently implemented, but we should be able to query the relevant
312 * http://www.opengl.org/registry/specs/ARB/wgl_pixel_format.txt
313 * (if supported on the executing machine!)
315 int *fgPlatformGlutGetModeValues(GLenum eWhat, int *size)