void idGLWidget::OnPaint() { if( !initialized ) { CDC *dc = GetDC(); QEW_SetupPixelFormat( dc->m_hDC, false ); ReleaseDC( dc ); initialized = true; } CPaintDC dc( this ); // device context for painting CRect rect; GetClientRect( rect ); if( !wglMakeCurrent( dc.m_hDC, win32.hGLRC ) ) { } GL_Viewport( 0, 0, rect.Width(), rect.Height() ); GL_Scissor( 0, 0, rect.Width(), rect.Height() ); glMatrixMode( GL_PROJECTION ); glLoadIdentity(); glClearColor( 0.4f, 0.4f, 0.4f, 0.7f ); glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); glDisable( GL_DEPTH_TEST ); glDisable( GL_BLEND ); glOrtho( 0, rect.Width(), 0, rect.Height(), -256, 256 ); if( drawable ) { drawable->draw( 1, 1, rect.Width() - 1, rect.Height() - 1 ); } else { GL_Viewport( 0, 0, rect.Width(), rect.Height() ); GL_Scissor( 0, 0, rect.Width(), rect.Height() ); glMatrixMode( GL_PROJECTION ); glLoadIdentity(); glClearColor( 0.4f, 0.4f, 0.4f, 0.7f ); glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); } wglSwapBuffers( dc ); glFlush(); wglMakeCurrent( win32.hDC, win32.hGLRC ); }
WINGDIAPI DWORD WINAPI wglSwapMultipleBuffers(UINT n, CONST WGLSWAP *ps) { UINT i; for (i =0; i < n; ++i) wglSwapBuffers(ps->hdc); return 0; }
/* ============ CameraWndProc ============ */ LONG WINAPI WCam_WndProc ( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { int fwKeys, xPos, yPos; RECT rect; GetClientRect(hWnd, &rect); switch (uMsg) { case WM_CREATE: { HFONT hfont; g_qeglobals.d_hdcBase = GetDC(hWnd); QEW_SetupPixelFormat(g_qeglobals.d_hdcBase, true); if ( ( g_qeglobals.d_hglrcBase = wglCreateContext( g_qeglobals.d_hdcBase ) ) == 0 ) Error ("wglCreateContext failed"); if (!wglMakeCurrent( g_qeglobals.d_hdcBase, g_qeglobals.d_hglrcBase )) Error ("wglMakeCurrent failed"); Texture_SetMode(g_qeglobals.d_savedinfo.iTexMenu); // // create GL font // hfont = CreateFont( 10, // logical height of font 7, // logical average character width 0, // angle of escapement 0, // base-line orientation angle 0, // font weight 0, // italic attribute flag 0, // underline attribute flag 0, // strikeout attribute flag 0, // character set identifier 0, // output precision 0, // clipping precision 0, // output quality 0, // pitch and family 0 // pointer to typeface name string ); if ( !hfont ) Error( "couldn't create font" ); SelectObject (g_qeglobals.d_hdcBase, hfont); if ( ( g_qeglobals.d_font_list = glGenLists (256) ) == 0 ) Error( "couldn't create font dlists" ); // create the bitmap display lists // we're making images of glyphs 0 thru 255 if ( !wglUseFontBitmaps (g_qeglobals.d_hdcBase, 1, 255, g_qeglobals.d_font_list) ) Error( "wglUseFontBitmaps faileD" ); // indicate start of glyph display lists glListBase (g_qeglobals.d_font_list); // report OpenGL information Sys_Printf ("GL_VENDOR: %s\n", glGetString (GL_VENDOR)); Sys_Printf ("GL_RENDERER: %s\n", glGetString (GL_RENDERER)); Sys_Printf ("GL_VERSION: %s\n", glGetString (GL_VERSION)); Sys_Printf ("GL_EXTENSIONS: %s\n", glGetString (GL_EXTENSIONS)); } return 0; case WM_PAINT: { PAINTSTRUCT ps; if (!wglMakeCurrent( g_qeglobals.d_hdcBase, g_qeglobals.d_hglrcBase )) Error ("wglMakeCurrent failed"); if ( BeginPaint(hWnd, &ps) ) { QE_CheckOpenGLForErrors(); Cam_Draw (); QE_CheckOpenGLForErrors(); EndPaint(hWnd, &ps); SwapBuffers(g_qeglobals.d_hdcBase); } } return 0; case WM_USER+267: // benchmark { PAINTSTRUCT ps; WINDOWPLACEMENT wp; double start, end; int i; memset( &wp, 0, sizeof( wp ) ); wp.length = sizeof( wp ); GetWindowPlacement( g_qeglobals.d_hwndCamera, &wp ); MoveWindow( g_qeglobals.d_hwndCamera, 30, 30, 400, 400, TRUE ); BeginPaint(hWnd, &ps); if (!wglMakeCurrent( g_qeglobals.d_hdcBase, g_qeglobals.d_hglrcBase)) Error ("wglMakeCurrent failed"); glDrawBuffer (GL_FRONT); start = Sys_DoubleTime (); for (i=0 ; i<100 ; i++) { camera.angles[YAW] = i*4; Cam_Draw (); } wglSwapBuffers(g_qeglobals.d_hdcBase); glDrawBuffer (GL_BACK); end = Sys_DoubleTime (); EndPaint(hWnd, &ps); Sys_Printf ("%5.2f seconds\n", end-start); SetWindowPlacement( g_qeglobals.d_hwndCamera, &wp ); } break; case WM_KEYDOWN: if ( QE_KeyDown (wParam) ) return 0; else return DefWindowProc( hWnd, uMsg, wParam, lParam ); case WM_MBUTTONDOWN: case WM_RBUTTONDOWN: case WM_LBUTTONDOWN: if (GetTopWindow(g_qeglobals.d_hwndMain) != hWnd) BringWindowToTop(hWnd); SetFocus (g_qeglobals.d_hwndCamera); SetCapture (g_qeglobals.d_hwndCamera); fwKeys = wParam; // key flags xPos = (short)LOWORD(lParam); // horizontal position of cursor yPos = (short)HIWORD(lParam); // vertical position of cursor yPos = (int)rect.bottom - 1 - yPos; Cam_MouseDown (xPos, yPos, fwKeys); return 0; case WM_MBUTTONUP: case WM_RBUTTONUP: case WM_LBUTTONUP: fwKeys = wParam; // key flags xPos = (short)LOWORD(lParam); // horizontal position of cursor yPos = (short)HIWORD(lParam); // vertical position of cursor yPos = (int)rect.bottom - 1 - yPos; Cam_MouseUp (xPos, yPos, fwKeys); if (! (fwKeys & (MK_LBUTTON|MK_RBUTTON|MK_MBUTTON))) ReleaseCapture (); return 0; case WM_MOUSEMOVE: fwKeys = wParam; // key flags xPos = (short)LOWORD(lParam); // horizontal position of cursor yPos = (short)HIWORD(lParam); // vertical position of cursor yPos = (int)rect.bottom - 1 - yPos; Cam_MouseMoved (xPos, yPos, fwKeys); return 0; case WM_SIZE: camera.width = rect.right; camera.height = rect.bottom; InvalidateRect(g_qeglobals.d_hwndCamera, NULL, false); return 0; case WM_KILLFOCUS: case WM_SETFOCUS: SendMessage( hWnd, WM_NCACTIVATE, uMsg == WM_SETFOCUS, 0 ); return 0; case WM_NCCALCSIZE:// don't let windows copy pixels DefWindowProc (hWnd, uMsg, wParam, lParam); return WVR_REDRAW; case WM_CLOSE: DestroyWindow (hWnd); return 0; case WM_DESTROY: QEW_StopGL( hWnd, g_qeglobals.d_hglrcBase, g_qeglobals.d_hdcBase ); return 0; } return DefWindowProc( hWnd, uMsg, wParam, lParam ); }
/* ================ rvGEWorkspace::Render Renders the workspace to the given DC ================ */ void rvGEWorkspace::Render ( HDC hdc ) { int front; int back; float scale; scale = g_ZoomScales[mZoom]; // Switch GL contexts to our dc if (!wglMakeCurrent( hdc, win32.hGLRC )) { common->Printf("ERROR: wglMakeCurrent failed.. Error:%i\n", glGetError()); common->Printf("Please restart Q3Radiant if the Map view is not working\n"); return; } // Prepare the view and clear it GL_State( GLS_DEFAULT ); glViewport(0, 0, mWindowWidth, mWindowHeight ); glScissor(0, 0, mWindowWidth, mWindowHeight ); glClearColor ( 0.75f, 0.75f, 0.75f, 0 ); glDisable(GL_DEPTH_TEST); glDisable(GL_CULL_FACE); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Render the workspace below GL_ProjectionMatrix.LoadIdentity(); GL_ProjectionMatrix.Ortho(0,mWindowWidth, mWindowHeight, 0, -1, 1); GL_ModelViewMatrix.LoadIdentity(); fhImmediateMode im; im.Color3f ( mApplication->GetOptions().GetWorkspaceColor()[0], mApplication->GetOptions().GetWorkspaceColor()[1], mApplication->GetOptions().GetWorkspaceColor()[2] ); im.Begin ( GL_QUADS ); im.Vertex2f ( mRect.x, mRect.y ); im.Vertex2f ( mRect.x + mRect.w, mRect.y ); im.Vertex2f ( mRect.x + mRect.w, mRect.y + mRect.h ); im.Vertex2f ( mRect.x, mRect.y + mRect.h ); im.End ( ); // Prepare the renderSystem view to draw the GUI in viewDef_t viewDef; memset ( &viewDef, 0, sizeof(viewDef) ); tr.viewDef = &viewDef; tr.viewDef->renderView.x = mRect.x; tr.viewDef->renderView.y = mWindowHeight - mRect.y - mRect.h; tr.viewDef->renderView.width = mRect.w; tr.viewDef->renderView.height = mRect.h; tr.viewDef->scissor.x1 = 0; tr.viewDef->scissor.y1 = 0; tr.viewDef->scissor.x2 = mRect.w; tr.viewDef->scissor.y2 = mRect.h; tr.viewDef->isEditor = true; renderSystem->BeginFrame(mWindowWidth, mWindowHeight ); // Draw the gui mInterface->Redraw ( 0 ); // eventLoop->Milliseconds() ); // We are done using the renderSystem now renderSystem->EndFrame( &front, &back ); if ( mApplication->GetActiveWorkspace ( ) == this ) { mApplication->GetStatusBar().SetTriangles ( backEnd.pc.c_drawIndexes/3 ); } // Prepare the viewport for drawing selections, etc. GL_State( GLS_DEFAULT ); glDisable( GL_TEXTURE_CUBE_MAP ); // glDisable(GL_BLEND); glDisable(GL_CULL_FACE); glViewport(0, 0, mWindowWidth, mWindowHeight ); glScissor(0, 0, mWindowWidth, mWindowHeight ); GL_ProjectionMatrix.LoadIdentity(); GL_ProjectionMatrix.Ortho(0, mWindowWidth, mWindowHeight, 0, -1, 1); GL_ModelViewMatrix.LoadIdentity(); RenderGrid ( ); mSelections.Render ( ); glFinish ( ); wglSwapBuffers(hdc); glEnable( GL_CULL_FACE); }