Debian Codegraph @

tools/quake2/extra/qe4/win_cam.c

raw symbols SCIP
1 /*
2 ===========================================================================
3 Copyright (C) 1997-2006 Id Software, Inc.
4
5 This file is part of Quake 2 Tools source code.
6
7 Quake 2 Tools source code is free software; you can redistribute it
8 and/or modify it under the terms of the GNU General Public License as
9 published by the Free Software Foundation; either version 2 of the License,
10 or (at your option) any later version.
11
12 Quake 2 Tools source code is distributed in the hope that it will be
13 useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with Quake 2 Tools source code; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 ===========================================================================
21 */
22
23 // win_cam.c -- windows specific camera view code
24
25 #include "qe3.h"
26
27 /*
28 ============
29 CameraWndProc
30 ============
31 */
32 LONG WINAPI WCam_WndProc (
33 HWND hWnd,
34 UINT uMsg,
35 WPARAM wParam,
36 LPARAM lParam)
37 {
38 int fwKeys, xPos, yPos;
39 RECT rect;
40
41 GetClientRect(hWnd, &rect);
42
43 switch (uMsg)
44 {
45 case WM_CREATE:
46 {
47 HFONT hfont;
48
49 g_qeglobals.d_hdcBase = GetDC(hWnd);
50 QEW_SetupPixelFormat(g_qeglobals.d_hdcBase, true);
51
52 if ( ( g_qeglobals.d_hglrcBase = wglCreateContext( g_qeglobals.d_hdcBase ) ) == 0 )
53 Error ("wglCreateContext failed");
54 if (!wglMakeCurrent( g_qeglobals.d_hdcBase, g_qeglobals.d_hglrcBase ))
55 Error ("wglMakeCurrent failed");
56
57 Texture_SetMode(g_qeglobals.d_savedinfo.iTexMenu);
58
59 //
60 // create GL font
61 //
62 hfont = CreateFont(
63 10, // logical height of font
64 7, // logical average character width
65 0, // angle of escapement
66 0, // base-line orientation angle
67 0, // font weight
68 0, // italic attribute flag
69 0, // underline attribute flag
70 0, // strikeout attribute flag
71 0, // character set identifier
72 0, // output precision
73 0, // clipping precision
74 0, // output quality
75 0, // pitch and family
76 0 // pointer to typeface name string
77 );
78
79 if ( !hfont )
80 Error( "couldn't create font" );
81
82 SelectObject (g_qeglobals.d_hdcBase, hfont);
83
84 if ( ( g_qeglobals.d_font_list = glGenLists (256) ) == 0 )
85 Error( "couldn't create font dlists" );
86
87 // create the bitmap display lists
88 // we're making images of glyphs 0 thru 255
89 if ( !wglUseFontBitmaps (g_qeglobals.d_hdcBase, 1, 255, g_qeglobals.d_font_list) )
90 Error( "wglUseFontBitmaps faileD" );
91
92 // indicate start of glyph display lists
93 glListBase (g_qeglobals.d_font_list);
94
95 // report OpenGL information
96 Sys_Printf ("GL_VENDOR: %s\n", glGetString (GL_VENDOR));
97 Sys_Printf ("GL_RENDERER: %s\n", glGetString (GL_RENDERER));
98 Sys_Printf ("GL_VERSION: %s\n", glGetString (GL_VERSION));
99 Sys_Printf ("GL_EXTENSIONS: %s\n", glGetString (GL_EXTENSIONS));
100 }
101 return 0;
102 case WM_PAINT:
103 {
104 PAINTSTRUCT ps;
105
106 if (!wglMakeCurrent( g_qeglobals.d_hdcBase, g_qeglobals.d_hglrcBase ))
107 Error ("wglMakeCurrent failed");
108
109 if ( BeginPaint(hWnd, &ps) )
110 {
111 QE_CheckOpenGLForErrors();
112 Cam_Draw ();
113 QE_CheckOpenGLForErrors();
114
115 EndPaint(hWnd, &ps);
116 SwapBuffers(g_qeglobals.d_hdcBase);
117 }
118 }
119 return 0;
120
121 case WM_USER+267: // benchmark
122 {
123 PAINTSTRUCT ps;
124 WINDOWPLACEMENT wp;
125 double start, end;
126 int i;
127
128 memset( &wp, 0, sizeof( wp ) );
129 wp.length = sizeof( wp );
130 GetWindowPlacement( g_qeglobals.d_hwndCamera, &wp );
131
132 MoveWindow( g_qeglobals.d_hwndCamera, 30, 30, 400, 400, TRUE );
133
134 BeginPaint(hWnd, &ps);
135 if (!wglMakeCurrent( g_qeglobals.d_hdcBase, g_qeglobals.d_hglrcBase))
136 Error ("wglMakeCurrent failed");
137 glDrawBuffer (GL_FRONT);
138
139 start = Sys_DoubleTime ();
140 for (i=0 ; i<100 ; i++)
141 {
142 camera.angles[YAW] = i*4;
143 Cam_Draw ();
144 }
145 SwapBuffers(g_qeglobals.d_hdcBase);
146 glDrawBuffer (GL_BACK);
147 end = Sys_DoubleTime ();
148 EndPaint(hWnd, &ps);
149 Sys_Printf ("%5.2f seconds\n", end-start);
150
151 SetWindowPlacement( g_qeglobals.d_hwndCamera, &wp );
152 }
153 break;
154
155 case WM_KEYDOWN:
156 if ( QE_KeyDown (wParam) )
157 return 0;
158 else
159 return DefWindowProc( hWnd, uMsg, wParam, lParam );
160
161 case WM_MBUTTONDOWN:
162 case WM_RBUTTONDOWN:
163 case WM_LBUTTONDOWN:
164 if (GetTopWindow(g_qeglobals.d_hwndMain) != hWnd)
165 BringWindowToTop(hWnd);
166
167 SetFocus (g_qeglobals.d_hwndCamera);
168 SetCapture (g_qeglobals.d_hwndCamera);
169 fwKeys = wParam; // key flags
170 xPos = (short)LOWORD(lParam); // horizontal position of cursor
171 yPos = (short)HIWORD(lParam); // vertical position of cursor
172 yPos = (int)rect.bottom - 1 - yPos;
173 Cam_MouseDown (xPos, yPos, fwKeys);
174 return 0;
175
176 case WM_MBUTTONUP:
177 case WM_RBUTTONUP:
178 case WM_LBUTTONUP:
179 fwKeys = wParam; // key flags
180 xPos = (short)LOWORD(lParam); // horizontal position of cursor
181 yPos = (short)HIWORD(lParam); // vertical position of cursor
182 yPos = (int)rect.bottom - 1 - yPos;
183 Cam_MouseUp (xPos, yPos, fwKeys);
184 if (! (fwKeys & (MK_LBUTTON|MK_RBUTTON|MK_MBUTTON)))
185 ReleaseCapture ();
186 return 0;
187
188 case WM_MOUSEMOVE:
189 fwKeys = wParam; // key flags
190 xPos = (short)LOWORD(lParam); // horizontal position of cursor
191 yPos = (short)HIWORD(lParam); // vertical position of cursor
192 yPos = (int)rect.bottom - 1 - yPos;
193 Cam_MouseMoved (xPos, yPos, fwKeys);
194 return 0;
195
196 case WM_SIZE:
197 camera.width = rect.right;
198 camera.height = rect.bottom;
199 InvalidateRect(g_qeglobals.d_hwndCamera, NULL, false);
200 return 0;
201
202 case WM_KILLFOCUS:
203 case WM_SETFOCUS:
204 SendMessage( hWnd, WM_NCACTIVATE, uMsg == WM_SETFOCUS, 0 );
205 return 0;
206
207 case WM_NCCALCSIZE:// don't let windows copy pixels
208 DefWindowProc (hWnd, uMsg, wParam, lParam);
209 return WVR_REDRAW;
210
211 case WM_CLOSE:
212 DestroyWindow (hWnd);
213 return 0;
214
215 case WM_DESTROY:
216 QEW_StopGL( hWnd, g_qeglobals.d_hglrcBase, g_qeglobals.d_hdcBase );
217 return 0;
218 }
219
220 return DefWindowProc( hWnd, uMsg, wParam, lParam );
221 }
222
223
224 /*
225 ==============
226 WCam_Create
227 ==============
228 */
229 void WCam_Create (HINSTANCE hInstance)
230 {
231 WNDCLASS wc;
232 char *title;
233
234 /* Register the camera class */
235 memset (&wc, 0, sizeof(wc));
236
237 wc.style = 0;
238 wc.lpfnWndProc = (WNDPROC)WCam_WndProc;
239 wc.cbClsExtra = 0;
240 wc.cbWndExtra = 0;
241 wc.hInstance = hInstance;
242 wc.hIcon = 0;
243 wc.hCursor = LoadCursor (NULL,IDC_ARROW);
244 wc.hbrBackground = NULL;
245 wc.lpszMenuName = 0;
246 wc.lpszClassName = CAMERA_WINDOW_CLASS;
247
248 if (!RegisterClass (&wc) )
249 Error ("WCam_Register: failed");
250
251 if ( g_qeglobals.d_savedinfo.exclude & EXCLUDE_DETAIL )
252 title = "Camera View (DETAIL EXCLUDED)";
253 else
254 title = "Camera View";
255
256 g_qeglobals.d_hwndCamera = CreateWindow (CAMERA_WINDOW_CLASS ,
257 title,
258 QE3_STYLE,
259 ZWIN_WIDTH,
260 20,
261 (int)(screen_width*CWIN_SIZE),
262 (int)(screen_height*CWIN_SIZE), // size
263
264 g_qeglobals.d_hwndMain, // parent window
265 0, // no menu
266 hInstance,
267 0);
268 if (!g_qeglobals.d_hwndCamera)
269 Error ("Couldn't create g_qeglobals.d_hwndCamera");
270
271 LoadWindowState(g_qeglobals.d_hwndCamera, "camerawindow");
272 ShowWindow (g_qeglobals.d_hwndCamera, SW_SHOWDEFAULT);
273 }