void CCamWnd::OnPaint() { CPaintDC dc(this); // device context for painting bool bPaint = true; if (!qwglMakeCurrent( dc.m_hDC, g_qeglobals.d_hglrcBase )) { Sys_Printf("ERROR: wglMakeCurrent failed..\n "); Sys_Printf("Please restart Q3Radiant if the camera view is not working\n"); } else { QE_CheckOpenGLForErrors(); g_pSplitList = NULL; if (g_bClipMode) { if (g_Clip1.Set() && g_Clip2.Set()) { g_pSplitList = ( (g_pParentWnd->ActiveXY()->GetViewType() == XZ) ? !g_bSwitch : g_bSwitch) ? &g_brBackSplits : &g_brFrontSplits; } } Cam_Draw (); QE_CheckOpenGLForErrors(); qwglSwapBuffers(dc.m_hDC); } }
void CZWnd::OnPaint() { CPaintDC dc( this ); // device context for painting //if (!wglMakeCurrent(m_dcZ, m_hglrcZ)) //if (!qwglMakeCurrent(dc.m_hDC, m_hglrcZ)) if ( !qwglMakeCurrent( dc.m_hDC, win32.hGLRC ) ) { common->Printf( "ERROR: wglMakeCurrent failed..\n " ); common->Printf( "Please restart " EDITOR_WINDOWTEXT " if the Z view is not working\n" ); } else { QE_CheckOpenGLForErrors(); Z_Draw (); //qwglSwapBuffers( m_dcZ ); qwglSwapBuffers( dc.m_hDC ); TRACE( "Z Paint\n" ); } }
void CZWnd::OnPaint() { CPaintDC dc(this); // device context for painting //if (!wglMakeCurrent(m_dcZ, m_hglrcZ)) if (!qwglMakeCurrent(dc.m_hDC, m_hglrcZ)) { Sys_Printf("ERROR: wglMakeCurrent failed..\n "); Sys_Printf("Please restart QERadiant if the Z view is not working\n"); } else { QE_CheckOpenGLForErrors(); Z_Draw (); //qwglSwapBuffers(m_dcZ); qwglSwapBuffers(dc.m_hDC); // TRACE("Z Paint\n"); } }
/* ============== Z_Draw ============== */ void Z_Draw( void ){ #ifdef DBG_WINDOWPOS CheckWatchit( "Z_Draw" ); #endif brush_t *brush; float w, h; double start, end; qtexture_t *q; float top, bottom; vec3_t org_top, org_bottom, dir_up, dir_down; int xCam = z.width / 3; if ( !active_brushes.next ) { return; // not valid yet } if ( z.timing ) { start = Sys_DoubleTime(); } // // clear // glViewport( 0, 0, z.width, z.height ); glClearColor( g_qeglobals.d_savedinfo.colors[COLOR_GRIDBACK][0], g_qeglobals.d_savedinfo.colors[COLOR_GRIDBACK][1], g_qeglobals.d_savedinfo.colors[COLOR_GRIDBACK][2], 0 ); /* GL Bug */ /* When not using hw acceleration, gl will fault if we clear the depth buffer bit on the first pass. The hack fix is to set the GL_DEPTH_BUFFER_BIT only after Z_Draw() has been called once. Yeah, right. */ glClear( glbitClear ); glbitClear |= GL_DEPTH_BUFFER_BIT; glMatrixMode( GL_PROJECTION ); glLoadIdentity(); w = z.width / 2 / z.scale; h = z.height / 2 / z.scale; glOrtho( -w, w, z.origin[2] - h, z.origin[2] + h, -8, 8 ); glDisable( GL_TEXTURE_2D ); glDisable( GL_TEXTURE_1D ); glDisable( GL_DEPTH_TEST ); glDisable( GL_BLEND ); // // now draw the grid // Z_DrawGrid(); // // draw stuff // glDisable( GL_CULL_FACE ); glShadeModel( GL_FLAT ); glPolygonMode( GL_FRONT_AND_BACK, GL_FILL ); glDisable( GL_TEXTURE_2D ); glDisable( GL_BLEND ); glDisable( GL_DEPTH_TEST ); // draw filled interiors and edges dir_up[0] = 0 ; dir_up[1] = 0; dir_up[2] = 1; dir_down[0] = 0 ; dir_down[1] = 0; dir_down[2] = -1; VectorCopy( z.origin, org_top ); org_top[2] = g_MaxWorldCoord; VectorCopy( z.origin, org_bottom ); org_bottom[2] = g_MinWorldCoord; for ( brush = active_brushes.next ; brush != &active_brushes ; brush = brush->next ) { if ( brush->bFiltered ) { continue; } if ( brush->mins[0] >= z.origin[0] || brush->maxs[0] <= z.origin[0] || brush->mins[1] >= z.origin[1] || brush->maxs[1] <= z.origin[1] ) { continue; } if ( !Brush_Ray( org_top, dir_down, brush, &top ) ) { continue; } top = org_top[2] - top; if ( !Brush_Ray( org_bottom, dir_up, brush, &bottom ) ) { continue; } bottom = org_bottom[2] + bottom; q = brush->brush_faces->pShader->getTexture(); glColor3f( q->color[0], q->color[1], q->color[2] ); glBegin( GL_QUADS ); glVertex2f( -xCam, bottom ); glVertex2f( xCam, bottom ); glVertex2f( xCam, top ); glVertex2f( -xCam, top ); glEnd(); glColor3f( 1,1,1 ); glBegin( GL_LINE_LOOP ); glVertex2f( -xCam, bottom ); glVertex2f( xCam, bottom ); glVertex2f( xCam, top ); glVertex2f( -xCam, top ); glEnd(); } // // now draw selected brushes // for ( brush = selected_brushes.next ; brush != &selected_brushes ; brush = brush->next ) { if ( !( brush->mins[0] >= z.origin[0] || brush->maxs[0] <= z.origin[0] || brush->mins[1] >= z.origin[1] || brush->maxs[1] <= z.origin[1] ) ) { if ( Brush_Ray( org_top, dir_down, brush, &top ) ) { top = org_top[2] - top; if ( Brush_Ray( org_bottom, dir_up, brush, &bottom ) ) { bottom = org_bottom[2] + bottom; q = brush->brush_faces->pShader->getTexture(); glColor3f( q->color[0], q->color[1], q->color[2] ); glBegin( GL_QUADS ); glVertex2f( -xCam, bottom ); glVertex2f( xCam, bottom ); glVertex2f( xCam, top ); glVertex2f( -xCam, top ); glEnd(); } } } glColor3fv( g_qeglobals.d_savedinfo.colors[COLOR_SELBRUSHES] ); glBegin( GL_LINE_LOOP ); glVertex2f( -xCam, brush->mins[2] ); glVertex2f( xCam, brush->mins[2] ); glVertex2f( xCam, brush->maxs[2] ); glVertex2f( -xCam, brush->maxs[2] ); glEnd(); } ZDrawCameraIcon(); glFinish(); QE_CheckOpenGLForErrors(); if ( z.timing ) { end = Sys_DoubleTime(); Sys_Printf( "z: %i ms\n", (int)( 1000 * ( end - start ) ) ); } }
/* ============ 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 ); }
/* ======================================================================================================================= Z_Draw ======================================================================================================================= */ void Z_Draw(void) { brush_t *brush; float top, bottom; idVec3 org_top, org_bottom, dir_up, dir_down; int xCam = z.width / 3; if (!active_brushes.next) { return; // not valid yet } // clear glViewport(0, 0, z.width, z.height); glScissor(0, 0, z.width, z.height); glClearColor ( g_qeglobals.d_savedinfo.colors[COLOR_GRIDBACK][0], g_qeglobals.d_savedinfo.colors[COLOR_GRIDBACK][1], g_qeglobals.d_savedinfo.colors[COLOR_GRIDBACK][2], 0 ); /* * GL Bug £ * When not using hw acceleration, gl will fault if we clear the depth buffer bit * on the first pass. The hack fix is to set the GL_DEPTH_BUFFER_BIT only after * Z_Draw() has been called once. Yeah, right. £ * glClear(glbitClear); */ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // // glbitClear |= GL_DEPTH_BUFFER_BIT; // glClear(GL_DEPTH_BUFFER_BIT); // const float w = z.width / 2 / z.scale; const float h = z.height / 2 / z.scale; GL_ProjectionMatrix.LoadIdentity(); GL_ProjectionMatrix.Ortho(-w, w, z.origin[2] - h, z.origin[2] + h, -8, 8); globalImages->BindNull(); glDisable(GL_DEPTH_TEST); glDisable(GL_BLEND); // now draw the grid Z_DrawGrid(); // draw stuff glDisable(GL_CULL_FACE); glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); glLineWidth(1.0f); globalImages->BindNull(); // draw filled interiors and edges dir_up[0] = 0; dir_up[1] = 0; dir_up[2] = 1; dir_down[0] = 0; dir_down[1] = 0; dir_down[2] = -1; VectorCopy(z.origin, org_top); org_top[2] = 4096; VectorCopy(z.origin, org_bottom); org_bottom[2] = -4096; for (brush = active_brushes.next; brush != &active_brushes; brush = brush->next) { if ( brush->mins[0] >= z.origin[0] || brush->maxs[0] <= z.origin[0] || brush->mins[1] >= z.origin[1] || brush->maxs[1] <= z.origin[1] ) { continue; } if (!Brush_Ray(org_top, dir_down, brush, &top)) { continue; } top = org_top[2] - top; if (!Brush_Ray(org_bottom, dir_up, brush, &bottom)) { continue; } bottom = org_bottom[2] + bottom; //q = declManager->FindMaterial(brush->brush_faces->texdef.name); fhImmediateMode im; im.Color3f(brush->owner->eclass->color.x, brush->owner->eclass->color.y, brush->owner->eclass->color.z); im.Begin(GL_QUADS); im.Vertex2f(-xCam, bottom); im.Vertex2f(xCam, bottom); im.Vertex2f(xCam, top); im.Vertex2f(-xCam, top); im.End(); im.Color3f(1, 1, 1); im.Begin(GL_LINE_LOOP); im.Vertex2f(-xCam, bottom); im.Vertex2f(xCam, bottom); im.Vertex2f(xCam, top); im.Vertex2f(-xCam, top); im.End(); } // now draw selected brushes fhImmediateMode im; for (brush = selected_brushes.next; brush != &selected_brushes; brush = brush->next) { if ( !( brush->mins[0] >= z.origin[0] || brush->maxs[0] <= z.origin[0] || brush->mins[1] >= z.origin[1] || brush->maxs[1] <= z.origin[1] ) ) { if (Brush_Ray(org_top, dir_down, brush, &top)) { top = org_top[2] - top; if (Brush_Ray(org_bottom, dir_up, brush, &bottom)) { bottom = org_bottom[2] + bottom; //q = declManager->FindMaterial(brush->brush_faces->texdef.name); im.Color3f(brush->owner->eclass->color.x, brush->owner->eclass->color.y, brush->owner->eclass->color.z); im.Begin(GL_QUADS); im.Vertex2f(-xCam, bottom); im.Vertex2f(xCam, bottom); im.Vertex2f(xCam, top); im.Vertex2f(-xCam, top); im.End(); } } } im.Color3fv(g_qeglobals.d_savedinfo.colors[COLOR_SELBRUSHES].ToFloatPtr()); im.Begin(GL_LINE_LOOP); im.Vertex2f(-xCam, brush->mins[2]); im.Vertex2f(xCam, brush->mins[2]); im.Vertex2f(xCam, brush->maxs[2]); im.Vertex2f(-xCam, brush->maxs[2]); im.End(); } ZDrawCameraIcon(); ZDrawZClip(); glFinish(); QE_CheckOpenGLForErrors(); }
// will free all GL binded qtextures and shaders // NOTE: doesn't make much sense out of Radiant exit or called during a reload void WINAPI QERApp_FreeShaders() { int i; brush_t *b; // store the shader names used by the patches for(i=0; i<PatchShaders.GetSize(); i++) delete PatchShaders.GetAt(i); PatchShaders.RemoveAll(); for (b=active_brushes.next ; b != NULL && b != &active_brushes ; b=b->next) { if (b->patchBrush) PushPatch(b->pPatch); } for (b=selected_brushes.next ; b != NULL && b != &selected_brushes ; b=b->next) { if (b->patchBrush) PushPatch(b->pPatch); } // reload shaders // empty the actives shaders list g_ActiveShaders.ReleaseAll(); g_Shaders.ReleaseAll(); // empty the main g_qeglobals.d_qtextures list // FIXME: when we reload later on, we need to have the shader names // for brushes it's stored in the texdef // but patches don't have texdef // see bug 104655 for details // so the solution, build an array of patchMesh_t* and their shader names #ifdef _DEBUG Sys_Printf("FIXME: bug 104655 workaround\n"); #endif // NOTE: maybe before we'd like to set all qtexture_t in the shaders list to notex? // NOTE: maybe there are some qtexture_t we don't want to erase? For plain color faces maybe? // NOTE: the GL textures are freed later on if (g_qeglobals.d_qtextures) { qtexture_t* pTex = g_qeglobals.d_qtextures->next; while (pTex != NULL && pTex != g_qeglobals.d_qtextures) { qtexture_t* pNextTex = pTex->next; if (g_qeglobals.bSurfacePropertiesPlugin) { // Timo // Surface properties plugin #ifdef _DEBUG if ( !pTex->pData ) Sys_Printf("WARNING: found a qtexture_t* with no IPluginQTexture\n"); #endif if ( pTex->pData ) GETPLUGINTEXDEF(pTex)->DecRef(); } free(pTex); pTex = pNextTex; } } // free GL bindings GLuint* pGln = new GLuint[texture_extension_number-1]; qglGenTextures(texture_extension_number-1, pGln); QE_CheckOpenGLForErrors(); qglDeleteTextures(texture_extension_number-1, pGln); QE_CheckOpenGLForErrors(); delete []pGln; texture_extension_number = 1; g_qeglobals.d_qtextures = NULL; // free the map g_qeglobals.d_qtexmap->RemoveAll(); }
/* ============== XY_Draw ============== */ void XY_Draw (void) { brush_t *brush; float w, h; entity_t *e; double start, end; vec3_t mins, maxs; int drawn, culled; int i; if (!active_brushes.next) return; // not valid yet if (g_qeglobals.d_xy.timing) start = Sys_DoubleTime (); // // clear // g_qeglobals.d_xy.d_dirty = false; glViewport(0, 0, g_qeglobals.d_xy.width, g_qeglobals.d_xy.height); glClearColor ( g_qeglobals.d_savedinfo.colors[COLOR_GRIDBACK][0], g_qeglobals.d_savedinfo.colors[COLOR_GRIDBACK][1], g_qeglobals.d_savedinfo.colors[COLOR_GRIDBACK][2], 0); glClear(GL_COLOR_BUFFER_BIT); // // set up viewpoint // glMatrixMode(GL_PROJECTION); glLoadIdentity (); w = g_qeglobals.d_xy.width/2 / g_qeglobals.d_xy.scale; h = g_qeglobals.d_xy.height/2 / g_qeglobals.d_xy.scale; mins[0] = g_qeglobals.d_xy.origin[0] - w; maxs[0] = g_qeglobals.d_xy.origin[0] + w; mins[1] = g_qeglobals.d_xy.origin[1] - h; maxs[1] = g_qeglobals.d_xy.origin[1] + h; glOrtho (mins[0], maxs[0], mins[1], maxs[1], -8000, 8000); // // now draw the grid // XY_DrawGrid (); // // draw stuff // glShadeModel (GL_FLAT); glDisable(GL_TEXTURE_2D); glDisable(GL_TEXTURE_1D); glDisable(GL_DEPTH_TEST); glDisable(GL_BLEND); glColor3f(0, 0, 0); // glEnable (GL_LINE_SMOOTH); drawn = culled = 0; e = NULL; for (brush = active_brushes.next ; brush != &active_brushes ; brush=brush->next) { if (brush->mins[0] > maxs[0] || brush->mins[1] > maxs[1] || brush->maxs[0] < mins[0] || brush->maxs[1] < mins[1] ) { culled++; continue; // off screen } if (FilterBrush (brush)) continue; drawn++; if (brush->owner != e) { e = brush->owner; glColor3fv(e->eclass->color); } Brush_DrawXY( brush ); } DrawPathLines (); // // draw pointfile // if ( g_qeglobals.d_pointfile_display_list) glCallList (g_qeglobals.d_pointfile_display_list); // // draw block grid // if ( g_qeglobals.show_blocks) XY_DrawBlockGrid (); // // now draw selected brushes // glTranslatef( g_qeglobals.d_select_translate[0], g_qeglobals.d_select_translate[1], g_qeglobals.d_select_translate[2]); glColor3f(1.0, 0.0, 0.0); glEnable (GL_LINE_STIPPLE); glLineStipple (3, 0xaaaa); glLineWidth (2); for (brush = selected_brushes.next ; brush != &selected_brushes ; brush=brush->next) { drawn++; Brush_DrawXY( brush ); } glDisable (GL_LINE_STIPPLE); glLineWidth (1); // edge / vertex flags if (g_qeglobals.d_select_mode == sel_vertex) { glPointSize (4); glColor3f (0,1,0); glBegin (GL_POINTS); for (i=0 ; i<g_qeglobals.d_numpoints ; i++) glVertex3fv (g_qeglobals.d_points[i]); glEnd (); glPointSize (1); } else if (g_qeglobals.d_select_mode == sel_edge) { float *v1, *v2; glPointSize (4); glColor3f (0,0,1); glBegin (GL_POINTS); for (i=0 ; i<g_qeglobals.d_numedges ; i++) { v1 = g_qeglobals.d_points[g_qeglobals.d_edges[i].p1]; v2 = g_qeglobals.d_points[g_qeglobals.d_edges[i].p2]; glVertex3f ( (v1[0]+v2[0])*0.5,(v1[1]+v2[1])*0.5,(v1[2]+v2[2])*0.5); } glEnd (); glPointSize (1); } glTranslatef (-g_qeglobals.d_select_translate[0], -g_qeglobals.d_select_translate[1], -g_qeglobals.d_select_translate[2]); // // now draw camera point // DrawCameraIcon (); DrawZIcon (); glFinish(); QE_CheckOpenGLForErrors(); if (g_qeglobals.d_xy.timing) { end = Sys_DoubleTime (); Sys_Printf ("xy: %i ms\n", (int)(1000*(end-start))); } }
/* ============ 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 ); }
void CCamWnd::Cam_Draw() { brush_t *brush; face_t *face; float screenaspect; float yfov; double start, end; int i; /* FILE *f = fopen("g:/nardo/raduffy/editorhack.dat", "w"); if (f != NULL) { fwrite(&m_Camera.origin[0], sizeof(float), 1, f); fwrite(&m_Camera.origin[1], sizeof(float), 1, f); fwrite(&m_Camera.origin[2], sizeof(float), 1, f); fwrite(&m_Camera.angles[PITCH], sizeof(float), 1, f); fwrite(&m_Camera.angles[YAW], sizeof(float), 1, f); fclose(f); } */ if (!active_brushes.next) return; // not valid yet if (m_Camera.timing) start = Sys_DoubleTime (); // // clear // QE_CheckOpenGLForErrors(); qglViewport(0, 0, m_Camera.width, m_Camera.height); qglScissor(0, 0, m_Camera.width, m_Camera.height); qglClearColor (g_qeglobals.d_savedinfo.colors[COLOR_CAMERABACK][0], g_qeglobals.d_savedinfo.colors[COLOR_CAMERABACK][1], g_qeglobals.d_savedinfo.colors[COLOR_CAMERABACK][2], 0); qglClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // // set up viewpoint // vec5_t lightPos; if (g_PrefsDlg.m_bGLLighting) { qglEnable(GL_LIGHTING); //qglEnable(GL_LIGHT0); lightPos[0] = lightPos[1] = lightPos[2] = 3.5; lightPos[3] = 1.0; qglLightModelfv(GL_LIGHT_MODEL_AMBIENT, lightPos); //qglLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, GL_TRUE); //lightPos[0] = lightPos[1] = lightPos[2] = 3.5; //qglLightfv(GL_LIGHT0, GL_AMBIENT, lightPos); } else { qglDisable(GL_LIGHTING); } qglMatrixMode(GL_PROJECTION); qglLoadIdentity (); screenaspect = (float)m_Camera.width / m_Camera.height; yfov = 2*atan((float)m_Camera.height / m_Camera.width)*180/Q_PI; qgluPerspective (yfov, screenaspect, 2, 8192); qglRotatef (-90, 1, 0, 0); // put Z going up qglRotatef (90, 0, 0, 1); // put Z going up qglRotatef (m_Camera.angles[0], 0, 1, 0); qglRotatef (-m_Camera.angles[1], 0, 0, 1); qglTranslatef (-m_Camera.origin[0], -m_Camera.origin[1], -m_Camera.origin[2]); Cam_BuildMatrix (); //if (m_Camera.draw_mode == cd_light) //{ // if (g_PrefsDlg.m_bGLLighting) // { // VectorCopy(m_Camera.origin, lightPos); // lightPos[3] = 1; // qglLightfv(GL_LIGHT0, GL_POSITION, lightPos); // } //} InitCull (); // // draw stuff // GLfloat lAmbient[] = {1.0, 1.0, 1.0, 1.0}; switch (m_Camera.draw_mode) { case cd_wire: qglPolygonMode (GL_FRONT_AND_BACK, GL_LINE); qglDisable(GL_TEXTURE_2D); qglDisable(GL_TEXTURE_1D); qglDisable(GL_BLEND); qglDisable(GL_DEPTH_TEST); qglColor3f(1.0, 1.0, 1.0); // qglEnable (GL_LINE_SMOOTH); break; case cd_solid: qglCullFace(GL_FRONT); qglEnable(GL_CULL_FACE); qglShadeModel (GL_FLAT); qglPolygonMode (GL_FRONT_AND_BACK, GL_FILL); qglDisable(GL_TEXTURE_2D); qglDisable(GL_BLEND); qglEnable(GL_DEPTH_TEST); qglDepthFunc (GL_LEQUAL); break; case cd_texture: qglCullFace(GL_FRONT); qglEnable(GL_CULL_FACE); qglShadeModel (GL_FLAT); qglPolygonMode (GL_FRONT_AND_BACK, GL_FILL); qglEnable(GL_TEXTURE_2D); qglTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); qglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); qglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); qglDisable(GL_BLEND); qglEnable(GL_DEPTH_TEST); qglDepthFunc (GL_LEQUAL); break; case cd_blend: qglCullFace(GL_FRONT); qglEnable(GL_CULL_FACE); qglShadeModel (GL_FLAT); qglPolygonMode (GL_FRONT_AND_BACK, GL_FILL); qglEnable(GL_TEXTURE_2D); qglTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); qglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); qglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); qglDisable(GL_DEPTH_TEST); qglEnable (GL_BLEND); qglBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); break; } qglMatrixMode(GL_TEXTURE); m_nNumTransBrushes = 0; for (brush = active_brushes.next ; brush != &active_brushes ; brush=brush->next) { //DrawLightRadius(brush); if (CullBrush (brush)) continue; if (FilterBrush (brush)) continue; if ((brush->brush_faces->texdef.flags & (SURF_TRANS33 | SURF_TRANS66)) || (brush->brush_faces->d_texture->bFromShader && brush->brush_faces->d_texture->fTrans != 1.0)) { m_TransBrushes [ m_nNumTransBrushes++ ] = brush; } else { //-- if (brush->patchBrush) //-- m_TransBrushes [ m_nNumTransBrushes++ ] = brush; //-- else Brush_Draw(brush); } } if (g_PrefsDlg.m_bGLLighting) { qglDisable (GL_LIGHTING); } // //qglDepthMask ( 0 ); // Don't write to depth buffer qglEnable ( GL_BLEND ); qglBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); for ( i = 0; i < m_nNumTransBrushes; i++ ) Brush_Draw (m_TransBrushes[i]); //qglDepthMask ( 1 ); // Ok, write now qglMatrixMode(GL_PROJECTION); // // now draw selected brushes // if (g_PrefsDlg.m_bGLLighting) { qglEnable (GL_LIGHTING); } qglTranslatef (g_qeglobals.d_select_translate[0], g_qeglobals.d_select_translate[1], g_qeglobals.d_select_translate[2]); qglMatrixMode(GL_TEXTURE); brush_t* pList = (g_bClipMode && g_pSplitList) ? g_pSplitList : &selected_brushes; // draw normally for (brush = pList->next ; brush != pList ; brush=brush->next) { //DrawLightRadius(brush); //if (brush->patchBrush && g_qeglobals.d_select_mode == sel_curvepoint) // continue; Brush_Draw(brush); } // blend on top qglMatrixMode(GL_PROJECTION); qglDisable (GL_LIGHTING); qglColor4f(1.0, 0.0, 0.0, 0.3); qglEnable (GL_BLEND); qglPolygonMode (GL_FRONT_AND_BACK, GL_FILL); qglBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); qglDisable (GL_TEXTURE_2D); for (brush = pList->next ; brush != pList ; brush=brush->next) { if ( (brush->patchBrush && g_qeglobals.d_select_mode == sel_curvepoint) || (brush->terrainBrush && g_qeglobals.d_select_mode == sel_terrainpoint) ) continue; for (face=brush->brush_faces ; face ; face=face->next) Face_Draw( face ); } int nCount = g_ptrSelectedFaces.GetSize(); if (nCount > 0) { for (int i = 0; i < nCount; i++) { face_t *selFace = reinterpret_cast<face_t*>(g_ptrSelectedFaces.GetAt(i)); Face_Draw(selFace); } } // non-zbuffered outline qglDisable (GL_BLEND); qglDisable (GL_DEPTH_TEST); qglPolygonMode (GL_FRONT_AND_BACK, GL_LINE); qglColor3f (1, 1, 1); for (brush = pList->next ; brush != pList ; brush=brush->next) { if (g_qeglobals.dontDrawSelectedOutlines || (brush->patchBrush && g_qeglobals.d_select_mode == sel_curvepoint) || (brush->terrainBrush && g_qeglobals.d_select_mode == sel_terrainpoint)) continue; for (face=brush->brush_faces ; face ; face=face->next) Face_Draw( face ); } // edge / vertex flags if (g_qeglobals.d_select_mode == sel_vertex) { qglPointSize (4); qglColor3f (0,1,0); qglBegin (GL_POINTS); for (i=0 ; i<g_qeglobals.d_numpoints ; i++) qglVertex3fv (g_qeglobals.d_points[i]); qglEnd (); qglPointSize (1); } else if (g_qeglobals.d_select_mode == sel_edge) { float *v1, *v2; qglPointSize (4); qglColor3f (0,0,1); qglBegin (GL_POINTS); for (i=0 ; i<g_qeglobals.d_numedges ; i++) { v1 = g_qeglobals.d_points[g_qeglobals.d_edges[i].p1]; v2 = g_qeglobals.d_points[g_qeglobals.d_edges[i].p2]; qglVertex3f ( (v1[0]+v2[0])*0.5,(v1[1]+v2[1])*0.5,(v1[2]+v2[2])*0.5); } qglEnd (); qglPointSize (1); } g_splineList->draw(static_cast<qboolean>(g_qeglobals.d_select_mode == sel_addpoint || g_qeglobals.d_select_mode == sel_editpoint)); if (g_qeglobals.selectObject && (g_qeglobals.d_select_mode == sel_addpoint || g_qeglobals.d_select_mode == sel_editpoint)) { g_qeglobals.selectObject->drawSelection(); } // // draw pointfile // qglEnable(GL_DEPTH_TEST); DrawPathLines (); if (g_qeglobals.d_pointfile_display_list) { Pointfile_Draw(); // glCallList (g_qeglobals.d_pointfile_display_list); } // bind back to the default texture so that we don't have problems // elsewhere using/modifying texture maps between contexts qglBindTexture( GL_TEXTURE_2D, 0 ); #if 0 // area selection hack if (g_qeglobals.d_select_mode == sel_area) { qglEnable (GL_BLEND); qglBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); qglColor4f(0.0, 0.0, 1.0, 0.25); qglPolygonMode (GL_FRONT_AND_BACK, GL_FILL); qglRectfv(g_qeglobals.d_vAreaTL, g_qeglobals.d_vAreaBR); qglDisable (GL_BLEND); } #endif qglFinish(); QE_CheckOpenGLForErrors(); // Sys_EndWait(); if (m_Camera.timing) { end = Sys_DoubleTime (); Sys_Printf ("Camera: %i ms\n", (int)(1000*(end-start))); } }
/* ======================================================================================================================= ======================================================================================================================= */ void CNewTexWnd::OnPaint() { CPaintDC dc(this); // device context for painting int nOld = g_qeglobals.d_texturewin.m_nTotalHeight; //hdcTexture = GetDC(); if (!qwglMakeCurrent(dc.GetSafeHdc(), win32.hGLRC)) { common->Printf("ERROR: wglMakeCurrent failed..\n "); } else { const char *name; qglClearColor ( g_qeglobals.d_savedinfo.colors[COLOR_TEXTUREBACK][0], g_qeglobals.d_savedinfo.colors[COLOR_TEXTUREBACK][1], g_qeglobals.d_savedinfo.colors[COLOR_TEXTUREBACK][2], 0 ); qglViewport(0, 0, rectClient.Width(), rectClient.Height()); qglScissor(0, 0, rectClient.Width(), rectClient.Height()); qglMatrixMode(GL_PROJECTION); qglLoadIdentity(); qglClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); qglDisable(GL_DEPTH_TEST); qglDisable(GL_BLEND); qglOrtho(0, rectClient.Width(), origin.y - rectClient.Height(), origin.y, -100, 100); qglPolygonMode(GL_FRONT_AND_BACK, GL_FILL); // init stuff current.x = 8; current.y = -8; currentRow = 0; currentIndex = 0; while (1) { const idMaterial *mat = NextPos(); if (mat == NULL) { break; } int width = mat->GetEditorImage()->uploadWidth * ((float)g_PrefsDlg.m_nTextureScale / 100); int height = mat->GetEditorImage()->uploadHeight * ((float)g_PrefsDlg.m_nTextureScale / 100); // Is this texture visible? if ((draw.y - height - FONT_HEIGHT < origin.y) && (draw.y > origin.y - rectClient.Height())) { // if in use, draw a background qglLineWidth(1); qglColor3f(1, 1, 1); globalImages->BindNull(); qglBegin(GL_LINE_LOOP); qglVertex2f(draw.x - 1, draw.y + 1 - FONT_HEIGHT); qglVertex2f(draw.x - 1, draw.y - height - 1 - FONT_HEIGHT); qglVertex2f(draw.x + 1 + width, draw.y - height - 1 - FONT_HEIGHT); qglVertex2f(draw.x + 1 + width, draw.y + 1 - FONT_HEIGHT); qglEnd(); // Draw the texture float fScale = (g_PrefsDlg.m_bHiColorTextures == TRUE) ? ((float)g_PrefsDlg.m_nTextureScale / 100) : 1.0; mat->GetEditorImage()->Bind(); QE_CheckOpenGLForErrors(); qglColor3f(1, 1, 1); qglBegin(GL_QUADS); qglTexCoord2f(0, 0); qglVertex2f(draw.x, draw.y - FONT_HEIGHT); qglTexCoord2f(1, 0); qglVertex2f(draw.x + width, draw.y - FONT_HEIGHT); qglTexCoord2f(1, 1); qglVertex2f(draw.x + width, draw.y - FONT_HEIGHT - height); qglTexCoord2f(0, 1); qglVertex2f(draw.x, draw.y - FONT_HEIGHT - height); qglEnd(); // draw the selection border if ( !idStr::Icmp(g_qeglobals.d_texturewin.texdef.name, mat->GetName()) ) { qglLineWidth(3); qglColor3f(1, 0, 0); globalImages->BindNull(); qglBegin(GL_LINE_LOOP); qglVertex2f(draw.x - 4, draw.y - FONT_HEIGHT + 4); qglVertex2f(draw.x - 4, draw.y - FONT_HEIGHT - height - 4); qglVertex2f(draw.x + 4 + width, draw.y - FONT_HEIGHT - height - 4); qglVertex2f(draw.x + 4 + width, draw.y - FONT_HEIGHT + 4); qglEnd(); qglLineWidth(1); } // draw the texture name globalImages->BindNull(); qglColor3f(1, 1, 1); qglRasterPos2f(draw.x, draw.y - FONT_HEIGHT + 2); // don't draw the directory name for (name = mat->GetName(); *name && *name != '/' && *name != '\\'; name++) { ; } if (!*name) { name = mat->GetName(); } else { name++; } qglCallLists(strlen(name), GL_UNSIGNED_BYTE, name); //qglCallLists(va("%s -- %d, %d" strlen(name), GL_UNSIGNED_BYTE, name); } } g_qeglobals.d_texturewin.m_nTotalHeight = abs(draw.y) + 100; // reset the current texture globalImages->BindNull(); qglFinish(); qwglSwapBuffers(dc.GetSafeHdc()); TRACE("Texture Paint\n"); } if (g_PrefsDlg.m_bTextureScrollbar && (m_bNeedRange || g_qeglobals.d_texturewin.m_nTotalHeight != nOld)) { m_bNeedRange = false; SetScrollRange(SB_VERT, 0, g_qeglobals.d_texturewin.m_nTotalHeight, TRUE); } //ReleaseDC(hdcTexture); }