2 * freeglut_init_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: Thu Jan 19, 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 #define FREEGLUT_BUILDING_LIB
\r
29 #include <GL/freeglut.h>
\r
30 #include "../Common/freeglut_internal.h"
\r
34 extern LRESULT CALLBACK fgPlatformWindowProc( HWND hWnd, UINT uMsg,
\r
35 WPARAM wParam, LPARAM lParam );
\r
39 * A call to this function should initialize all the display stuff...
\r
41 void fgPlatformInitialize( const char* displayName )
\r
46 /* What we need to do is to initialize the fgDisplay global structure here. */
\r
47 fgDisplay.pDisplay.Instance = GetModuleHandle( NULL );
\r
48 fgDisplay.pDisplay.DisplayName= displayName ? strdup(displayName) : 0 ;
\r
49 atom = GetClassInfo( fgDisplay.pDisplay.Instance, _T("FREEGLUT"), &wc );
\r
53 ZeroMemory( &wc, sizeof(WNDCLASS) );
\r
56 * Each of the windows should have its own device context, and we
\r
57 * want redraw events during Vertical and Horizontal Resizes by
\r
60 * XXX Old code had "| CS_DBCLCKS" commented out. Plans for the
\r
61 * XXX future? Dead-end idea?
\r
63 wc.lpfnWndProc = fgPlatformWindowProc;
\r
66 wc.hInstance = fgDisplay.pDisplay.Instance;
\r
67 wc.hIcon = LoadIcon( fgDisplay.pDisplay.Instance, _T("GLUT_ICON") );
\r
69 #if defined(_WIN32_WCE)
\r
70 wc.style = CS_HREDRAW | CS_VREDRAW;
\r
72 wc.style = CS_OWNDC | CS_HREDRAW | CS_VREDRAW;
\r
74 wc.hIcon = LoadIcon( NULL, IDI_WINLOGO );
\r
77 wc.hCursor = LoadCursor( NULL, IDC_ARROW );
\r
78 wc.hbrBackground = NULL;
\r
79 wc.lpszMenuName = NULL;
\r
80 wc.lpszClassName = _T("FREEGLUT");
\r
82 /* Register the window class */
\r
83 atom = RegisterClass( &wc );
\r
84 FREEGLUT_INTERNAL_ERROR_EXIT ( atom, "Window Class Not Registered", "fgPlatformInitialize" );
\r
87 /* The screen dimensions can be obtained via GetSystemMetrics() calls */
\r
88 fgDisplay.ScreenWidth = GetSystemMetrics( SM_CXSCREEN );
\r
89 fgDisplay.ScreenHeight = GetSystemMetrics( SM_CYSCREEN );
\r
92 HWND desktop = GetDesktopWindow( );
\r
93 HDC context = GetDC( desktop );
\r
95 fgDisplay.ScreenWidthMM = GetDeviceCaps( context, HORZSIZE );
\r
96 fgDisplay.ScreenHeightMM = GetDeviceCaps( context, VERTSIZE );
\r
98 ReleaseDC( desktop, context );
\r
100 /* If we have a DisplayName try to use it for metrics */
\r
101 if( fgDisplay.pDisplay.DisplayName )
\r
103 HDC context = CreateDC(fgDisplay.pDisplay.DisplayName,0,0,0);
\r
106 fgDisplay.ScreenWidth = GetDeviceCaps( context, HORZRES );
\r
107 fgDisplay.ScreenHeight = GetDeviceCaps( context, VERTRES );
\r
108 fgDisplay.ScreenWidthMM = GetDeviceCaps( context, HORZSIZE );
\r
109 fgDisplay.ScreenHeightMM = GetDeviceCaps( context, VERTSIZE );
\r
113 fgWarning("fgPlatformInitialize: "
\r
114 "CreateDC failed, Screen size info may be incorrect\n"
\r
115 "This is quite likely caused by a bad '-display' parameter");
\r
118 /* Set the timer granularity to 1 ms */
\r
119 timeBeginPeriod ( 1 );
\r
122 fgState.Initialised = GL_TRUE;
\r
124 /* Avoid registering atexit callback on Win32 as it results in an access
\r
125 * violation due to calling into a module which has been unloaded.
\r
126 * Any cleanup isn't needed on Windows anyway, the OS takes care of it.c
\r
127 * see: http://blogs.msdn.com/b/oldnewthing/archive/2012/01/05/10253268.aspx
\r
129 /* atexit(fgDeinitialize); */
\r
131 /* InputDevice uses GlutTimerFunc(), so fgState.Initialised must be TRUE */
\r
132 fgInitialiseInputDevices();
\r
137 /* Platform-Specific Deinitialization Functions: */
\r
138 extern void fghCloseInputDevices ( void );
\r
140 void fgPlatformDeinitialiseInputDevices ( void )
\r
142 #if !defined(_WIN32_WCE)
\r
143 fghCloseInputDevices ();
\r
144 #endif /* !defined(_WIN32_WCE) */
\r
145 fgState.JoysticksInitialised = GL_FALSE;
\r
146 fgState.InputDevsInitialised = GL_FALSE;
\r
149 void fgPlatformCloseDisplay ( void )
\r
151 if( fgDisplay.pDisplay.DisplayName )
\r
153 free( fgDisplay.pDisplay.DisplayName );
\r
154 fgDisplay.pDisplay.DisplayName = NULL;
\r
157 /* Reset the timer granularity */
\r
158 timeEndPeriod ( 1 );
\r
161 void fgPlatformDestroyContext ( SFG_PlatformDisplay pDisplay, SFG_WindowContextType MContext )
\r
163 /* Do nothing -- this is required for X11 */
\r
167 * Everything down to the end of the next two functions is copied from the X sources.
\r
172 Copyright 1985, 1986, 1987,1998 The Open Group
\r
174 Permission to use, copy, modify, distribute, and sell this software and its
\r
175 documentation for any purpose is hereby granted without fee, provided that
\r
176 the above copyright notice appear in all copies and that both that
\r
177 copyright notice and this permission notice appear in supporting
\r
180 The above copyright notice and this permission notice shall be included
\r
181 in all copies or substantial portions of the Software.
\r
183 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
\r
184 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
\r
185 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
\r
186 IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR
\r
187 OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
\r
188 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
\r
189 OTHER DEALINGS IN THE SOFTWARE.
\r
191 Except as contained in this notice, the name of The Open Group shall
\r
192 not be used in advertising or otherwise to promote the sale, use or
\r
193 other dealings in this Software without prior written authorization
\r
194 from The Open Group.
\r
198 #define NoValue 0x0000
\r
199 #define XValue 0x0001
\r
200 #define YValue 0x0002
\r
201 #define WidthValue 0x0004
\r
202 #define HeightValue 0x0008
\r
203 #define AllValues 0x000F
\r
204 #define XNegative 0x0010
\r
205 #define YNegative 0x0020
\r
208 * XParseGeometry parses strings of the form
\r
209 * "=<width>x<height>{+-}<xoffset>{+-}<yoffset>", where
\r
210 * width, height, xoffset, and yoffset are unsigned integers.
\r
211 * Example: "=80x24+300-49"
\r
212 * The equal sign is optional.
\r
213 * It returns a bitmask that indicates which of the four values
\r
214 * were actually found in the string. For each value found,
\r
215 * the corresponding argument is updated; for each value
\r
216 * not found, the corresponding argument is left unchanged.
\r
220 ReadInteger(char *string, char **NextString)
\r
222 register int Result = 0;
\r
225 if (*string == '+')
\r
227 else if (*string == '-')
\r
232 for (; (*string >= '0') && (*string <= '9'); string++)
\r
234 Result = (Result * 10) + (*string - '0');
\r
236 *NextString = string;
\r
243 int XParseGeometry (
\r
244 const char *string,
\r
247 unsigned int *width, /* RETURN */
\r
248 unsigned int *height) /* RETURN */
\r
250 int mask = NoValue;
\r
251 register char *strind;
\r
252 unsigned int tempWidth = 0, tempHeight = 0;
\r
253 int tempX = 0, tempY = 0;
\r
254 char *nextCharacter;
\r
256 if ( (string == NULL) || (*string == '\0'))
\r
258 if (*string == '=')
\r
259 string++; /* ignore possible '=' at beg of geometry spec */
\r
261 strind = (char *)string;
\r
262 if (*strind != '+' && *strind != '-' && *strind != 'x') {
\r
263 tempWidth = ReadInteger(strind, &nextCharacter);
\r
264 if (strind == nextCharacter)
\r
266 strind = nextCharacter;
\r
267 mask |= WidthValue;
\r
270 if (*strind == 'x' || *strind == 'X') {
\r
272 tempHeight = ReadInteger(strind, &nextCharacter);
\r
273 if (strind == nextCharacter)
\r
275 strind = nextCharacter;
\r
276 mask |= HeightValue;
\r
279 if ((*strind == '+') || (*strind == '-')) {
\r
280 if (*strind == '-') {
\r
282 tempX = -ReadInteger(strind, &nextCharacter);
\r
283 if (strind == nextCharacter)
\r
285 strind = nextCharacter;
\r
291 tempX = ReadInteger(strind, &nextCharacter);
\r
292 if (strind == nextCharacter)
\r
294 strind = nextCharacter;
\r
297 if ((*strind == '+') || (*strind == '-')) {
\r
298 if (*strind == '-') {
\r
300 tempY = -ReadInteger(strind, &nextCharacter);
\r
301 if (strind == nextCharacter)
\r
303 strind = nextCharacter;
\r
309 tempY = ReadInteger(strind, &nextCharacter);
\r
310 if (strind == nextCharacter)
\r
312 strind = nextCharacter;
\r
318 /* If strind isn't at the end of the string the it's an invalid
\r
319 geometry specification. */
\r
321 if (*strind != '\0') return 0;
\r
327 if (mask & WidthValue)
\r
328 *width = tempWidth;
\r
329 if (mask & HeightValue)
\r
330 *height = tempHeight;
\r
336 /* -- PLATFORM-SPECIFIC INTERFACE FUNCTION -------------------------------------------------- */
\r
338 void (__cdecl *__glutExitFunc)( int return_value ) = NULL;
\r
340 void FGAPIENTRY __glutInitWithExit( int *pargc, char **argv, void (__cdecl *exit_function)(int) )
\r
342 __glutExitFunc = exit_function;
\r
343 glutInit(pargc, argv);
\r