home *** CD-ROM | disk | FTP | other *** search
/ PC PowerPlay 58 / pcpp58a.iso / extras / quake 3 source / Q3A_ToolSource.exe / Main / WIN_CAM.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  2001-01-02  |  6.6 KB  |  254 lines

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