2 * freeglut_state_mswin.c
\r
4 * The Windows-specific mouse cursor related stuff.
\r
6 * Copyright (c) 2012 Stephen J. Baker. All Rights Reserved.
\r
7 * Written by John F. Fay, <fayjf@sourceforge.net>
\r
8 * Creation date: Sun Jan 22, 2012
\r
10 * Permission is hereby granted, free of charge, to any person obtaining a
\r
11 * copy of this software and associated documentation files (the "Software"),
\r
12 * to deal in the Software without restriction, including without limitation
\r
13 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
\r
14 * and/or sell copies of the Software, and to permit persons to whom the
\r
15 * Software is furnished to do so, subject to the following conditions:
\r
17 * The above copyright notice and this permission notice shall be included
\r
18 * in all copies or substantial portions of the Software.
\r
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
\r
21 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
\r
22 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
\r
23 * PAWEL W. OLSZTA BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
\r
24 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
\r
25 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\r
28 #include <GL/freeglut.h>
\r
29 #include "freeglut_internal_mswin.h"
\r
33 /* The following include file is available from SGI but is not standard:
\r
34 * #include <GL/wglext.h>
\r
35 * So we copy the necessary parts out of it to support the multisampling query
\r
37 #define WGL_SAMPLES_ARB 0x2042
\r
41 int fgPlatformGlutGet ( GLenum eWhat )
\r
44 GLboolean boolValue ;
\r
50 case GLUT_WINDOW_NUM_SAMPLES:
\r
51 glGetIntegerv(WGL_SAMPLES_ARB, &nsamples);
\r
54 /* Handle the OpenGL inquiries */
\r
55 case GLUT_WINDOW_RGBA:
\r
56 #if defined(_WIN32_WCE)
\r
57 boolValue = (GLboolean)0; /* WinCE doesn't support this feature */
\r
59 glGetBooleanv ( GL_RGBA_MODE, &boolValue );
\r
60 returnValue = boolValue ? 1 : 0;
\r
63 case GLUT_WINDOW_DOUBLEBUFFER:
\r
64 #if defined(_WIN32_WCE)
\r
65 boolValue = (GLboolean)0; /* WinCE doesn't support this feature */
\r
67 glGetBooleanv ( GL_DOUBLEBUFFER, &boolValue );
\r
68 returnValue = boolValue ? 1 : 0;
\r
71 case GLUT_WINDOW_STEREO:
\r
72 #if defined(_WIN32_WCE)
\r
73 boolValue = (GLboolean)0; /* WinCE doesn't support this feature */
\r
75 glGetBooleanv ( GL_STEREO, &boolValue );
\r
76 returnValue = boolValue ? 1 : 0;
\r
80 case GLUT_WINDOW_RED_SIZE:
\r
81 glGetIntegerv ( GL_RED_BITS, &returnValue );
\r
83 case GLUT_WINDOW_GREEN_SIZE:
\r
84 glGetIntegerv ( GL_GREEN_BITS, &returnValue );
\r
86 case GLUT_WINDOW_BLUE_SIZE:
\r
87 glGetIntegerv ( GL_BLUE_BITS, &returnValue );
\r
89 case GLUT_WINDOW_ALPHA_SIZE:
\r
90 glGetIntegerv ( GL_ALPHA_BITS, &returnValue );
\r
92 case GLUT_WINDOW_ACCUM_RED_SIZE:
\r
93 #if defined(_WIN32_WCE)
\r
94 returnValue = 0; /* WinCE doesn't support this feature */
\r
96 glGetIntegerv ( GL_ACCUM_RED_BITS, &returnValue );
\r
99 case GLUT_WINDOW_ACCUM_GREEN_SIZE:
\r
100 #if defined(_WIN32_WCE)
\r
101 returnValue = 0; /* WinCE doesn't support this feature */
\r
103 glGetIntegerv ( GL_ACCUM_GREEN_BITS, &returnValue );
\r
105 return returnValue;
\r
106 case GLUT_WINDOW_ACCUM_BLUE_SIZE:
\r
107 #if defined(_WIN32_WCE)
\r
108 returnValue = 0; /* WinCE doesn't support this feature */
\r
110 glGetIntegerv ( GL_ACCUM_BLUE_BITS, &returnValue );
\r
112 return returnValue;
\r
113 case GLUT_WINDOW_ACCUM_ALPHA_SIZE:
\r
114 #if defined(_WIN32_WCE)
\r
115 returnValue = 0; /* WinCE doesn't support this feature */
\r
117 glGetIntegerv ( GL_ACCUM_ALPHA_BITS, &returnValue );
\r
119 return returnValue;
\r
120 case GLUT_WINDOW_DEPTH_SIZE:
\r
121 glGetIntegerv ( GL_DEPTH_BITS, &returnValue );
\r
122 return returnValue;
\r
124 case GLUT_WINDOW_BUFFER_SIZE:
\r
125 returnValue = 1 ; /* ????? */
\r
126 return returnValue;
\r
127 case GLUT_WINDOW_STENCIL_SIZE:
\r
128 returnValue = 0 ; /* ????? */
\r
129 return returnValue;
\r
131 case GLUT_WINDOW_X:
\r
132 case GLUT_WINDOW_Y:
\r
133 case GLUT_WINDOW_WIDTH:
\r
134 case GLUT_WINDOW_HEIGHT:
\r
137 * There is considerable confusion about the "right thing to
\r
138 * do" concerning window size and position. GLUT itself is
\r
139 * not consistent between Windows and UNIX/X11; since
\r
140 * platform independence is a virtue for "freeglut", we
\r
141 * decided to break with GLUT's behaviour.
\r
143 * Under UNIX/X11, it is apparently not possible to get the
\r
144 * window border sizes in order to subtract them off the
\r
145 * window's initial position until some time after the window
\r
146 * has been created. Therefore we decided on the following
\r
147 * behaviour, both under Windows and under UNIX/X11:
\r
148 * - When you create a window with position (x,y) and size
\r
149 * (w,h), the upper left hand corner of the outside of the
\r
150 * window is at (x,y) and the size of the drawable area is
\r
152 * - When you query the size and position of the window--as
\r
153 * is happening here for Windows--"freeglut" will return
\r
154 * the size of the drawable area--the (w,h) that you
\r
155 * specified when you created the window--and the coordinates
\r
156 * of the upper left hand corner of the drawable
\r
157 * area--which is NOT the (x,y) you specified.
\r
162 freeglut_return_val_if_fail( fgStructure.CurrentWindow != NULL, 0 );
\r
164 #if defined(_WIN32_WCE)
\r
165 GetWindowRect( fgStructure.CurrentWindow->Window.Handle, &winRect );
\r
167 winRect = fghGetClientArea(fgStructure.CurrentWindow, FALSE);
\r
168 #endif /* defined(_WIN32_WCE) */
\r
172 case GLUT_WINDOW_X: return winRect.left ;
\r
173 case GLUT_WINDOW_Y: return winRect.top ;
\r
174 case GLUT_WINDOW_WIDTH: return winRect.right - winRect.left;
\r
175 case GLUT_WINDOW_HEIGHT: return winRect.bottom - winRect.top;
\r
180 case GLUT_WINDOW_BORDER_WIDTH :
\r
181 case GLUT_WINDOW_HEADER_HEIGHT :
\r
182 #if defined(_WIN32_WCE)
\r
188 if (fgStructure.CurrentWindow && fgStructure.CurrentWindow->Window.Handle)
\r
189 windowStyle = GetWindowLong(fgStructure.CurrentWindow->Window.Handle, GWL_STYLE);
\r
191 /* If no window, return sizes for a default window with title bar and border */
\r
192 windowStyle = WS_OVERLAPPEDWINDOW;
\r
196 case GLUT_WINDOW_BORDER_WIDTH:
\r
198 int xBorderWidth, yBorderWidth;
\r
199 fghGetBorderWidth(windowStyle, &xBorderWidth, &yBorderWidth);
\r
200 return xBorderWidth;
\r
202 case GLUT_WINDOW_HEADER_HEIGHT:
\r
203 /* 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... */
\r
204 return (windowStyle & WS_MAXIMIZEBOX)? GetSystemMetrics( SM_CYCAPTION ) : 0;
\r
207 #endif /* defined(_WIN32_WCE) */
\r
209 case GLUT_DISPLAY_MODE_POSSIBLE:
\r
210 #if defined(_WIN32_WCE)
\r
213 return fgSetupPixelFormat( fgStructure.CurrentWindow, GL_TRUE,
\r
215 #endif /* defined(_WIN32_WCE) */
\r
218 case GLUT_WINDOW_FORMAT_ID:
\r
219 #if !defined(_WIN32_WCE)
\r
220 if( fgStructure.CurrentWindow != NULL )
\r
221 return GetPixelFormat( fgStructure.CurrentWindow->Window.Device );
\r
222 #endif /* defined(_WIN32_WCE) */
\r
226 fgWarning( "glutGet(): missing enum handle %d", eWhat );
\r
234 int fgPlatformGlutDeviceGet ( GLenum eWhat )
\r
238 case GLUT_HAS_KEYBOARD:
\r
240 * Win32 is assumed a keyboard, and this cannot be queried,
\r
241 * except for WindowsCE.
\r
243 * X11 has a core keyboard by definition, although it can
\r
244 * be present as a virtual/dummy keyboard. For now, there
\r
245 * is no reliable way to tell if a real keyboard is present.
\r
247 #if defined(_WIN32_CE)
\r
248 return ( GetKeyboardStatus() & KBDI_KEYBOARD_PRESENT ) ? 1 : 0;
\r
249 # if FREEGLUT_LIB_PRAGMAS
\r
250 # pragma comment (lib,"Kbdui.lib")
\r
257 case GLUT_HAS_MOUSE:
\r
259 * MS Windows can be booted without a mouse.
\r
261 return GetSystemMetrics( SM_MOUSEPRESENT );
\r
263 case GLUT_NUM_MOUSE_BUTTONS:
\r
264 # if defined(_WIN32_WCE)
\r
267 return GetSystemMetrics( SM_CMOUSEBUTTONS );
\r
271 fgWarning( "glutDeviceGet(): missing enum handle %d", eWhat );
\r
275 /* And now -- the failure. */
\r
280 int fgPlatformGlutLayerGet( GLenum eWhat )
\r
283 * This is easy as layers are not implemented ;-)
\r
285 * XXX Can we merge the UNIX/X11 and WIN32 sections? Or
\r
286 * XXX is overlay support planned?
\r
291 case GLUT_OVERLAY_POSSIBLE:
\r
292 /* return fgSetupPixelFormat( fgStructure.CurrentWindow, GL_TRUE,
\r
293 PFD_OVERLAY_PLANE ); */
\r
296 case GLUT_LAYER_IN_USE:
\r
297 return GLUT_NORMAL;
\r
299 case GLUT_HAS_OVERLAY:
\r
302 case GLUT_TRANSPARENT_INDEX:
\r
304 * Return just anything, which is always defined as zero
\r
310 case GLUT_NORMAL_DAMAGED:
\r
311 /* XXX Actually I do not know. Maybe. */
\r
314 case GLUT_OVERLAY_DAMAGED:
\r
318 fgWarning( "glutLayerGet(): missing enum handle %d", eWhat );
\r
322 /* And fail. That's good. Programs do love failing. */
\r