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 ); }
BOOL idGLWidget::Create( LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT &rect, CWnd *pParentWnd, UINT nID, CCreateContext *pContext ) { if( CWnd::Create( lpszClassName, lpszWindowName, dwStyle, rect, pParentWnd, nID, pContext ) == -1 ) { return FALSE; } CDC *dc = GetDC(); QEW_SetupPixelFormat( dc->m_hDC, false ); ReleaseDC( dc ); return TRUE; }
int CZWnd::OnCreate(LPCREATESTRUCT lpCreateStruct) { if (CWnd::OnCreate(lpCreateStruct) == -1) return -1; m_dcZ = ::GetDC(GetSafeHwnd()); QEW_SetupPixelFormat(m_dcZ, false); m_pZClip = new CZClip(); return 0; }
/* ======================================================================================================================= ======================================================================================================================= */ int CNewTexWnd::OnCreate(LPCREATESTRUCT lpCreateStruct) { if (CWnd::OnCreate(lpCreateStruct) == -1) { return -1; } ShowScrollBar(SB_VERT, g_PrefsDlg.m_bTextureScrollbar); m_bNeedRange = true; hdcTexture = GetDC(); QEW_SetupPixelFormat(hdcTexture->m_hDC, false); EnableToolTips(TRUE); EnableTrackingToolTips(TRUE); return 0; }
void CCamWnd::ReInitGL() { qwglMakeCurrent(0,0); QEW_SetupPixelFormat(GetDC()->m_hDC, true); if (!qwglMakeCurrent(g_qeglobals.d_hdcBase, g_qeglobals.d_hglrcBase)) Error ("wglMakeCurrent failed"); return; long lStyle = ::GetWindowLong(GetSafeHwnd(), GWL_STYLE); int nID = ::GetWindowLong(GetSafeHwnd(), GWL_ID); CWnd* pParent = GetParent(); CRect rctClient; GetClientRect(rctClient); DestroyWindow(); Create(CAMERA_WINDOW_CLASS, "", lStyle, rctClient, pParent, nID); }
/* ======================================================================================================================= ======================================================================================================================= */ BOOL CNewTexWnd::Create ( LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT &rect, CWnd *pParentWnd, UINT nID, CCreateContext *pContext ) { BOOL ret = CWnd::Create(lpszClassName, lpszWindowName, dwStyle, rect, pParentWnd, nID, pContext); if (ret) { hdcTexture = GetDC(); QEW_SetupPixelFormat(hdcTexture->m_hDC, false); } return ret; }
int CZWnd::OnCreate(LPCREATESTRUCT lpCreateStruct) { if (CWnd::OnCreate(lpCreateStruct) == -1) return -1; g_qeglobals.d_hwndZ = GetSafeHwnd(); m_dcZ = ::GetDC(GetSafeHwnd()); QEW_SetupPixelFormat(m_dcZ, false); if ((m_hglrcZ = qwglCreateContext(m_dcZ )) == 0) Error("wglCreateContext in CZWnd::OnCreate failed"); if (!qwglShareLists(g_qeglobals.d_hglrcBase, m_hglrcZ)) Error( "wglShareLists in CZWnd::OnCreate failed"); if (!qwglMakeCurrent(m_dcZ, m_hglrcZ)) Error ("wglMakeCurrent in CZWnd::OnCreate failed"); 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 (); } SwapBuffers(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 ); }
/* ============ WZ_WndProc ============ */ LONG WINAPI WZ_WndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam ) { int fwKeys, xPos, yPos; RECT rect; GetClientRect( hWnd, &rect ); switch ( uMsg ) { case WM_DESTROY: QEW_StopGL( hWnd, s_hglrcZ, s_hdcZ ); return 0; case WM_CREATE: s_hdcZ = GetDC( hWnd ); QEW_SetupPixelFormat( s_hdcZ, false ); if ( ( s_hglrcZ = wglCreateContext( s_hdcZ ) ) == 0 ) Error( "wglCreateContext in WZ_WndProc failed" ); if ( !wglMakeCurrent( s_hdcZ, s_hglrcZ ) ) Error( "wglMakeCurrent in WZ_WndProc failed" ); if ( !wglShareLists( g_qeglobals.d_hglrcBase, s_hglrcZ ) ) Error( "wglShareLists in WZ_WndProc failed" ); return 0; case WM_PAINT: { PAINTSTRUCT ps; BeginPaint( hWnd, &ps ); if ( !wglMakeCurrent( s_hdcZ, s_hglrcZ ) ) Error( "wglMakeCurrent failed" ); QE_CheckOpenGLForErrors(); Z_Draw(); SwapBuffers( s_hdcZ ); EndPaint( hWnd, &ps ); } return 0; case WM_KEYDOWN: QE_KeyDown( wParam ); return 0; case WM_MBUTTONDOWN: case WM_RBUTTONDOWN: case WM_LBUTTONDOWN: if ( GetTopWindow( g_qeglobals.d_hwndMain ) != hWnd ) BringWindowToTop( hWnd ); SetFocus( g_qeglobals.d_hwndZ ); SetCapture( g_qeglobals.d_hwndZ ); 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; Z_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; Z_MouseUp( xPos, yPos, fwKeys ); if ( !( fwKeys & ( MK_LBUTTON | MK_RBUTTON | MK_MBUTTON ) ) ) ReleaseCapture(); return 0; case WM_GETMINMAXINFO: { MINMAXINFO* pmmi = ( LPMINMAXINFO ) lParam; pmmi->ptMinTrackSize.x = ZWIN_WIDTH; 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; Z_MouseMoved( xPos, yPos, fwKeys ); return 0; case WM_SIZE: z.width = rect.right; z.height = rect.bottom; InvalidateRect( g_qeglobals.d_hwndZ, NULL, false ); return 0; case WM_NCCALCSIZE:// don't let windows copy pixels DefWindowProc( hWnd, uMsg, wParam, lParam ); return WVR_REDRAW; case WM_KILLFOCUS: case WM_SETFOCUS: SendMessage( hWnd, WM_NCACTIVATE, uMsg == WM_SETFOCUS, 0 ); return 0; case WM_CLOSE: /* call destroy window to cleanup and go away */ DestroyWindow( hWnd ); return 0; } return DefWindowProc( hWnd, uMsg, wParam, lParam ); }
int CCamWnd::OnCreate(LPCREATESTRUCT lpCreateStruct) { if (CWnd::OnCreate(lpCreateStruct) == -1) return -1; g_qeglobals.d_hdcBase = GetDC()->m_hDC; QEW_SetupPixelFormat(g_qeglobals.d_hdcBase, true); if ((g_qeglobals.d_hglrcBase = qwglCreateContext(g_qeglobals.d_hdcBase)) == 0) Error("wglCreateContext failed"); if (!qwglMakeCurrent(g_qeglobals.d_hdcBase, g_qeglobals.d_hglrcBase)) Error ("wglMakeCurrent failed"); // // create GL font // HFONT hfont = ::CreateFont( 12, // logical height of font 6, // 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 "system font" // pointer to typeface name string ); if (!hfont) Error( "couldn't create font" ); ::SelectObject(g_qeglobals.d_hdcBase, hfont); if ((g_qeglobals.d_font_list = qglGenLists (256)) == 0) Error( "couldn't create font dlists" ); // create the bitmap display lists // we're making images of glyphs 0 thru 255 if (g_PrefsDlg.m_bBuggyICD) { if ( !qwglUseFontBitmaps (g_qeglobals.d_hdcBase, 1, 255, g_qeglobals.d_font_list-1) ) Error( "wglUseFontBitmaps faileD" ); } else { if ( !qwglUseFontBitmaps (g_qeglobals.d_hdcBase, 1, 255, g_qeglobals.d_font_list) ) Error( "wglUseFontBitmaps faileD" ); } // indicate start of glyph display lists qglListBase (g_qeglobals.d_font_list); // report OpenGL information Sys_Printf ("GL_VENDOR: %s\n", qglGetString (GL_VENDOR)); Sys_Printf ("GL_RENDERER: %s\n", qglGetString (GL_RENDERER)); Sys_Printf ("GL_VERSION: %s\n", qglGetString (GL_VERSION)); Sys_Printf ("GL_EXTENSIONS: %s\n", qglGetString (GL_EXTENSIONS)); g_qeglobals.d_hwndCamera = GetSafeHwnd(); return 0; }