2 ===========================================================================
3 Copyright (C) 1997-2006 Id Software, Inc.
5 This file is part of Quake 2 Tools source code.
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.
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.
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 ===========================================================================
23 // win_cam.c -- windows specific camera view code
32 LONG WINAPI WCam_WndProc (
38 int fwKeys, xPos, yPos;
41 GetClientRect(hWnd, &rect);
49 g_qeglobals.d_hdcBase = GetDC(hWnd);
50 QEW_SetupPixelFormat(g_qeglobals.d_hdcBase, true);
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");
57 Texture_SetMode(g_qeglobals.d_savedinfo.iTexMenu);
63 10, // logical height of font
64 7, // logical average character width
65 0, // angle of escapement
66 0, // base-line orientation angle
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
75 0, // pitch and family
76 0 // pointer to typeface name string
80 Error( "couldn't create font" );
82 SelectObject (g_qeglobals.d_hdcBase, hfont);
84 if ( ( g_qeglobals.d_font_list = glGenLists (256) ) == 0 )
85 Error( "couldn't create font dlists" );
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" );
92 // indicate start of glyph display lists
93 glListBase (g_qeglobals.d_font_list);
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));
106 if (!wglMakeCurrent( g_qeglobals.d_hdcBase, g_qeglobals.d_hglrcBase ))
107 Error ("wglMakeCurrent failed");
109 if ( BeginPaint(hWnd, &ps) )
111 QE_CheckOpenGLForErrors();
113 QE_CheckOpenGLForErrors();
116 SwapBuffers(g_qeglobals.d_hdcBase);
121 case WM_USER+267: // benchmark
128 memset( &wp, 0, sizeof( wp ) );
129 wp.length = sizeof( wp );
130 GetWindowPlacement( g_qeglobals.d_hwndCamera, &wp );
132 MoveWindow( g_qeglobals.d_hwndCamera, 30, 30, 400, 400, TRUE );
134 BeginPaint(hWnd, &ps);
135 if (!wglMakeCurrent( g_qeglobals.d_hdcBase, g_qeglobals.d_hglrcBase))
136 Error ("wglMakeCurrent failed");
137 glDrawBuffer (GL_FRONT);
139 start = Sys_DoubleTime ();
140 for (i=0 ; i<100 ; i++)
142 camera.angles[YAW] = i*4;
145 SwapBuffers(g_qeglobals.d_hdcBase);
146 glDrawBuffer (GL_BACK);
147 end = Sys_DoubleTime ();
149 Sys_Printf ("%5.2f seconds\n", end-start);
151 SetWindowPlacement( g_qeglobals.d_hwndCamera, &wp );
156 if ( QE_KeyDown (wParam) )
159 return DefWindowProc( hWnd, uMsg, wParam, lParam );
164 if (GetTopWindow(g_qeglobals.d_hwndMain) != hWnd)
165 BringWindowToTop(hWnd);
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);
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)))
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);
197 camera.width = rect.right;
198 camera.height = rect.bottom;
199 InvalidateRect(g_qeglobals.d_hwndCamera, NULL, false);
204 SendMessage( hWnd, WM_NCACTIVATE, uMsg == WM_SETFOCUS, 0 );
207 case WM_NCCALCSIZE:// don't let windows copy pixels
208 DefWindowProc (hWnd, uMsg, wParam, lParam);
212 DestroyWindow (hWnd);
216 QEW_StopGL( hWnd, g_qeglobals.d_hglrcBase, g_qeglobals.d_hdcBase );
220 return DefWindowProc( hWnd, uMsg, wParam, lParam );
229 void WCam_Create (HINSTANCE hInstance)
234 /* Register the camera class */
235 memset (&wc, 0, sizeof(wc));
238 wc.lpfnWndProc = (WNDPROC)WCam_WndProc;
241 wc.hInstance = hInstance;
243 wc.hCursor = LoadCursor (NULL,IDC_ARROW);
244 wc.hbrBackground = NULL;
246 wc.lpszClassName = CAMERA_WINDOW_CLASS;
248 if (!RegisterClass (&wc) )
249 Error ("WCam_Register: failed");
251 if ( g_qeglobals.d_savedinfo.exclude & EXCLUDE_DETAIL )
252 title = "Camera View (DETAIL EXCLUDED)";
254 title = "Camera View";
256 g_qeglobals.d_hwndCamera = CreateWindow (CAMERA_WINDOW_CLASS ,
261 (int)(screen_width*CWIN_SIZE),
262 (int)(screen_height*CWIN_SIZE), // size
264 g_qeglobals.d_hwndMain, // parent window
268 if (!g_qeglobals.d_hwndCamera)
269 Error ("Couldn't create g_qeglobals.d_hwndCamera");
271 LoadWindowState(g_qeglobals.d_hwndCamera, "camerawindow");
272 ShowWindow (g_qeglobals.d_hwndCamera, SW_SHOWDEFAULT);