WIN_CAM.CPP 7.3 KB

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