void idGLWidget::OnPaint() { if (!initialized) { CDC *dc = GetDC(); QEW_SetupPixelFormat(dc->m_hDC); ReleaseDC(dc); initialized = true; } CPaintDC dc(this); // device context for painting CRect rect; GetClientRect(rect); if (!qwglMakeCurrent(dc.m_hDC, win32.hGLRC)) { } qglViewport(0, 0, rect.Width(), rect.Height()); qglScissor(0, 0, rect.Width(), rect.Height()); qglMatrixMode(GL_PROJECTION); qglLoadIdentity(); qglClearColor (0.4f, 0.4f, 0.4f, 0.7f); qglClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); qglDisable(GL_DEPTH_TEST); qglDisable(GL_BLEND); qglOrtho(0, rect.Width(), 0, rect.Height(), -256, 256); if (drawable) { drawable->draw(1, 1, rect.Width()-1, rect.Height()-1); } else { qglViewport(0, 0, rect.Width(), rect.Height()); qglScissor(0, 0, rect.Width(), rect.Height()); qglMatrixMode(GL_PROJECTION); qglLoadIdentity(); qglClearColor (0.4f, 0.4f, 0.4f, 0.7f); qglClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); } qwglSwapBuffers(dc); qglFlush(); qwglMakeCurrent(win32.hDC, win32.hGLRC); }
/* ================ RB_SetGL2D ================ */ void RB_SetGL2D(void) { backEnd.projection2D = qtrue; // set 2D virtual screen size qglViewport(0, 0, glConfig.vidWidth, glConfig.vidHeight); qglScissor(0, 0, glConfig.vidWidth, glConfig.vidHeight); qglMatrixMode(GL_PROJECTION); qglLoadIdentity(); qglOrtho(0, glConfig.vidWidth, glConfig.vidHeight, 0, 0, 1); qglMatrixMode(GL_MODELVIEW); qglLoadIdentity(); GL_State(GLS_DEPTHTEST_DISABLE | GLS_SRCBLEND_SRC_ALPHA | GLS_DSTBLEND_ONE_MINUS_SRC_ALPHA); qglDisable(GL_FOG); //----(SA) added qglDisable(GL_CULL_FACE); qglDisable(GL_CLIP_PLANE0); // set time for 2D shaders backEnd.refdef.time = ri.Milliseconds(); backEnd.refdef.floatTime = backEnd.refdef.time * 0.001f; }
/* ================ RB_SetGL2D ================ */ void RB_SetGL2D (void) { if ( tess.numIndexes | tess.numVertexes ) Com_Printf(" Going 2d with verts?" ); backEnd.projection2D = qtrue; backEnd.currentModel = 0; // set 2D virtual screen size qglViewport( 0, 0, glConfig.vidWidth, glConfig.vidHeight ); qglScissor( 0, 0, glConfig.vidWidth, glConfig.vidHeight ); qglMatrixMode(GL_PROJECTION); qglLoadIdentity (); qglOrtho (0, glConfig.vidWidth, glConfig.vidHeight, 0, 0, 1); qglMatrixMode(GL_MODELVIEW); qglLoadIdentity (); GL_State( GLS_DEPTHTEST_DISABLE | GLS_SRCBLEND_SRC_ALPHA | GLS_DSTBLEND_ONE_MINUS_SRC_ALPHA ); GL_Cull( CT_TWO_SIDED ); qglDisable( GL_CLIP_PLANE0 ); // set time for 2D shaders // tess.shaderTime = ri.Milliseconds(); }
/* ====================== RB_SetDefaultGLState This should initialize all GL state that any part of the entire program may touch, including the editor. ====================== */ void RB_SetDefaultGLState( void ) { int i; RB_LogComment( "--- R_SetDefaultGLState ---\n" ); qglClearDepth( 1.0f ); qglColor4f (1,1,1,1); // the vertex array is always enabled qglEnableClientState( GL_VERTEX_ARRAY ); qglEnableClientState( GL_TEXTURE_COORD_ARRAY ); qglDisableClientState( GL_COLOR_ARRAY ); // // make sure our GL state vector is set correctly // memset( &backEnd.glState, 0, sizeof( backEnd.glState ) ); backEnd.glState.forceGlState = true; qglColorMask( 1, 1, 1, 1 ); qglEnable( GL_DEPTH_TEST ); qglEnable( GL_BLEND ); qglEnable( GL_SCISSOR_TEST ); qglEnable( GL_CULL_FACE ); qglDisable( GL_LIGHTING ); qglDisable( GL_LINE_STIPPLE ); qglDisable( GL_STENCIL_TEST ); qglPolygonMode (GL_FRONT_AND_BACK, GL_FILL); qglDepthMask( GL_TRUE ); qglDepthFunc( GL_ALWAYS ); qglCullFace( GL_FRONT_AND_BACK ); qglShadeModel( GL_SMOOTH ); if ( r_useScissor.GetBool() ) { qglScissor( 0, 0, glConfig.vidWidth, glConfig.vidHeight ); } for ( i = glConfig.maxTextureUnits - 1 ; i >= 0 ; i-- ) { GL_SelectTexture( i ); // object linear texgen is our default qglTexGenf( GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR ); qglTexGenf( GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR ); qglTexGenf( GL_R, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR ); qglTexGenf( GL_Q, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR ); GL_TexEnv( GL_MODULATE ); qglDisable( GL_TEXTURE_2D ); if ( glConfig.texture3DAvailable ) { qglDisable( GL_TEXTURE_3D ); } if ( glConfig.cubeMapAvailable ) { qglDisable( GL_TEXTURE_CUBE_MAP_EXT ); } } }
/* * RB_ApplyScissor */ void RB_ApplyScissor( void ) { int h = rb.gl.scissor[3]; if( rb.gl.scissorChanged ) { rb.gl.scissorChanged = false; qglScissor( rb.gl.scissor[0], rb.gl.fbHeight - h - rb.gl.scissor[1], rb.gl.scissor[2], h ); } }
static void SetViewportAndScissor( void ) { GL_SetProjectionMatrix( backEnd.viewParms.projectionMatrix ); // set the window clipping qglViewport( backEnd.viewParms.viewportX, backEnd.viewParms.viewportY, backEnd.viewParms.viewportWidth, backEnd.viewParms.viewportHeight ); qglScissor( backEnd.viewParms.viewportX, backEnd.viewParms.viewportY, backEnd.viewParms.viewportWidth, backEnd.viewParms.viewportHeight ); }
/* * RB_Scissor */ void RB_Scissor( int x, int y, int w, int h ) { qglScissor( x, rb.gl.fbHeight - h - y, w, h ); rb.gl.scissor[0] = x; rb.gl.scissor[1] = y; rb.gl.scissor[2] = w; rb.gl.scissor[3] = h; }
/* * RB_Scissor */ void RB_Scissor( int x, int y, int w, int h ) { qglScissor( x, glConfig.height - h - y, w, h ); rb.gl.scissorX = x; rb.gl.scissorY = y; rb.gl.scissorW = w; rb.gl.scissorH = h; }
/* ================== RB_STD_LightScale Perform extra blending passes to multiply the entire buffer by a floating point value ================== */ void RB_STD_LightScale( void ) { float v, f; if ( backEnd.overBright == 1.0f ) { return; } if ( r_skipLightScale.GetBool() ) { return; } // the scissor may be smaller than the viewport for subviews if ( r_useScissor.GetBool() ) { qglScissor( backEnd.viewDef->viewport.x1 + backEnd.viewDef->scissor.x1, backEnd.viewDef->viewport.y1 + backEnd.viewDef->scissor.y1, backEnd.viewDef->scissor.x2 - backEnd.viewDef->scissor.x1 + 1, backEnd.viewDef->scissor.y2 - backEnd.viewDef->scissor.y1 + 1 ); backEnd.currentScissor = backEnd.viewDef->scissor; } // full screen blends qglLoadIdentity(); qglMatrixMode( GL_PROJECTION ); qglPushMatrix(); qglLoadIdentity(); qglOrtho( 0, 1, 0, 1, -1, 1 ); GL_State( GLS_SRCBLEND_DST_COLOR | GLS_DSTBLEND_SRC_COLOR ); GL_Cull( CT_TWO_SIDED ); // so mirror views also get it globalImages->BindNull(); qglDisable( GL_DEPTH_TEST ); qglDisable( GL_STENCIL_TEST ); v = 1; while ( idMath::Fabs( v - backEnd.overBright ) > 0.01 ) { // a little extra slop f = backEnd.overBright / v; f /= 2; if ( f > 1 ) { f = 1; } qglColor3f( f, f, f ); v = v * f * 2; qglBegin( GL_QUADS ); qglVertex2f( 0,0 ); qglVertex2f( 0,1 ); qglVertex2f( 1,1 ); qglVertex2f( 1,0 ); qglEnd(); } qglPopMatrix(); qglEnable( GL_DEPTH_TEST ); qglMatrixMode( GL_MODELVIEW ); GL_Cull( CT_FRONT_SIDED ); }
/* ================= R_BloomScreen ================= */ void R_BloomScreen( void ) { if( !r_bloom->integer ) return; if(r_bloom_sky_only->integer) return; if ( backEnd.doneBloom ) return; if ( !backEnd.doneSurfaces ) return; backEnd.doneBloom = qtrue; if( !bloom.started ) { R_Bloom_InitTextures(); if( !bloom.started ) return; } if ( !backEnd.projection2D ) RB_SetGL2D(); #if 0 // set up full screen workspace GL_TexEnv( GL_MODULATE ); qglScissor( 0, 0, glConfig.vidWidth, glConfig.vidHeight ); qglViewport( 0, 0, glConfig.vidWidth, glConfig.vidHeight ); qglMatrixMode( GL_PROJECTION ); qglLoadIdentity (); qglOrtho( 0, glConfig.vidWidth, glConfig.vidHeight, 0, 0, 1 ); qglMatrixMode( GL_MODELVIEW ); qglLoadIdentity (); GL_Cull( CT_TWO_SIDED ); #endif qglColor4f( 1, 1, 1, 1 ); //Backup the old screen in a texture R_Bloom_BackupScreen(); // create the bloom texture using one of a few methods if(r_bloom_cascade->integer) R_Bloom_Cascaded(); else R_Bloom_WarsowEffect (); // R_Bloom_CreateEffect(); // restore the screen-backup to the screen R_Bloom_RestoreScreen(); // Do the final pass using the bloom texture for the final effect R_Bloom_DrawEffect (); // LEILEI - Lens Bloom Hack // The concept of this is to inverse the coordinates on both X and Y, // then scale outward using the offset value applied, as well as the modulated color // applied to give a rainbow streak effect. Most effective with high bloom darkness // values. if(r_bloom_reflection->integer) R_Bloom_LensEffect (); }
void SetViewportAndScissor( void ) { qglMatrixMode(GL_PROJECTION); qglLoadMatrixf( backEnd.viewParms.projectionMatrix ); qglMatrixMode(GL_MODELVIEW); // set the window clipping qglViewport( backEnd.viewParms.viewportX, backEnd.viewParms.viewportY, backEnd.viewParms.viewportWidth, backEnd.viewParms.viewportHeight ); qglScissor( backEnd.viewParms.viewportX, backEnd.viewParms.viewportY, backEnd.viewParms.viewportWidth, backEnd.viewParms.viewportHeight ); }
static void SetViewportAndScissor( void ) { qglMatrixMode(GL_PROJECTION); qglLoadMatrixf( backEnd.viewParms.projectionMatrix ); qglMatrixMode(GL_MODELVIEW); // set the window clipping qglViewport( backEnd.viewParms.viewportX, backEnd.viewParms.viewportY, backEnd.viewParms.viewportWidth, backEnd.viewParms.viewportHeight ); if(r_subviewScissor->integer) { qglScissor( backEnd.viewParms.scissorMinX, backEnd.viewParms.scissorMinY, backEnd.viewParms.scissorMaxX - backEnd.viewParms.scissorMinX, backEnd.viewParms.scissorMaxY - backEnd.viewParms.scissorMinY ); } else { qglScissor( backEnd.viewParms.viewportX, backEnd.viewParms.viewportY, backEnd.viewParms.viewportWidth, backEnd.viewParms.viewportHeight ); } }
void idGLDrawableConsole::draw(int x, int y, int w, int h) { qglPushAttrib( GL_ALL_ATTRIB_BITS ); qglClearColor( 0.1f, 0.1f, 0.1f, 0.0f ); qglScissor( 0, 0, w, h ); qglClear( GL_COLOR_BUFFER_BIT ); renderSystem->BeginFrame( w, h ); console->Draw( true ); renderSystem->EndFrame( NULL, NULL ); qglPopAttrib(); }
/* ================== RB_STD_FogAllLights ================== */ void RB_STD_FogAllLights( void ) { viewLight_t *vLight; if ( r_skipFogLights.GetBool() || r_showOverDraw.GetInteger() != 0 || backEnd.viewDef->isXraySubview /* dont fog in xray mode*/ ) { return; } qglDisable( GL_STENCIL_TEST ); for ( vLight = backEnd.viewDef->viewLights ; vLight ; vLight = vLight->next ) { backEnd.vLight = vLight; if ( !vLight->lightShader->IsFogLight() && !vLight->lightShader->IsBlendLight() ) { continue; } #if 0 // _D3XP disabled that if ( r_ignore.GetInteger() ) { // we use the stencil buffer to guarantee that no pixels will be // double fogged, which happens in some areas that are thousands of // units from the origin backEnd.currentScissor = vLight->scissorRect; if ( r_useScissor.GetBool() ) { qglScissor( backEnd.viewDef->viewport.x1 + backEnd.currentScissor.x1, backEnd.viewDef->viewport.y1 + backEnd.currentScissor.y1, backEnd.currentScissor.x2 + 1 - backEnd.currentScissor.x1, backEnd.currentScissor.y2 + 1 - backEnd.currentScissor.y1 ); } qglClear( GL_STENCIL_BUFFER_BIT ); qglEnable( GL_STENCIL_TEST ); // only pass on the cleared stencil values qglStencilFunc( GL_EQUAL, 128, 255 ); // when we pass the stencil test and depth test and are going to draw, // increment the stencil buffer so we don't ever draw on that pixel again qglStencilOp( GL_KEEP, GL_KEEP, GL_INCR ); } #endif if ( vLight->lightShader->IsFogLight() ) { RB_FogPass( vLight->globalInteractions, vLight->localInteractions ); } else if ( vLight->lightShader->IsBlendLight() ) { RB_BlendLight( vLight->globalInteractions, vLight->localInteractions ); } qglDisable( GL_STENCIL_TEST ); } qglEnable( GL_STENCIL_TEST ); }
/* ================== GL_Scissor ================== */ void GL_Scissor (rect_t rect){ if (glState.scissorX == rect.x && glState.scissorY == rect.y && glState.scissorWidth == rect.width && glState.scissorHeight == rect.height) return; glState.scissorX = rect.x; glState.scissorY = rect.y; glState.scissorWidth = rect.width; glState.scissorHeight = rect.height; qglScissor(rect.x, rect.y, rect.width, rect.height); }
/* ================== RB_RenderViewLight ================== */ static void RB_RenderViewLight(viewLight_t *vLight) { backEnd.vLight = vLight; // do fogging later if (vLight->lightShader->IsFogLight()) { return; } if (vLight->lightShader->IsBlendLight()) { return; } RB_LogComment("---------- RB_RenderViewLight 0x%p ----------\n", vLight); // clear the stencil buffer if needed if (vLight->globalShadows || vLight->localShadows) { backEnd.currentScissor = vLight->scissorRect; if (r_useScissor.GetBool()) { qglScissor(backEnd.viewDef->viewport.x1 + backEnd.currentScissor.x1, backEnd.viewDef->viewport.y1 + backEnd.currentScissor.y1, backEnd.currentScissor.x2 + 1 - backEnd.currentScissor.x1, backEnd.currentScissor.y2 + 1 - backEnd.currentScissor.y1); } qglClear(GL_STENCIL_BUFFER_BIT); } else { // no shadows, so no need to read or write the stencil buffer // we might in theory want to use GL_ALWAYS instead of disabling // completely, to satisfy the invarience rules qglStencilFunc(GL_ALWAYS, 128, 255); } backEnd.depthFunc = GLS_DEPTHFUNC_EQUAL; RB_StencilShadowPass(vLight->globalShadows); RB_CreateDrawInteractions(vLight->localInteractions); RB_StencilShadowPass(vLight->localShadows); RB_CreateDrawInteractions(vLight->globalInteractions); if (r_skipTranslucent.GetBool()) { return; } // disable stencil testing for translucent interactions, because // the shadow isn't calculated at their point, and the shadow // behind them may be depth fighting with a back side, so there // isn't any reasonable thing to do qglStencilFunc(GL_ALWAYS, 128, 255); backEnd.depthFunc = GLS_DEPTHFUNC_LESS; RB_CreateDrawInteractions(vLight->translucentInteractions); }
/* ============= RB_ScissorPic ============= */ const void *RB_Scissor ( const void *data ) { const scissorCommand_t *cmd; cmd = (const scissorCommand_t *)data; if ( !backEnd.projection2D ) { RB_SetGL2D(); } if (cmd->x >= 0) { qglScissor( cmd->x,(glConfig.vidHeight - cmd->y - cmd->h),cmd->w,cmd->h); } else { qglScissor( 0, 0, glConfig.vidWidth, glConfig.vidHeight); } return (const void *)(cmd + 1); }
static void SetViewportAndScissor( void ) { qglMatrixMode(GL_PROJECTION); qglLoadMatrixf( backEnd.viewParms.projectionMatrix ); qglMatrixMode(GL_MODELVIEW); // set the window clipping qglViewport( backEnd.viewParms.viewportX, backEnd.viewParms.viewportY, backEnd.viewParms.viewportWidth, backEnd.viewParms.viewportHeight ); qglScissor( backEnd.viewParms.viewportX, backEnd.viewParms.viewportY, backEnd.viewParms.viewportWidth, backEnd.viewParms.viewportHeight ); Matrix4Copy(backEnd.viewParms.projectionMatrix, glState.currentProjectionMatrix); Matrix4Multiply(glState.currentProjectionMatrix, glState.currentModelViewMatrix, glState.currentModelViewProjectionMatrix); }
void idGLDrawableView::draw(int x, int y, int w, int h) { int i; renderView_t refdef; const idMaterial *mat = material; if (mat) { qglViewport(x, y, w, h); qglScissor(x, y, w, h); qglMatrixMode(GL_PROJECTION); qglClearColor( 0.1f, 0.1f, 0.1f, 0.0f ); qglClear(GL_COLOR_BUFFER_BIT); UpdateLights(); // render it renderSystem->BeginFrame(w, h); memset( &refdef, 0, sizeof( refdef ) ); UpdateCamera( &refdef ); // Copy global shaderparms to view for( i = 0; i < MAX_GLOBAL_SHADER_PARMS; i++ ) { refdef.shaderParms[ i ] = globalParms[ i ]; } refdef.width = SCREEN_WIDTH; refdef.height = SCREEN_HEIGHT; refdef.fov_x = 90; refdef.fov_y = 2 * atan((float)h / w) * idMath::M_RAD2DEG; refdef.time = eventLoop->Milliseconds(); world->RenderScene( &refdef ); if ( showLights ) { drawLights( &refdef ); } renderSystem->EndFrame( NULL, NULL ); world->DebugClearLines( refdef.time ); qglMatrixMode( GL_MODELVIEW ); qglLoadIdentity(); } }
/* ================ RB_SetGL2D ================ */ void RB_SetGL2D (void) { backEnd.projection2D = qtrue; // set 2D virtual screen size #ifdef IPHONE if ( glConfig.vidRotation == 90.0 || glConfig.vidRotation == 270.0 ) { qglViewport ( 0, 0, glConfig.vidHeight, glConfig.vidWidth ); qglScissor( 0, 0, glConfig.vidHeight, glConfig.vidWidth ); } else #endif // IPHONE { qglViewport ( 0, 0, glConfig.vidWidth, glConfig.vidHeight ); qglScissor( 0, 0, glConfig.vidWidth, glConfig.vidHeight ); } qglMatrixMode(GL_PROJECTION); qglLoadIdentity (); #ifdef IPHONE qglRotatef (glConfig.vidRotation, 0, 0, 1); qglTranslatef (0, 0, 0); #endif // IPHONE qglOrtho (0, glConfig.vidWidth, glConfig.vidHeight, 0, 0, 1); qglMatrixMode(GL_MODELVIEW); qglLoadIdentity (); GL_State( GLS_DEPTHTEST_DISABLE | GLS_SRCBLEND_SRC_ALPHA | GLS_DSTBLEND_ONE_MINUS_SRC_ALPHA ); qglDisable( GL_CULL_FACE ); qglDisable( GL_CLIP_PLANE0 ); // set time for 2D shaders backEnd.refdef.time = ri.Milliseconds(); backEnd.refdef.floatTime = backEnd.refdef.time * 0.001f; }
static void SetViewportAndScissor( void ) { qglMatrixMode( GL_PROJECTION ); qglLoadMatrixf( backEnd.viewParms.projectionMatrix ); qglMatrixMode( GL_MODELVIEW ); // set the window clipping qglViewport( backEnd.viewParms.viewportX, backEnd.viewParms.viewportY, backEnd.viewParms.viewportWidth, backEnd.viewParms.viewportHeight ); // TODO: insert handling for widescreen? (when looking through camera) qglScissor( backEnd.viewParms.viewportX, backEnd.viewParms.viewportY, backEnd.viewParms.viewportWidth, backEnd.viewParms.viewportHeight ); }
/* ================ RB_SetGL2D ================ */ void RB_SetGL2D (void) { mat4_t matrix; int width, height; if (backEnd.projection2D && backEnd.last2DFBO == glState.currentFBO) return; backEnd.projection2D = qtrue; backEnd.last2DFBO = glState.currentFBO; if (glState.currentFBO) { width = glState.currentFBO->width; height = glState.currentFBO->height; } else { width = glConfig.vidWidth; height = glConfig.vidHeight; } // set 2D virtual screen size qglViewport( 0, 0, width, height ); qglScissor( 0, 0, width, height ); Mat4Ortho(0, width, height, 0, 0, 1, matrix); GL_SetProjectionMatrix(matrix); Mat4Identity(matrix); GL_SetModelviewMatrix(matrix); GL_State( GLS_DEPTHTEST_DISABLE | GLS_SRCBLEND_SRC_ALPHA | GLS_DSTBLEND_ONE_MINUS_SRC_ALPHA ); qglDisable( GL_CULL_FACE ); qglDisable( GL_CLIP_PLANE0 ); // set time for 2D shaders backEnd.refdef.time = ri.Milliseconds(); backEnd.refdef.floatTime = backEnd.refdef.time * 0.001f; // reset color scaling backEnd.refdef.colorScale = 1.0f; }
/* ==================== RB_RenderDrawSurfListWithFunction The triangle functions can check backEnd.currentSpace != surf->space to see if they need to perform any new matrix setup. The modelview matrix will already have been loaded, and backEnd.currentSpace will be updated after the triangle function completes. ==================== */ void RB_RenderDrawSurfListWithFunction( drawSurf_t **drawSurfs, int numDrawSurfs, void (*triFunc_)( const drawSurf_t *) ) { int i; const drawSurf_t *drawSurf; backEnd.currentSpace = NULL; for (i = 0 ; i < numDrawSurfs ; i++ ) { drawSurf = drawSurfs[i]; // change the matrix if needed if ( drawSurf->space != backEnd.currentSpace ) { qglLoadMatrixf( drawSurf->space->modelViewMatrix ); } if ( drawSurf->space->weaponDepthHack ) { RB_EnterWeaponDepthHack(); } if ( drawSurf->space->modelDepthHack != 0.0f ) { RB_EnterModelDepthHack( drawSurf->space->modelDepthHack ); } // change the scissor if needed if ( r_useScissor.GetBool() && !backEnd.currentScissor.Equals( drawSurf->scissorRect ) ) { backEnd.currentScissor = drawSurf->scissorRect; qglScissor( backEnd.viewDef->viewport.x1 + backEnd.currentScissor.x1, backEnd.viewDef->viewport.y1 + backEnd.currentScissor.y1, backEnd.currentScissor.x2 + 1 - backEnd.currentScissor.x1, backEnd.currentScissor.y2 + 1 - backEnd.currentScissor.y1 ); } // render it triFunc_( drawSurf ); if ( drawSurf->space->weaponDepthHack || drawSurf->space->modelDepthHack != 0.0f ) { RB_LeaveDepthHack(); } backEnd.currentSpace = drawSurf->space; } }
/* ============= RB_SetGL2D This is not used by the normal game paths, just by some tools ============= */ void RB_SetGL2D( void ) { // set 2D virtual screen size qglViewport( 0, 0, glConfig.vidWidth, glConfig.vidHeight ); if ( r_useScissor.GetBool() ) { qglScissor( 0, 0, glConfig.vidWidth, glConfig.vidHeight ); } qglMatrixMode( GL_PROJECTION ); qglLoadIdentity(); qglOrtho( 0, 640, 480, 0, 0, 1 ); // always assume 640x480 virtual coordinates qglMatrixMode( GL_MODELVIEW ); qglLoadIdentity(); GL_State( GLS_DEPTHFUNC_ALWAYS | GLS_SRCBLEND_SRC_ALPHA | GLS_DSTBLEND_ONE_MINUS_SRC_ALPHA ); GL_Cull( CT_TWO_SIDED ); qglDisable( GL_DEPTH_TEST ); qglDisable( GL_STENCIL_TEST ); }
/* ================= RB_BeginDrawingView Any mirrored or portaled views have already been drawn, so prepare to actually render the visible surfaces for this view ================= */ void RB_BeginDrawingView (void) { // set the modelview matrix for the viewer qglMatrixMode(GL_PROJECTION); qglLoadMatrixf( backEnd.viewDef->projectionMatrix ); qglMatrixMode(GL_MODELVIEW); // set the window clipping qglViewport( tr.viewportOffset[0] + backEnd.viewDef->viewport.x1, tr.viewportOffset[1] + backEnd.viewDef->viewport.y1, backEnd.viewDef->viewport.x2 + 1 - backEnd.viewDef->viewport.x1, backEnd.viewDef->viewport.y2 + 1 - backEnd.viewDef->viewport.y1 ); // the scissor may be smaller than the viewport for subviews qglScissor( tr.viewportOffset[0] + backEnd.viewDef->viewport.x1 + backEnd.viewDef->scissor.x1, tr.viewportOffset[1] + backEnd.viewDef->viewport.y1 + backEnd.viewDef->scissor.y1, backEnd.viewDef->scissor.x2 + 1 - backEnd.viewDef->scissor.x1, backEnd.viewDef->scissor.y2 + 1 - backEnd.viewDef->scissor.y1 ); backEnd.currentScissor = backEnd.viewDef->scissor; // ensures that depth writes are enabled for the depth clear GL_State( GLS_DEFAULT ); // we don't have to clear the depth / stencil buffer for 2D rendering if ( backEnd.viewDef->viewEntitys ) { qglStencilMask( 0xff ); // some cards may have 7 bit stencil buffers, so don't assume this // should be 128 qglClearStencil( 1<<(glConfig.stencilBits-1) ); qglClear( GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT ); qglEnable( GL_DEPTH_TEST ); } else { qglDisable( GL_DEPTH_TEST ); qglDisable( GL_STENCIL_TEST ); } backEnd.glState.faceCulling = -1; // force face culling to set next time GL_Cull( CT_FRONT_SIDED ); }
/* ================= R_PostprocessScreen ================= */ void R_PostprocessScreen( void ) { if( !postprocess ) return; if ( backEnd.donepostproc ) return; if ( !backEnd.doneSurfaces ) return; backEnd.donepostproc = qtrue; if( !postproc.started ) { R_Postprocess_InitTextures(); if( !postproc.started ) return; } if ( !backEnd.projection2D ) RB_SetGL2D(); #if 0 // set up full screen workspace GL_TexEnv( GL_MODULATE ); qglScissor( 0, 0, glConfig.vidWidth, glConfig.vidHeight ); qglViewport( 0, 0, glConfig.vidWidth, glConfig.vidHeight ); qglMatrixMode( GL_PROJECTION ); qglLoadIdentity (); qglOrtho( 0, glConfig.vidWidth, glConfig.vidHeight, 0, 0, 1 ); qglMatrixMode( GL_MODELVIEW ); qglLoadIdentity (); GL_Cull( CT_TWO_SIDED ); #endif qglColor4f( 1, 1, 1, 1 ); //Backup the old screen in a texture R_Postprocess_BackupScreen(); //Redraw texture using GLSL program R_Bloom_RestoreScreen_Postprocessed(); }
void idGLDrawable::draw(int x, int y, int w, int h) { GL_State( GLS_DEFAULT ); qglViewport(x, y, w, h); qglScissor(x, y, w, h); qglMatrixMode(GL_PROJECTION); qglClearColor( 0.1f, 0.1f, 0.1f, 0.0f ); qglClear(GL_COLOR_BUFFER_BIT); qglPolygonMode(GL_FRONT_AND_BACK, GL_FILL); qglLineWidth(0.5); qglColor3f(1, 1, 1); globalImages->BindNull(); qglBegin(GL_LINE_LOOP); qglColor3f(1, 0, 0); qglVertex2f(x + 3, y + 3); qglColor3f(0, 1, 0); qglVertex2f(x + 3, h - 3); qglColor3f(0, 0, 1); qglVertex2f(w - 3, h - 3); qglColor3f(1, 1, 1); qglVertex2f(w - 3, y + 3); qglEnd(); }
// Based on RB_SetGL2D(): FIXME? Code duplication can probably be avoided. static void Unicode_Setup2D (void) { backEnd.projection2D = qtrue; // set 2D virtual screen size qglViewport( 0, 0, glConfig.vidWidth, glConfig.vidHeight ); qglScissor( 0, 0, glConfig.vidWidth, glConfig.vidHeight ); qglMatrixMode(GL_PROJECTION); qglLoadIdentity (); qglOrtho (0, glConfig.vidWidth, glConfig.vidHeight, 0, -200, 200); // This changed. FIXME? Perhaps do it beter. qglMatrixMode(GL_MODELVIEW); qglLoadIdentity (); GL_State( GLS_DEPTHTEST_DISABLE | GLS_SRCBLEND_SRC_ALPHA | GLS_DSTBLEND_ONE_MINUS_SRC_ALPHA ); qglDisable( GL_CULL_FACE ); qglDisable( GL_CLIP_PLANE0 ); qglDisable( GL_CLIP_PLANE1 ); // set time for 2D shaders //backEnd.refdef.time = ri.Milliseconds(); //backEnd.refdef.floatTime = backEnd.refdef.time * 0.001f; }
void idGLDrawableModel::draw(int x, int y, int w, int h) { if ( !worldModel ) { return; } if ( worldModel->IsDynamicModel() != DM_STATIC ) { //return; } rect.Set( x, y, w, h ); qglViewport(x, y, w, h); qglScissor(x, y, w, h); qglMatrixMode(GL_PROJECTION); qglClearColor( 0.1f, 0.1f, 0.1f, 0.0f ); qglClear(GL_COLOR_BUFFER_BIT); if (worldDirty) { //InitWorld(); world->InitFromMap( NULL ); renderLight_t parms; idDict spawnArgs; spawnArgs.Set("classname", "light"); spawnArgs.Set("name", "light_1"); spawnArgs.Set("origin", "-128 0 0"); idStr str; sprintf(str, "%f %f %f", light, light, light); spawnArgs.Set("_color", str); gameEdit->ParseSpawnArgsToRenderLight( &spawnArgs, &parms ); lightDef = world->AddLightDef( &parms ); renderEntity_t worldEntity; memset( &worldEntity, 0, sizeof( worldEntity ) ); spawnArgs.Clear(); spawnArgs.Set("classname", "func_static"); spawnArgs.Set("name", spawnArgs.GetString("model")); spawnArgs.Set("origin", "0 0 0"); if ( skinStr.Length() ) { spawnArgs.Set( "skin", skinStr ); } gameEdit->ParseSpawnArgsToRenderEntity(&spawnArgs, &worldEntity); worldEntity.hModel = worldModel; worldEntity.axis = rotation.ToMat3(); worldEntity.shaderParms[0] = 1; worldEntity.shaderParms[1] = 1; worldEntity.shaderParms[2] = 1; worldEntity.shaderParms[3] = 1; modelDef = world->AddEntityDef( &worldEntity ); worldDirty = false; } renderView_t refdef; // render it renderSystem->BeginFrame(w, h); memset( &refdef, 0, sizeof( refdef ) ); refdef.vieworg.Set(zOffset, xOffset, -yOffset); refdef.viewaxis = idAngles(0,0,0).ToMat3(); refdef.shaderParms[0] = 1; refdef.shaderParms[1] = 1; refdef.shaderParms[2] = 1; refdef.shaderParms[3] = 1; refdef.width = SCREEN_WIDTH; refdef.height = SCREEN_HEIGHT; refdef.fov_x = 90; refdef.fov_y = 2 * atan((float)h / w) * idMath::M_RAD2DEG; refdef.time = eventLoop->Milliseconds(); world->RenderScene( &refdef ); int frontEnd, backEnd; renderSystem->EndFrame( &frontEnd, &backEnd ); qglMatrixMode( GL_MODELVIEW ); qglLoadIdentity(); }
void idGLDrawableMaterial::draw(int x, int y, int w, int h) { const idMaterial *mat = material; if (mat) { qglViewport(x, y, w, h); qglScissor(x, y, w, h); qglMatrixMode(GL_PROJECTION); qglClearColor( 0.1f, 0.1f, 0.1f, 0.0f ); qglClear(GL_COLOR_BUFFER_BIT); if (worldDirty) { InitWorld(); renderLight_t parms; idDict spawnArgs; spawnArgs.Set("classname", "light"); spawnArgs.Set("name", "light_1"); spawnArgs.Set("origin", "0 0 0"); idStr str; sprintf(str, "%f %f %f", light, light, light); spawnArgs.Set("_color", str); gameEdit->ParseSpawnArgsToRenderLight( &spawnArgs, &parms ); lightDef = world->AddLightDef( &parms ); idImage *img = (mat->GetNumStages() > 0) ? mat->GetStage(0)->texture.image : mat->GetEditorImage(); if (img == NULL) { common->Warning("Unable to load image for preview for %s", mat->GetName()); return; } int width = img->uploadWidth; int height = img->uploadHeight; width *= scale; height *= scale; srfTriangles_t *tris = worldModel->AllocSurfaceTriangles( 4, 6 ); tris->numVerts = 4; tris->numIndexes = 6; tris->indexes[0] = 0; tris->indexes[1] = 1; tris->indexes[2] = 2; tris->indexes[3] = 3; tris->indexes[4] = 1; tris->indexes[5] = 0; tris->verts[0].xyz.x = 64; tris->verts[0].xyz.y = -xOffset + 0 - width / 2; tris->verts[0].xyz.z = yOffset + 0 - height / 2; tris->verts[0].st.x = 1; tris->verts[0].st.y = 1; tris->verts[1].xyz.x = 64; tris->verts[1].xyz.y = -xOffset + width / 2; tris->verts[1].xyz.z = yOffset + height / 2; tris->verts[1].st.x = 0; tris->verts[1].st.y = 0; tris->verts[2].xyz.x = 64; tris->verts[2].xyz.y = -xOffset + 0 - width / 2; tris->verts[2].xyz.z = yOffset + height / 2; tris->verts[2].st.x = 1; tris->verts[2].st.y = 0; tris->verts[3].xyz.x = 64; tris->verts[3].xyz.y = -xOffset + width / 2; tris->verts[3].xyz.z = yOffset + 0 - height / 2; tris->verts[3].st.x = 0; tris->verts[3].st.y = 1; tris->verts[0].normal = tris->verts[1].xyz.Cross(tris->verts[3].xyz); tris->verts[1].normal = tris->verts[2].normal = tris->verts[3].normal = tris->verts[0].normal; AddTris(tris, mat); worldModel->FinishSurfaces(); renderEntity_t worldEntity; memset( &worldEntity, 0, sizeof( worldEntity ) ); if ( mat->HasGui() ) { worldEntity.gui[ 0 ] = mat->GlobalGui(); } worldEntity.hModel = worldModel; worldEntity.axis = mat3_default; worldEntity.shaderParms[0] = 1; worldEntity.shaderParms[1] = 1; worldEntity.shaderParms[2] = 1; worldEntity.shaderParms[3] = 1; modelDef = world->AddEntityDef( &worldEntity ); worldDirty = false; } renderView_t refdef; // render it renderSystem->BeginFrame(w, h); memset( &refdef, 0, sizeof( refdef ) ); refdef.vieworg.Set(viewAngle, 0, 0); refdef.viewaxis = idAngles(0,0,0).ToMat3(); refdef.shaderParms[0] = 1; refdef.shaderParms[1] = 1; refdef.shaderParms[2] = 1; refdef.shaderParms[3] = 1; refdef.width = SCREEN_WIDTH; refdef.height = SCREEN_HEIGHT; refdef.fov_x = 90; refdef.fov_y = 2 * atan((float)h / w) * idMath::M_RAD2DEG; refdef.time = eventLoop->Milliseconds(); world->RenderScene( &refdef ); int frontEnd, backEnd; renderSystem->EndFrame( &frontEnd, &backEnd ); qglMatrixMode( GL_MODELVIEW ); qglLoadIdentity(); } }