comparison mupdf-source/thirdparty/freeglut/src/mswin/fg_init_mswin.c @ 2:b50eed0cc0ef upstream

ADD: MuPDF v1.26.7: the MuPDF source as downloaded by a default build of PyMuPDF 1.26.4. The directory name has changed: no version number in the expanded directory now.
author Franz Glasner <fzglas.hg@dom66.de>
date Mon, 15 Sep 2025 11:43:07 +0200
parents
children
comparison
equal deleted inserted replaced
1:1d09e1dec1d9 2:b50eed0cc0ef
1 /*
2 * fg_init_mswin.c
3 *
4 * The Windows-specific mouse cursor related stuff.
5 *
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
9 *
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:
16 *
17 * The above copyright notice and this permission notice shall be included
18 * in all copies or substantial portions of the Software.
19 *
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.
26 */
27
28 #define FREEGLUT_BUILDING_LIB
29 #include <GL/freeglut.h>
30 #include "../fg_internal.h"
31
32
33
34 extern LRESULT CALLBACK fgPlatformWindowProc( HWND hWnd, UINT uMsg,
35 WPARAM wParam, LPARAM lParam );
36 extern void fgPlatformInitSystemTime();
37 extern void fghCloseInputDevices(void);
38
39 char *fgClipboardBuffer[3] = { NULL, NULL, NULL };
40
41
42 /*
43 * A call to this function should initialize all the display stuff...
44 */
45 void fgPlatformInitialize( const char* displayName )
46 {
47 WNDCLASS wc;
48 BOOL atom;
49
50 /* What we need to do is to initialize the fgDisplay global structure here. */
51 fgDisplay.pDisplay.Instance = GetModuleHandle( NULL );
52 fgDisplay.pDisplay.DisplayName= displayName ? strdup(displayName) : 0 ;
53 atom = GetClassInfo( fgDisplay.pDisplay.Instance, _T("FREEGLUT"), &wc );
54
55 if( atom == 0 )
56 {
57 ZeroMemory( &wc, sizeof(WNDCLASS) );
58
59 /*
60 * Each of the windows should have its own device context, and we
61 * want redraw events during Vertical and Horizontal Resizes by
62 * the user.
63 */
64 wc.lpfnWndProc = fgPlatformWindowProc;
65 wc.cbClsExtra = 0;
66 wc.cbWndExtra = 0;
67 wc.hInstance = fgDisplay.pDisplay.Instance;
68 wc.hIcon = LoadIcon( fgDisplay.pDisplay.Instance, _T("GLUT_ICON") );
69
70 #if defined(_WIN32_WCE)
71 wc.style = CS_HREDRAW | CS_VREDRAW;
72 #else
73 wc.style = CS_OWNDC | CS_HREDRAW | CS_VREDRAW;
74 if (!wc.hIcon)
75 wc.hIcon = LoadIcon( NULL, IDI_WINLOGO );
76 #endif
77
78 wc.hCursor = LoadCursor( NULL, IDC_ARROW );
79 wc.hbrBackground = NULL;
80 wc.lpszMenuName = NULL;
81 wc.lpszClassName = _T("FREEGLUT");
82
83 /* Register the window class */
84 atom = RegisterClass( &wc );
85 FREEGLUT_INTERNAL_ERROR_EXIT ( atom, "Window Class Not Registered", "fgPlatformInitialize" );
86 }
87
88 /* The screen dimensions can be obtained via GetSystemMetrics() calls */
89 fgDisplay.ScreenWidth = GetSystemMetrics( SM_CXSCREEN );
90 fgDisplay.ScreenHeight = GetSystemMetrics( SM_CYSCREEN );
91
92 {
93 HWND desktop = GetDesktopWindow( );
94 HDC context = GetDC( desktop );
95
96 fgDisplay.ScreenWidthMM = GetDeviceCaps( context, HORZSIZE );
97 fgDisplay.ScreenHeightMM = GetDeviceCaps( context, VERTSIZE );
98
99 ReleaseDC( desktop, context );
100 }
101 /* If we have a DisplayName try to use it for metrics */
102 if( fgDisplay.pDisplay.DisplayName )
103 {
104 HDC context = CreateDC(fgDisplay.pDisplay.DisplayName,0,0,0);
105 if( context )
106 {
107 fgDisplay.ScreenWidth = GetDeviceCaps( context, HORZRES );
108 fgDisplay.ScreenHeight = GetDeviceCaps( context, VERTRES );
109 fgDisplay.ScreenWidthMM = GetDeviceCaps( context, HORZSIZE );
110 fgDisplay.ScreenHeightMM = GetDeviceCaps( context, VERTSIZE );
111 DeleteDC(context);
112 }
113 else
114 fgWarning("fgPlatformInitialize: "
115 "CreateDC failed, Screen size info may be incorrect\n"
116 "This is quite likely caused by a bad '-display' parameter");
117
118 }
119 /* Set the timer granularity to 1 ms */
120 timeBeginPeriod ( 1 );
121 /* Init setup to deal with timer wrap, can't query system time before this is done */
122 fgPlatformInitSystemTime();
123 /* Get start time */
124 fgState.Time = fgSystemTime();
125
126
127 fgState.Initialised = GL_TRUE;
128
129 /* Avoid registering atexit callback on Win32 as it can result in an
130 * access violation due to calling into a module which has been
131 * unloaded.
132 * Any cleanup isn't needed on Windows anyway, the OS takes care of it.
133 * see: http://blogs.msdn.com/b/oldnewthing/archive/2012/01/05/10253268.aspx
134 */
135 /* atexit(fgDeinitialize); */
136
137 /* InputDevice uses GlutTimerFunc(), so fgState.Initialised must be TRUE */
138 fgInitialiseInputDevices();
139 }
140
141
142
143 /* Platform-Specific Deinitialization Functions: */
144 void fgPlatformDeinitialiseInputDevices ( void )
145 {
146 #if !defined(_WIN32_WCE)
147 fghCloseInputDevices ();
148 #endif /* !defined(_WIN32_WCE) */
149 fgState.JoysticksInitialised = GL_FALSE;
150 fgState.InputDevsInitialised = GL_FALSE;
151 }
152
153 void fgPlatformCloseDisplay ( void )
154 {
155 int i;
156
157 if( fgDisplay.pDisplay.DisplayName )
158 {
159 free( fgDisplay.pDisplay.DisplayName );
160 fgDisplay.pDisplay.DisplayName = NULL;
161 }
162
163 for (i = 0; i < 3; ++i)
164 {
165 free(fgClipboardBuffer[i]);
166 fgClipboardBuffer[i] = NULL;
167 }
168
169 /* Reset the timer granularity */
170 timeEndPeriod ( 1 );
171 }
172
173 void fgPlatformDestroyContext ( SFG_PlatformDisplay pDisplay, SFG_WindowContextType MContext )
174 {
175 /* Do nothing -- this is required for X11 */
176 }
177
178 /* -- PLATFORM-SPECIFIC INTERFACE FUNCTION -------------------------------------------------- */
179
180 void (__cdecl *__glutExitFunc)( int return_value ) = NULL;
181
182 void FGAPIENTRY __glutInitWithExit( int *pargc, char **argv, void (__cdecl *exit_function)(int) )
183 {
184 __glutExitFunc = exit_function;
185 glutInit(pargc, argv);
186 }
187