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 ; /* ????? */
145 case GLUT_WINDOW_STENCIL_SIZE:
146 returnValue = 0 ; /* ????? */
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 #endif /* defined(_WIN32_WCE) */
190 case GLUT_WINDOW_X: return winRect.left ;
191 case GLUT_WINDOW_Y: return winRect.top ;
192 case GLUT_WINDOW_WIDTH: return winRect.right - winRect.left;
193 case GLUT_WINDOW_HEIGHT: return winRect.bottom - winRect.top;
198 case GLUT_WINDOW_BORDER_WIDTH :
199 case GLUT_WINDOW_HEADER_HEIGHT :
200 #if defined(_WIN32_WCE)
206 if (fgStructure.CurrentWindow && fgStructure.CurrentWindow->Window.Handle)
207 windowStyle = GetWindowLong(fgStructure.CurrentWindow->Window.Handle, GWL_STYLE);
209 /* If no window, return sizes for a default window with title bar and border */
210 windowStyle = WS_OVERLAPPEDWINDOW;
214 case GLUT_WINDOW_BORDER_WIDTH:
216 int xBorderWidth, yBorderWidth;
217 fghGetBorderWidth(windowStyle, &xBorderWidth, &yBorderWidth);
220 case GLUT_WINDOW_HEADER_HEIGHT:
221 /* 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... */
222 return (windowStyle & WS_MAXIMIZEBOX)? GetSystemMetrics( SM_CYCAPTION ) : 0;
225 #endif /* defined(_WIN32_WCE) */
227 case GLUT_DISPLAY_MODE_POSSIBLE:
228 #if defined(_WIN32_WCE)
231 return fgSetupPixelFormat( fgStructure.CurrentWindow, GL_TRUE,
233 #endif /* defined(_WIN32_WCE) */
236 case GLUT_WINDOW_FORMAT_ID:
237 #if !defined(_WIN32_WCE)
238 if( fgStructure.CurrentWindow != NULL )
239 return GetPixelFormat( fgStructure.CurrentWindow->Window.pContext.Device );
240 #endif /* defined(_WIN32_WCE) */
244 fgWarning( "glutGet(): missing enum handle %d", eWhat );
252 int fgPlatformGlutDeviceGet ( GLenum eWhat )
256 case GLUT_HAS_KEYBOARD:
258 * Win32 is assumed a keyboard, and this cannot be queried,
259 * except for WindowsCE.
261 #if defined(_WIN32_CE)
262 return ( GetKeyboardStatus() & KBDI_KEYBOARD_PRESENT ) ? 1 : 0;
263 # if FREEGLUT_LIB_PRAGMAS
264 # pragma comment (lib,"Kbdui.lib")
273 * MS Windows can be booted without a mouse.
275 return GetSystemMetrics( SM_MOUSEPRESENT );
277 case GLUT_NUM_MOUSE_BUTTONS:
278 # if defined(_WIN32_WCE)
281 return GetSystemMetrics( SM_CMOUSEBUTTONS );
285 fgWarning( "glutDeviceGet(): missing enum handle %d", eWhat );
289 /* And now -- the failure. */
294 * This is for querying the number of supported auxiliary or multisample
295 * buffers for a (the current?) display mode.
296 * see http://old.nabble.com/-GLX--glutGetModeValues-to13514723.html#a13514723
297 * Not currently implemented, but we should be able to query the relevant
299 * http://www.opengl.org/registry/specs/ARB/wgl_pixel_format.txt
300 * (if supported on the executing machine!)
302 int *fgPlatformGlutGetModeValues(GLenum eWhat, int *size)