4 * The Windows-specific mouse cursor related stuff.
6 * Copyright (c) 2012 Stephen J. Baker. All Rights Reserved.
7 * Written by John F. Fay, <fayjf@sourceforge.net>
8 * Creation date: Thu Jan 19, 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 #define FREEGLUT_BUILDING_LIB
29 #include <GL/freeglut.h>
30 #include "../fg_internal.h"
34 extern LRESULT CALLBACK fgPlatformWindowProc( HWND hWnd, UINT uMsg,
35 WPARAM wParam, LPARAM lParam );
36 extern void fgPlatformInitSystemTime();
37 extern void fghCloseInputDevices(void);
41 * A call to this function should initialize all the display stuff...
43 void fgPlatformInitialize( const char* displayName )
48 /* What we need to do is to initialize the fgDisplay global structure here. */
49 fgDisplay.pDisplay.Instance = GetModuleHandle( NULL );
50 fgDisplay.pDisplay.DisplayName= displayName ? strdup(displayName) : 0 ;
51 atom = GetClassInfo( fgDisplay.pDisplay.Instance, _T("FREEGLUT"), &wc );
55 ZeroMemory( &wc, sizeof(WNDCLASS) );
58 * Each of the windows should have its own device context, and we
59 * want redraw events during Vertical and Horizontal Resizes by
62 wc.lpfnWndProc = fgPlatformWindowProc;
65 wc.hInstance = fgDisplay.pDisplay.Instance;
66 wc.hIcon = LoadIcon( fgDisplay.pDisplay.Instance, _T("GLUT_ICON") );
68 #if defined(_WIN32_WCE)
69 wc.style = CS_HREDRAW | CS_VREDRAW;
71 wc.style = CS_OWNDC | CS_HREDRAW | CS_VREDRAW;
73 wc.hIcon = LoadIcon( NULL, IDI_WINLOGO );
76 wc.hCursor = LoadCursor( NULL, IDC_ARROW );
77 wc.hbrBackground = NULL;
78 wc.lpszMenuName = NULL;
79 wc.lpszClassName = _T("FREEGLUT");
81 /* Register the window class */
82 atom = RegisterClass( &wc );
83 FREEGLUT_INTERNAL_ERROR_EXIT ( atom, "Window Class Not Registered", "fgPlatformInitialize" );
86 /* The screen dimensions can be obtained via GetSystemMetrics() calls */
87 fgDisplay.ScreenWidth = GetSystemMetrics( SM_CXSCREEN );
88 fgDisplay.ScreenHeight = GetSystemMetrics( SM_CYSCREEN );
91 HWND desktop = GetDesktopWindow( );
92 HDC context = GetDC( desktop );
94 fgDisplay.ScreenWidthMM = GetDeviceCaps( context, HORZSIZE );
95 fgDisplay.ScreenHeightMM = GetDeviceCaps( context, VERTSIZE );
97 ReleaseDC( desktop, context );
99 /* If we have a DisplayName try to use it for metrics */
100 if( fgDisplay.pDisplay.DisplayName )
102 HDC context = CreateDC(fgDisplay.pDisplay.DisplayName,0,0,0);
105 fgDisplay.ScreenWidth = GetDeviceCaps( context, HORZRES );
106 fgDisplay.ScreenHeight = GetDeviceCaps( context, VERTRES );
107 fgDisplay.ScreenWidthMM = GetDeviceCaps( context, HORZSIZE );
108 fgDisplay.ScreenHeightMM = GetDeviceCaps( context, VERTSIZE );
112 fgWarning("fgPlatformInitialize: "
113 "CreateDC failed, Screen size info may be incorrect\n"
114 "This is quite likely caused by a bad '-display' parameter");
117 /* Set the timer granularity to 1 ms */
118 timeBeginPeriod ( 1 );
119 /* Init setup to deal with timer wrap, can't query system time before this is done */
120 fgPlatformInitSystemTime();
122 fgState.Time = fgSystemTime();
125 fgState.Initialised = GL_TRUE;
127 /* Avoid registering atexit callback on Win32 as it can result in an
128 * access violation due to calling into a module which has been
130 * Any cleanup isn't needed on Windows anyway, the OS takes care of it.
131 * see: http://blogs.msdn.com/b/oldnewthing/archive/2012/01/05/10253268.aspx
133 /* atexit(fgDeinitialize); */
135 /* InputDevice uses GlutTimerFunc(), so fgState.Initialised must be TRUE */
136 fgInitialiseInputDevices();
141 /* Platform-Specific Deinitialization Functions: */
142 void fgPlatformDeinitialiseInputDevices ( void )
144 #if !defined(_WIN32_WCE)
145 fghCloseInputDevices ();
146 #endif /* !defined(_WIN32_WCE) */
147 fgState.JoysticksInitialised = GL_FALSE;
148 fgState.InputDevsInitialised = GL_FALSE;
151 void fgPlatformCloseDisplay ( void )
153 if( fgDisplay.pDisplay.DisplayName )
155 free( fgDisplay.pDisplay.DisplayName );
156 fgDisplay.pDisplay.DisplayName = NULL;
159 /* Reset the timer granularity */
163 void fgPlatformDestroyContext ( SFG_PlatformDisplay pDisplay, SFG_WindowContextType MContext )
165 /* Do nothing -- this is required for X11 */
168 /* -- PLATFORM-SPECIFIC INTERFACE FUNCTION -------------------------------------------------- */
170 void (__cdecl *__glutExitFunc)( int return_value ) = NULL;
172 void FGAPIENTRY __glutInitWithExit( int *pargc, char **argv, void (__cdecl *exit_function)(int) )
174 __glutExitFunc = exit_function;
175 glutInit(pargc, argv);