void Terrain_DrawCam( terrainMesh_t *pm ) { qglColor3f( 1,1,1 ); qglPushAttrib( GL_ALL_ATTRIB_BITS ); if ( g_bPatchWireFrame ) { if( pm->bSelected ) { qglLineWidth( 2 ); } else { qglLineWidth( 1 ); } qglDisable( GL_CULL_FACE ); qglPolygonMode( GL_FRONT_AND_BACK, GL_LINE ); qglDisable( GL_TEXTURE_2D ); if ( g_PrefsDlg.m_bGLLighting ) { qglDisable( GL_LIGHTING ); } DrawTerrain( pm, pm->bSelected, true ); if ( g_PrefsDlg.m_bGLLighting ) { qglEnable( GL_LIGHTING ); } qglEnable( GL_CULL_FACE ); qglLineWidth( 1 ); } else { qglEnable( GL_CULL_FACE ); qglCullFace( GL_FRONT ); // draw the textured polys DrawTerrain( pm, pm->bSelected, true ); // if selected, draw the red tint on the polys if( pm->bSelected ) { // && ( g_qeglobals.d_savedinfo.include & INCLUDE_CAMERATINT ) ) { 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 ); DrawTerrain( pm, pm->bSelected ); qglColor3f( 1, 1, 1 ); } // draw the backside poly outlines qglCullFace( GL_BACK ); qglPolygonMode( GL_FRONT_AND_BACK, GL_LINE ); qglDisable( GL_BLEND ); DrawTerrain( pm, pm->bSelected, true ); } qglPopAttrib(); }
/* ================= RB_ShadowFinish Darken everything that is is a shadow volume. We have to delay this until everything has been shadowed, because otherwise shadows from different body parts would overlap and double darken. ================= */ void RB_ShadowFinish(void) { if (r_shadows->integer != 2) { return; } if (glConfig.stencilBits < 4) { return; } qglEnable(GL_STENCIL_TEST); qglStencilFunc(GL_NOTEQUAL, 0, 255); qglDisable(GL_CLIP_PLANE0); qglDisable(GL_CULL_FACE); GL_Bind(tr.whiteImage); qglLoadIdentity(); qglColor3f(0.6f, 0.6f, 0.6f); GL_State(GLS_DEPTHMASK_TRUE | GLS_SRCBLEND_DST_COLOR | GLS_DSTBLEND_ZERO); GLboolean text = qglIsEnabled(GL_TEXTURE_COORD_ARRAY); GLboolean glcol = qglIsEnabled(GL_COLOR_ARRAY); if (text) { qglDisableClientState(GL_TEXTURE_COORD_ARRAY); } if (glcol) { qglDisableClientState(GL_COLOR_ARRAY); } GLfloat vtx[] = { -100, 100, -10, 100, 100, -10, 100, -100, -10, -100, -100, -10 }; qglVertexPointer(3, GL_FLOAT, 0, vtx); qglDrawArrays(GL_TRIANGLE_FAN, 0, 4); if (text) { qglEnableClientState(GL_TEXTURE_COORD_ARRAY); } if (glcol) { qglEnableClientState(GL_COLOR_ARRAY); } qglColor4f(1, 1, 1, 1); qglDisable(GL_STENCIL_TEST); }
/* ================= R_Bloom_DrawEffect ================= */ static void R_Bloom_DrawEffect( void ) { float alpha=r_bloom_alpha->value; GL_Bind( bloom.effect.texture ); GL_State( GLS_DEPTHTEST_DISABLE | GLS_SRCBLEND_ONE | GLS_DSTBLEND_ONE ); if(r_bloom_cascade->integer){ alpha=r_bloom_cascade_alpha->value; } qglColor4f( alpha,alpha,alpha, 1.0f ); R_Bloom_Quad( glConfig.vidWidth, glConfig.vidHeight, 0, 0, bloom.effect.readW, bloom.effect.readW ); }
void R_DrawAliasBatchPass (entity_t **ents, int numents, qbool showtris) { int i; gltexture_t *lasttexture = NULL; gltexture_t *lastfullbright = NULL; if (!numents) return; if (showtris) GL_TexEnv (GL_TEXTURE0_ARB, GL_TEXTURE_2D, GL_REPLACE); else if (gl_overbright.value) GL_TexEnv (GL_TEXTURE0_ARB, GL_TEXTURE_2D, GL_RGB_SCALE_ARB); else GL_TexEnv (GL_TEXTURE0_ARB, GL_TEXTURE_2D, GL_MODULATE); for (i = 0; i < numents; i++) { entity_t *ent = ents[i]; aliasstate_t *state = &ent->aliasstate; aliashdr_t *hdr = Mod_Extradata (ent->model); // we need a separate test for culling here as r_shadows mode doesn't cull if (ent->visframe != r_framecount) continue; if (!showtris && ((state->tx != lasttexture) || (state->fb != lastfullbright))) { if (state->fb) { GL_TexEnv (GL_TEXTURE1_ARB, GL_TEXTURE_2D, GL_ADD); GL_BindTexture (GL_TEXTURE1_ARB, state->fb); } else GL_TexEnv (GL_TEXTURE1_ARB, GL_TEXTURE_2D, GL_NONE); GL_BindTexture (GL_TEXTURE0_ARB, state->tx); lasttexture = state->tx; lastfullbright = state->fb; } // OK, this works better in GL... go figure... R_DrawAliasModel (ent, hdr, state, showtris); } GL_TexEnv (GL_TEXTURE1_ARB, GL_TEXTURE_2D, GL_NONE); GL_TexEnv (GL_TEXTURE0_ARB, GL_TEXTURE_2D, GL_REPLACE); qglColor4f (1, 1, 1, 1); // go back to the world matrix qglLoadMatrixf (r_world_matrix.m16); }
/* ================ Draw_FadeScreen ================ */ void Draw_FadeScreen (void) { qglEnable (GL_BLEND); qglDisable (GL_TEXTURE_2D); qglColor4f (0, 0, 0, 0.8); xeeBegin (GL_QUADS); xeeVertex2f (0,0); xeeVertex2f (vid.width, 0); xeeVertex2f (vid.width, vid.height); xeeVertex2f (0, vid.height); xeeEnd (); xeeSubmit(); qglColor4f (1,1,1,1); qglEnable (GL_TEXTURE_2D); qglDisable (GL_BLEND); }
/* ** GL_SetDefaultState */ void GL_SetDefaultState( void ) { qglClearDepth( 1.0f ); qglCullFace(GL_FRONT); qglColor4f (1,1,1,1); // initialize downstream texture unit if we're running // in a multitexture environment if ( qglActiveTextureARB ) { GL_SelectTexture( 1 ); GL_TextureMode( r_textureMode->string ); GL_TexEnv( GL_MODULATE ); qglDisable( GL_TEXTURE_2D ); GL_SelectTexture( 0 ); } qglEnable(GL_TEXTURE_2D); GL_TextureMode( r_textureMode->string ); GL_TexEnv( GL_MODULATE ); //qglShadeModel( GL_SMOOTH ); qglDepthFunc( GL_LEQUAL ); // // make sure our GL state vector is set correctly // glState.glStateBits = GLS_DEPTHTEST_DISABLE | GLS_DEPTHMASK_TRUE; glState.storedGlState = 0; glState.currentProgram = 0; qglUseProgramObjectARB(0); qglBindBufferARB(GL_ARRAY_BUFFER_ARB, 0); qglBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 0); glState.currentVao = NULL; qglPolygonMode (GL_FRONT_AND_BACK, GL_FILL); qglDepthMask( GL_TRUE ); qglDisable( GL_DEPTH_TEST ); qglEnable( GL_SCISSOR_TEST ); qglDisable( GL_CULL_FACE ); qglDisable( GL_BLEND ); if (glRefConfig.seamlessCubeMap) qglEnable(GL_TEXTURE_CUBE_MAP_SEAMLESS); // GL_POLYGON_OFFSET_FILL will be glEnable()d when this is used qglPolygonOffset( r_offsetFactor->value, r_offsetUnits->value ); qglClearColor( 0.0f, 0.0f, 0.0f, 1.0f ); // FIXME: get color of sky }
/* ** GL_SetDefaultState */ void GL_SetDefaultState( void ) { qglClearDepth( 1.0f ); qglCullFace(GL_FRONT); qglColor4f (1,1,1,1); // initialize downstream texture unit if we're running // in a multitexture environment if ( qglActiveTextureARB ) { GL_SelectTexture( 1 ); GL_TextureMode( r_textureMode->string ); GL_TexEnv( GL_MODULATE ); qglDisable( GL_TEXTURE_2D ); GL_SelectTexture( 0 ); } qglEnable(GL_TEXTURE_2D); GL_TextureMode( r_textureMode->string ); GL_TexEnv( GL_MODULATE ); qglShadeModel( GL_SMOOTH ); qglDepthFunc( GL_LEQUAL ); // the vertex array is always enabled, but the color and texture // arrays are enabled and disabled around the compiled vertex array call qglEnableClientState (GL_VERTEX_ARRAY); // // make sure our GL state vector is set correctly // glState.glStateBits = GLS_DEPTHTEST_DISABLE | GLS_DEPTHMASK_TRUE; qglPolygonMode (GL_FRONT_AND_BACK, GL_FILL); qglDepthMask( GL_TRUE ); qglDisable( GL_DEPTH_TEST ); qglEnable( GL_SCISSOR_TEST ); qglDisable( GL_CULL_FACE ); qglDisable( GL_BLEND ); #ifdef _NPATCH // If n-patches are supported, make sure they are disabled for now // Set the initial tesselation level and the interpolation modes if ( qglPNTrianglesiATI ) { qglDisable( GL_PN_TRIANGLES_ATI ); qglPNTrianglesiATI( GL_PN_TRIANGLES_POINT_MODE_ATI, GL_PN_TRIANGLES_POINT_MODE_CUBIC_ATI ); qglPNTrianglesiATI( GL_PN_TRIANGLES_NORMAL_MODE_ATI, GL_PN_TRIANGLES_NORMAL_MODE_QUADRATIC_ATI ); qglPNTrianglesiATI( GL_PN_TRIANGLES_TESSELATION_LEVEL_ATI, 3 ); } #endif // _NPATCH }
/* ================= R_Bloom_DownsampleView ================= */ void R_Bloom_DownsampleView( void ) { GL_Disable( GL_BLEND ); qglColor4f( 1.0f, 1.0f, 1.0f, 1.0f ); //stepped downsample if( r_screendownsamplingtexture_size ) { int midsample_width = r_screendownsamplingtexture_size * sampleText_tcw; int midsample_height = r_screendownsamplingtexture_size * sampleText_tch; //copy the screen and draw resized GL_Bind(r_bloomscreentexture->texnum); qglCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, curView_x, vid.height - (curView_y + curView_height), curView_width, curView_height); R_Bloom_Quad( 0, vid.height-midsample_height, midsample_width, midsample_height, screenText_tcw, screenText_tch ); //now copy into Downsampling (mid-sized) texture GL_Bind(r_bloomdownsamplingtexture->texnum); qglCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, midsample_width, midsample_height); //now draw again in bloom size qglColor4f( 0.5f, 0.5f, 0.5f, 1.0f ); R_Bloom_Quad( 0, vid.height-sample_height, sample_width, sample_height, sampleText_tcw, sampleText_tch ); //now blend the big screen texture into the bloom generation space (hoping it adds some blur) GL_Enable( GL_BLEND ); GL_BlendFunc(GL_ONE, GL_ONE); qglColor4f( 0.5f, 0.5f, 0.5f, 1.0f ); GL_Bind(r_bloomscreentexture->texnum); R_Bloom_Quad( 0, vid.height-sample_height, sample_width, sample_height, screenText_tcw, screenText_tch ); qglColor4f( 1.0f, 1.0f, 1.0f, 1.0f ); GL_Disable( GL_BLEND ); } else { //downsample simple GL_Bind(r_bloomscreentexture->texnum); qglCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, curView_x, vid.height - (curView_y + curView_height), curView_width, curView_height); R_Bloom_Quad( 0, vid.height-sample_height, sample_width, sample_height, screenText_tcw, screenText_tch ); } }
/* ** GL_SetDefaultState */ void GL_SetDefaultState( void ) { qglClearDepth( 1.0f ); qglCullFace(GL_FRONT); qglColor4f (1,1,1,1); GL_BindNullTextures(); if (glRefConfig.framebufferObject) GL_BindNullFramebuffers(); qglEnable(GL_TEXTURE_2D); GL_TextureMode( r_textureMode->string ); //qglShadeModel( GL_SMOOTH ); qglDepthFunc( GL_LEQUAL ); // // make sure our GL state vector is set correctly // glState.glStateBits = GLS_DEPTHTEST_DISABLE | GLS_DEPTHMASK_TRUE; glState.storedGlState = 0; glState.faceCulling = CT_TWO_SIDED; glState.faceCullFront = qtrue; GL_BindNullProgram(); if (glRefConfig.vertexArrayObject) qglBindVertexArray(0); qglBindBuffer(GL_ARRAY_BUFFER, 0); qglBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); glState.currentVao = NULL; glState.vertexAttribsEnabled = 0; qglPolygonMode (GL_FRONT_AND_BACK, GL_FILL); qglDepthMask( GL_TRUE ); qglDisable( GL_DEPTH_TEST ); qglEnable( GL_SCISSOR_TEST ); qglDisable( GL_CULL_FACE ); qglDisable( GL_BLEND ); if (glRefConfig.seamlessCubeMap) qglEnable(GL_TEXTURE_CUBE_MAP_SEAMLESS); // GL_POLYGON_OFFSET_FILL will be glEnable()d when this is used qglPolygonOffset( r_offsetFactor->value, r_offsetUnits->value ); qglClearColor( 0.0f, 0.0f, 0.0f, 1.0f ); // FIXME: get color of sky }
/* ** GL_SetDefaultState */ void GL_SetDefaultState(void) { qglClearDepth(1.0f); qglCullFace(GL_FRONT); qglColor4f (1,1,1,1); /* initialize downstream texture unit if we're running * in a multitexture environment */ if(qglActiveTextureARB){ GL_SelectTexture(1); GL_TextureMode(r_textureMode->string); GL_TexEnv(GL_MODULATE); qglDisable(GL_TEXTURE_2D); GL_SelectTexture(0); } qglEnable(GL_TEXTURE_2D); GL_TextureMode(r_textureMode->string); GL_TexEnv(GL_MODULATE); qglShadeModel(GL_SMOOTH); qglDepthFunc(GL_LEQUAL); /* the vertex array is always enabled, but the color and texture * arrays are enabled and disabled around the compiled vertex array call */ qglEnableClientState (GL_VERTEX_ARRAY); /* * make sure our GL state vector is set correctly * */ glState.glStateBits = GLS_DEPTHTEST_DISABLE | GLS_DEPTHMASK_TRUE; glState.vertexAttribsState = 0; glState.vertexAttribPointersSet = 0; glState.currentProgram = 0; qglUseProgramObjectARB(0); qglBindBufferARB(GL_ARRAY_BUFFER_ARB, 0); qglBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 0); glState.currentVBO = NULL; glState.currentIBO = NULL; qglPolygonMode (GL_FRONT_AND_BACK, GL_FILL); qglDepthMask(GL_TRUE); qglDisable(GL_DEPTH_TEST); qglEnable(GL_SCISSOR_TEST); qglDisable(GL_CULL_FACE); qglDisable(GL_BLEND); }
/* ** GL_SetDefaultState */ void GL_SetDefaultState( void ) { qglClearDepth( 1.0f ); qglCullFace(GL_FRONT); qglColor4f (1,1,1,1); // initialize downstream texture unit if we're running // in a multitexture environment if ( qglActiveTextureARB ) { GL_SelectTexture( 1 ); GL_TextureMode( r_textureMode->string ); GL_TexEnv( GL_MODULATE ); qglDisable( GL_TEXTURE_2D ); GL_SelectTexture( 0 ); } qglEnable(GL_TEXTURE_2D); GL_TextureMode( r_textureMode->string ); GL_TexEnv( GL_MODULATE ); //qglShadeModel( GL_SMOOTH ); qglDepthFunc( GL_LEQUAL ); // // make sure our GL state vector is set correctly // glState.glStateBits = GLS_DEPTHTEST_DISABLE | GLS_DEPTHMASK_TRUE; glState.vertexAttribsState = 0; glState.vertexAttribPointersSet = 0; glState.currentProgram = 0; qglUseProgramObjectARB(0); qglBindBufferARB(GL_ARRAY_BUFFER_ARB, 0); qglBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 0); glState.currentVBO = NULL; glState.currentIBO = NULL; if (glRefConfig.framebuffer_srgb) { qglEnable(GL_FRAMEBUFFER_SRGB_EXT); } qglPolygonMode (GL_FRONT_AND_BACK, GL_FILL); qglDepthMask( GL_TRUE ); qglDisable( GL_DEPTH_TEST ); qglEnable( GL_SCISSOR_TEST ); qglDisable( GL_CULL_FACE ); qglDisable( GL_BLEND ); }
/* ================ rvGEWorkspace::RenderGrid Renders the grid on top of the user interface ================ */ void rvGEWorkspace::RenderGrid ( void ) { float x; float y; float step; idVec4& color = mApplication->GetOptions().GetGridColor ( ); // See if the grid is off before rendering it if ( !mApplication->GetOptions().GetGridVisible ( )) { return; } qglEnable(GL_BLEND); qglBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); qglColor4f ( color[0], color[1], color[2], 0.5f ); qglBegin ( GL_LINES ); step = mApplication->GetOptions().GetGridWidth ( ) * g_ZoomScales[mZoom]; for ( x = mRect.x + mRect.w; x >= mRect.x ; x -= step ) { qglVertex2f ( x, mRect.y ); qglVertex2f ( x, mRect.y + mRect.h ); } step = mApplication->GetOptions().GetGridHeight ( ) * g_ZoomScales[mZoom]; for ( y = mRect.y + mRect.h; y >= mRect.y ; y -= step ) { qglVertex2f ( mRect.x, y ); qglVertex2f ( mRect.x + mRect.w, y ); } qglEnd ( ); qglDisable(GL_BLEND); qglColor3f ( color[0], color[1], color[2] ); qglBegin ( GL_LINES ); step = mApplication->GetOptions().GetGridWidth ( ) * g_ZoomScales[mZoom]; for ( x = mRect.x + mRect.w; x >= mRect.x ; x -= step * 4 ) { qglVertex2f ( x, mRect.y ); qglVertex2f ( x, mRect.y + mRect.h ); } step = mApplication->GetOptions().GetGridHeight ( ) * g_ZoomScales[mZoom]; for ( y = mRect.y + mRect.h; y >= mRect.y ; y -= step * 4 ) { qglVertex2f ( mRect.x, y ); qglVertex2f ( mRect.x + mRect.w, y ); } qglEnd ( ); }
/* * R_Bloom_DownsampleView */ static void R_Bloom_DownsampleView( void ) { qglColor4f( 1.0f, 1.0f, 1.0f, 1.0f ); if( r_screendownsamplingtexture_size ) { // stepped downsample int midsample_width = ( r_screendownsamplingtexture_size * sampleText_tcw ); int midsample_height = ( r_screendownsamplingtexture_size * sampleText_tch ); // copy the screen and draw resized GL_Bind( 0, r_bloomscreentexture ); qglCopyTexSubImage2D( GL_TEXTURE_2D, 0, 0, 0, curView_x, glState.height - ( curView_y + curView_height ), curView_width, curView_height ); R_Bloom_Quad( 0, 0, midsample_width, midsample_height, screenTex_tcw, screenTex_tch ); // now copy into downsampling (mid-sized) texture GL_Bind( 0, r_bloomdownsamplingtexture ); qglCopyTexSubImage2D( GL_TEXTURE_2D, 0, 0, 0, 0, 0, midsample_width, midsample_height ); // now draw again in bloom size qglColor4f( 0.5f, 0.5f, 0.5f, 1.0f ); R_Bloom_Quad( 0, 0, sample_width, sample_height, sampleText_tcw, sampleText_tch ); // now blend the big screen texture into the bloom generation space (hoping it adds some blur) GL_SetState( GLSTATE_NO_DEPTH_TEST|GLSTATE_SRCBLEND_ONE|GLSTATE_DSTBLEND_ONE ); GL_Bind( 0, r_bloomscreentexture ); R_Bloom_Quad( 0, 0, sample_width, sample_height, screenTex_tcw, screenTex_tch ); qglColor4f( 1.0f, 1.0f, 1.0f, 1.0f ); } else { // downsample simple GL_Bind( 0, r_bloomscreentexture ); qglCopyTexSubImage2D( GL_TEXTURE_2D, 0, 0, 0, curView_x, glState.height - ( curView_y + curView_height ), curView_width, curView_height ); R_Bloom_Quad( 0, 0, sample_width, sample_height, screenTex_tcw, screenTex_tch ); } }
void CSnowSystem::Render(void) { int i; SParticle *item; vec3_t origin; if (!(mOverallContents & CONTENTS_OUTSIDE)) { return; } CWorldEffectsSystem::Render(); VectorAdd(backEnd.viewParms.or.origin, mMinSpread, origin); qglColor4f(0.8f, 0.8f, 0.8f, mAlpha); // GL_State(GLS_SRCBLEND_SRC_ALPHA|GLS_DSTBLEND_ONE); GL_State(GLS_ALPHA); qglDisable(GL_TEXTURE_2D); if (qglPointParameterfEXT) { qglPointSize(10.0); qglPointParameterfEXT(GL_POINT_SIZE_MIN_EXT, 1.0); qglPointParameterfEXT(GL_POINT_SIZE_MAX_EXT, 4.0); // qglPointParameterfEXT(GL_POINT_FADE_THRESHOLD_SIZE_EXT, 3.0); qglPointParameterfvEXT(GL_DISTANCE_ATTENUATION_EXT, (float *)attenuation); } else { qglPointSize(2.0); } item = mSnowList; qglBegin(GL_POINTS); for(i=mMaxSnowflakes;i;i--) { if (item->flags & PARTICLE_FLAG_RENDER) { qglVertex3fv(item->pos); } item++; } qglEnd(); qglEnable(GL_TEXTURE_2D); }
/* ================= R_Bloom_RestoreScreen Restore the temporary framebuffer section we used with the backup texture ================= */ static void R_Bloom_RestoreScreen( void ) { float dry=r_bloom_dry->value; if(r_bloom_cascade->integer) dry=r_bloom_cascade_dry->value; GL_State( GLS_DEPTHTEST_DISABLE | GLS_SRCBLEND_ONE | GLS_DSTBLEND_ZERO ); GL_Bind( bloom.screen.texture ); qglColor4f( dry,dry,dry, 1 ); if(dry<.99f){ R_Bloom_Quad( bloom.screen.width, bloom.screen.height, 0, 0, 1.f, 1.f ); }else{ R_Bloom_Quad( bloom.work.width, bloom.work.height, 0, 0, bloom.work.width / (float)bloom.screen.width, bloom.work.height / (float)bloom.screen.height ); } }
/* ** GL_SetDefaultState */ void GL_SetDefaultState( void ) { qglClearDepth( 1.0f ); qglCullFace(GL_FRONT); qglColor4f (1,1,1,1); // initialize downstream texture unit if we're running // in a multitexture environment if ( qglActiveTextureARB ) { GL_SelectTexture( 1 ); GL_TextureMode( r_textureMode->string ); GL_TexEnv( GL_MODULATE ); qglDisable( GL_TEXTURE_2D ); GL_SelectTexture( 0 ); } qglEnable(GL_TEXTURE_2D); GL_TextureMode( r_textureMode->string ); GL_TexEnv( GL_MODULATE ); qglShadeModel( GL_SMOOTH ); qglDepthFunc( GL_LEQUAL ); // the vertex array is always enabled, but the color and texture // arrays are enabled and disabled around the compiled vertex array call qglEnableClientState (GL_VERTEX_ARRAY); // // make sure our GL state vector is set correctly // glState.glStateBits = GLS_DEPTHTEST_DISABLE | GLS_DEPTHMASK_TRUE; #ifdef HAVE_GLES glPixelStorei(GL_PACK_ALIGNMENT, 1); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); #else qglPolygonMode (GL_FRONT_AND_BACK, GL_FILL); #endif qglDepthMask( GL_TRUE ); qglDisable( GL_DEPTH_TEST ); qglEnable( GL_SCISSOR_TEST ); qglDisable( GL_CULL_FACE ); qglDisable( GL_BLEND ); }
/* * R_Bloom_DrawEffect */ static void R_Bloom_DrawEffect( void ) { GL_Bind( 0, r_bloomeffecttexture ); GL_TexEnv( GL_MODULATE ); GL_SetState( GLSTATE_NO_DEPTH_TEST|GLSTATE_SRCBLEND_ONE|GLSTATE_DSTBLEND_ONE ); qglColor4f( r_bloom_alpha->value, r_bloom_alpha->value, r_bloom_alpha->value, 1.0f ); qglBegin( GL_QUADS ); qglTexCoord2f( 0, sampleText_tch ); qglVertex2f( curView_x, curView_y ); qglTexCoord2f( 0, 0 ); qglVertex2f( curView_x, curView_y+curView_height ); qglTexCoord2f( sampleText_tcw, 0 ); qglVertex2f( curView_x+curView_width, curView_y+curView_height ); qglTexCoord2f( sampleText_tcw, sampleText_tch ); qglVertex2f( curView_x+curView_width, curView_y ); qglEnd(); }
/* =================== RB_OutlinesPass Draws outlines on surfaces with shader.hasOutlines set =================== */ static void RB_OutlinesPass( void ) { int outlines; float outlinesAlpha; outlines = r_outlines->value; outlinesAlpha = r_outlinesAlpha->value; if ( !tess.shader->hasOutlines ) return; if ( !r_outlines->integer ) return; GL_Bind( tr.whiteImage ); qglColor4f( 0, 0, 0, outlinesAlpha ); GL_State( GLS_POLYMODE_LINE | GLS_DEPTHMASK_TRUE | GLS_SRCBLEND_SRC_ALPHA | GLS_DSTBLEND_ONE_MINUS_SRC_ALPHA ); qglPolygonMode( GL_BACK, GL_LINE ); qglLineWidth( outlines + 1 ); qglCullFace( GL_BACK ); qglDisableClientState( GL_COLOR_ARRAY ); qglDisableClientState( GL_TEXTURE_COORD_ARRAY ); qglVertexPointer (3, GL_FLOAT, 16, tess.xyz); // padded for SIMD if (qglLockArraysEXT) { qglLockArraysEXT(0, tess.numVertexes); GLimp_LogComment( "glLockArraysEXT\n" ); } R_DrawElements( tess.numIndexes, tess.indexes ); if (qglUnlockArraysEXT) { qglUnlockArraysEXT(); GLimp_LogComment( "glUnlockArraysEXT\n" ); } // FIX: Must reset these manually or renderer will b0rk! qglCullFace( GL_FRONT ); qglLineWidth( 1 ); }
/* ================= R_Bloom_DrawEffect ================= */ void R_Bloom_DrawEffect( refdef_t *fd ) { GL_Bind(r_bloomeffecttexture->texnum); GL_Enable(GL_BLEND); GL_BlendFunc(GL_ONE, GL_ONE); qglColor4f(r_bloom_alpha->value + fd->bloomalpha /*bc mod*/, r_bloom_alpha->value + fd->bloomalpha /*bc mod*/, r_bloom_alpha->value + fd->bloomalpha /*bc mod*/, 1.0f); GL_TexEnv(GL_MODULATE); qglBegin(GL_QUADS); qglTexCoord2f( 0, sampleText_tch ); qglVertex2f( curView_x, curView_y ); qglTexCoord2f( 0, 0 ); qglVertex2f( curView_x, curView_y + curView_height ); qglTexCoord2f( sampleText_tcw, 0 ); qglVertex2f( curView_x + curView_width, curView_y + curView_height ); qglTexCoord2f( sampleText_tcw, sampleText_tch ); qglVertex2f( curView_x + curView_width, curView_y ); qglEnd(); GL_Disable(GL_BLEND); }
//Water caustics void EmitCausticPolys (const glpoly_t *p) { int i, nv; float txm, tym; const float *v; txm = (float)cos(r_newrefdef.time*0.3f) * 0.3f; tym = (float)sin(r_newrefdef.time*-0.3f) * 0.6f; GL_SelectTexture(1); qglDisable(GL_TEXTURE_2D); GL_SelectTexture(0); qglEnable(GL_BLEND); qglBlendFunc(GL_ZERO, GL_SRC_COLOR); qglColor4f (1, 1, 1, 0.275f); GL_Bind(r_caustictexture->texnum); v = p->verts[0]; nv = p->numverts; qglBegin (GL_POLYGON); for (i = 0; i < nv; i++, v += VERTEXSIZE) { qglTexCoord2f (v[3]+txm, v[4]+tym); qglVertex3fv (v); } qglEnd(); qglBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); qglColor4fv(colorWhite); qglDisable(GL_BLEND); GL_SelectTexture(1); qglEnable(GL_TEXTURE_2D); GL_SelectTexture(0); }
/* ================= 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(); }
/* ** GL_SetDefaultState */ void GL_SetDefaultState( void ) { glClearColor (1.0f, 0.0f, 0.5f, 0.5f); glCullFace(GL_FRONT); qglEnable(GL_TEXTURE_2D); qglEnable(GL_ALPHA_TEST); qglAlphaFunc(GL_GREATER, 0.666f); qglDisable (GL_DEPTH_TEST); qglDisable (GL_CULL_FACE); qglDisable (GL_BLEND); qglColor4f(colorWhite[0], colorWhite[1], colorWhite[2], colorWhite[3]); GL_TextureMode( gl_texturemode->string ); glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); GL_TexEnv(GL_TEXTURE0, GL_REPLACE); gl_swapinterval->modified = true; GL_UpdateSwapInterval(); }
void CWindingMsg::Draw2D( VIEWTYPE vt ){ int i; int nDim1 = ( vt == YZ ) ? 1 : 0; int nDim2 = ( vt == XY ) ? 1 : 2; qglColor3f( 1.0f,0.f,0.0f ); qglPointSize( 4 ); qglBegin( GL_POINTS ); for ( i = 0; i < numpoints; i++ ) qglVertex2f( wt[i][nDim1], wt[i][nDim2] ); qglEnd(); qglPointSize( 1 ); qglEnable( GL_BLEND ); qglPolygonMode( GL_FRONT_AND_BACK, GL_FILL ); qglBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); qglColor4f( 0.133f,0.4f,1.0f,0.5f ); qglBegin( GL_POLYGON ); for ( i = 0; i < numpoints; i++ ) qglVertex2f( wt[i][nDim1], wt[i][nDim2] ); qglEnd(); qglDisable( GL_BLEND ); }
/* ** GL_SetDefaultState */ void GL_SetDefaultState( void ) { qglClearDepth( 1.0f ); qglCullFace( GL_FRONT ); qglColor4f( 1,1,1,1 ); // initialize downstream texture unit if we're running // in a multitexture environment if ( qglActiveTextureARB ) { GL_SelectTexture( 1 ); GL_TextureMode( r_textureMode->string ); GL_TexEnv( GL_MODULATE ); qglDisable( GL_TEXTURE_2D ); GL_SelectTexture( 0 ); } qglEnable( GL_TEXTURE_2D ); GL_TextureMode( r_textureMode->string ); GL_TexEnv( GL_MODULATE ); qglShadeModel( GL_SMOOTH ); qglDepthFunc( GL_LEQUAL ); // the vertex array is always enabled, but the color and texture // arrays are enabled and disabled around the compiled vertex array call qglEnableClientState( GL_VERTEX_ARRAY ); // // make sure our GL state vector is set correctly // glState.glStateBits = GLS_DEPTHTEST_DISABLE | GLS_DEPTHMASK_TRUE; #ifdef USE_OPENGLES glPixelStorei(GL_PACK_ALIGNMENT, 1); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); #else qglPolygonMode( GL_FRONT_AND_BACK, GL_FILL ); #endif qglDepthMask( GL_TRUE ); qglDisable( GL_DEPTH_TEST ); qglEnable( GL_SCISSOR_TEST ); qglDisable( GL_CULL_FACE ); qglDisable( GL_BLEND ); #ifndef USE_OPENGLES //----(SA) added. // ATI pn_triangles if ( qglPNTrianglesiATI ) { int maxtess; // get max supported tesselation qglGetIntegerv( GL_MAX_PN_TRIANGLES_TESSELATION_LEVEL_ATI, (GLint*)&maxtess ); glConfig.ATIMaxTruformTess = maxtess; // cap if necessary if ( r_ati_truform_tess->value > maxtess ) { ri.Cvar_Set( "r_ati_truform_tess", va( "%d", maxtess ) ); } // set Wolf defaults qglPNTrianglesiATI( GL_PN_TRIANGLES_TESSELATION_LEVEL_ATI, r_ati_truform_tess->value ); } //----(SA) end #endif if ( glConfig.anisotropicAvailable ) { float maxAnisotropy; qglGetFloatv( GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &maxAnisotropy ); glConfig.maxAnisotropy = maxAnisotropy; // set when rendering // qglTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, glConfig.maxAnisotropy); } }
void RB_DistortionFill(void) { float alpha = tr_distortionAlpha; float spost = 0.0f; float spost2 = 0.0f; if ( glConfig.stencilBits < 4 ) { return; } //ok, cap the stupid thing now I guess if (!tr_distortionPrePost) { RB_CaptureScreenImage(); } qglEnable(GL_STENCIL_TEST); qglStencilFunc(GL_NOTEQUAL, 0, 0xFFFFFFFF); qglStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); qglDisable (GL_CLIP_PLANE0); GL_Cull( CT_TWO_SIDED ); //reset the view matrices and go into ortho mode qglMatrixMode(GL_PROJECTION); qglPushMatrix(); qglLoadIdentity(); qglOrtho(0, glConfig.vidWidth, glConfig.vidHeight, 32, -1, 1); qglMatrixMode(GL_MODELVIEW); qglPushMatrix(); qglLoadIdentity(); if (tr_distortionStretch) { //override spost = tr_distortionStretch; spost2 = tr_distortionStretch; } else { //do slow stretchy effect spost = sin(tr.refdef.time*0.0005f); if (spost < 0.0f) { spost = -spost; } spost *= 0.2f; spost2 = sin(tr.refdef.time*0.0005f); if (spost2 < 0.0f) { spost2 = -spost2; } spost2 *= 0.08f; } if (alpha != 1.0f) { //blend GL_State(GLS_SRCBLEND_SRC_ALPHA|GLS_DSTBLEND_SRC_ALPHA); } else { //be sure to reset the draw state GL_State(0); } #ifdef _XBOX qglBeginEXT(GL_QUADS, 4, 0, 0, 4, 0); #else qglBegin(GL_QUADS); #endif // _XBOX qglColor4f(1.0f, 1.0f, 1.0f, alpha); qglTexCoord2f(0+spost2, 1-spost); qglVertex2f(0, 0); qglTexCoord2f(0+spost2, 0+spost); qglVertex2f(0, glConfig.vidHeight); qglTexCoord2f(1-spost2, 0+spost); qglVertex2f(glConfig.vidWidth, glConfig.vidHeight); qglTexCoord2f(1-spost2, 1-spost); qglVertex2f(glConfig.vidWidth, 0); qglEnd(); if (tr_distortionAlpha == 1.0f && tr_distortionStretch == 0.0f) { //no overrides if (tr_distortionNegate) { //probably the crazy alternate saber trail alpha = 0.8f; GL_State(GLS_SRCBLEND_ZERO|GLS_DSTBLEND_ONE_MINUS_SRC_COLOR); } else { alpha = 0.5f; GL_State(GLS_SRCBLEND_SRC_ALPHA|GLS_DSTBLEND_SRC_ALPHA); } spost = sin(tr.refdef.time*0.0008f); if (spost < 0.0f) { spost = -spost; } spost *= 0.08f; spost2 = sin(tr.refdef.time*0.0008f); if (spost2 < 0.0f) { spost2 = -spost2; } spost2 *= 0.2f; #ifdef _XBOX qglBeginEXT(GL_QUADS, 4, 0, 0, 4, 0); #else qglBegin(GL_QUADS); #endif // _XBOX qglColor4f(1.0f, 1.0f, 1.0f, alpha); qglTexCoord2f(0+spost2, 1-spost); qglVertex2f(0, 0); qglTexCoord2f(0+spost2, 0+spost); qglVertex2f(0, glConfig.vidHeight); qglTexCoord2f(1-spost2, 0+spost); qglVertex2f(glConfig.vidWidth, glConfig.vidHeight); qglTexCoord2f(1-spost2, 1-spost); qglVertex2f(glConfig.vidWidth, 0); qglEnd(); } //pop the view matrices back qglMatrixMode(GL_PROJECTION); qglPopMatrix(); qglMatrixMode(GL_MODELVIEW); qglPopMatrix(); qglDisable( GL_STENCIL_TEST ); }
/* ================ rvGESelectionMgr::Render Render the selections including the move/size bars ================ */ void rvGESelectionMgr::Render ( void ) { if ( !mSelections.Num ( ) ) { return; } qglEnable(GL_BLEND); qglBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); UpdateRectangle ( ); qglPolygonMode(GL_FRONT_AND_BACK, GL_LINE ); idVec4& color = gApp.GetOptions().GetSelectionColor ( ); qglColor4f ( color[0],color[1],color[2], 1.0f ); qglBegin(GL_LINE_LOOP ); qglVertex2f ( mRect.x, mRect.y ); qglVertex2f ( mRect.x + mRect.w, mRect.y ); qglVertex2f ( mRect.x + mRect.w, mRect.y + mRect.h); qglVertex2f ( mRect.x, mRect.y + mRect.h); qglEnd ( ); qglColor4f ( color[0],color[1],color[2], 0.75f ); int i; for ( i = 0; i < mSelections.Num(); i ++ ) { rvGEWindowWrapper* wrapper; idRectangle rect; wrapper = rvGEWindowWrapper::GetWrapper ( mSelections[i] ); assert ( wrapper ); rect = wrapper->GetScreenRect ( ); mWorkspace->WorkspaceToWindow ( rect ); if ( i == 0 ) { qglPolygonMode(GL_FRONT_AND_BACK, GL_FILL ); qglBegin ( GL_TRIANGLES ); qglVertex2f ( rect.x, rect.y ); qglVertex2f ( rect.x + GUIED_GRABSIZE, rect.y ); qglVertex2f ( rect.x, rect.y + GUIED_GRABSIZE ); qglEnd ( ); } qglPolygonMode(GL_FRONT_AND_BACK, GL_LINE ); qglBegin(GL_LINE_LOOP ); qglVertex2f ( rect.x, rect.y ); qglVertex2f ( rect.x + rect.w, rect.y ); qglVertex2f ( rect.x + rect.w, rect.y + rect.h); qglVertex2f ( rect.x, rect.y + rect.h); qglEnd ( ); qglPolygonMode(GL_FRONT_AND_BACK, GL_FILL ); qglBegin( GL_QUADS ); qglVertex2f ( rect.x + (rect.w - GUIED_CENTERSIZE) / 2, rect.y + (rect.h - GUIED_CENTERSIZE) / 2 ); qglVertex2f ( rect.x + (rect.w + GUIED_CENTERSIZE) / 2, rect.y + (rect.h - GUIED_CENTERSIZE) / 2 ); qglVertex2f ( rect.x + (rect.w + GUIED_CENTERSIZE) / 2, rect.y + (rect.h + GUIED_CENTERSIZE) / 2 ); qglVertex2f ( rect.x + (rect.w - GUIED_CENTERSIZE) / 2, rect.y + (rect.h + GUIED_CENTERSIZE) / 2 ); qglEnd ( ); } if ( mExpression ) { return; } qglPolygonMode(GL_FRONT_AND_BACK, GL_LINE ); qglColor4f ( color[0],color[1],color[2], 1.0f ); qglBegin(GL_QUADS); // Top Left qglVertex2f ( mRect.x - GUIED_GRABSIZE, mRect.y - GUIED_GRABSIZE ); qglVertex2f ( mRect.x - 1, mRect.y - GUIED_GRABSIZE ); qglVertex2f ( mRect.x - 1, mRect.y - 1 ); qglVertex2f ( mRect.x - GUIED_GRABSIZE, mRect.y - 1 ); // Left qglVertex2f ( mRect.x - GUIED_GRABSIZE, mRect.y + mRect.h / 2 - GUIED_GRABSIZE / 2); qglVertex2f ( mRect.x - 1, mRect.y + mRect.h / 2 - GUIED_GRABSIZE / 2 ); qglVertex2f ( mRect.x - 1, mRect.y + mRect.h / 2 + GUIED_GRABSIZE / 2 ); qglVertex2f ( mRect.x - GUIED_GRABSIZE, mRect.y + mRect.h / 2 + GUIED_GRABSIZE / 2 ); // Bototm Left qglVertex2f ( mRect.x - GUIED_GRABSIZE, mRect.y + mRect.h + 1 ); qglVertex2f ( mRect.x - 1, mRect.y + mRect.h + 1 ); qglVertex2f ( mRect.x - 1, mRect.y + mRect.h + GUIED_GRABSIZE ); qglVertex2f ( mRect.x - GUIED_GRABSIZE, mRect.y + mRect.h + GUIED_GRABSIZE ); // Bottom qglVertex2f ( mRect.x - GUIED_GRABSIZE / 2 + mRect.w / 2, mRect.y + mRect.h + 1 ); qglVertex2f ( mRect.x + GUIED_GRABSIZE / 2 + mRect.w / 2, mRect.y + mRect.h + 1 ); qglVertex2f ( mRect.x + GUIED_GRABSIZE / 2 + mRect.w / 2, mRect.y + mRect.h + GUIED_GRABSIZE ); qglVertex2f ( mRect.x - GUIED_GRABSIZE / 2 + mRect.w / 2, mRect.y + mRect.h + GUIED_GRABSIZE ); // Bottom Right qglVertex2f ( mRect.x + mRect.w + 1, mRect.y + mRect.h + 1 ); qglVertex2f ( mRect.x + mRect.w + GUIED_GRABSIZE, mRect.y + mRect.h + 1 ); qglVertex2f ( mRect.x + mRect.w + GUIED_GRABSIZE, mRect.y + mRect.h + GUIED_GRABSIZE ); qglVertex2f ( mRect.x + mRect.w + 1, mRect.y + mRect.h + GUIED_GRABSIZE ); // Right qglVertex2f ( mRect.x + mRect.w + 1, mRect.y + mRect.h / 2 - GUIED_GRABSIZE / 2); qglVertex2f ( mRect.x + mRect.w + GUIED_GRABSIZE, mRect.y + mRect.h / 2 - GUIED_GRABSIZE / 2 ); qglVertex2f ( mRect.x + mRect.w + GUIED_GRABSIZE, mRect.y + mRect.h / 2 + GUIED_GRABSIZE / 2 ); qglVertex2f ( mRect.x + mRect.w + 1, mRect.y + mRect.h / 2 + GUIED_GRABSIZE / 2 ); // Top Right qglVertex2f ( mRect.x + mRect.w + 1, mRect.y - GUIED_GRABSIZE ); qglVertex2f ( mRect.x + mRect.w + GUIED_GRABSIZE, mRect.y - GUIED_GRABSIZE ); qglVertex2f ( mRect.x + mRect.w + GUIED_GRABSIZE, mRect.y - 1 ); qglVertex2f ( mRect.x + mRect.w + 1, mRect.y - 1 ); // Top qglVertex2f ( mRect.x - GUIED_GRABSIZE / 2 + mRect.w / 2, mRect.y - GUIED_GRABSIZE ); qglVertex2f ( mRect.x + GUIED_GRABSIZE / 2 + mRect.w / 2, mRect.y - GUIED_GRABSIZE ); qglVertex2f ( mRect.x + GUIED_GRABSIZE / 2 + mRect.w / 2, mRect.y - 1 ); qglVertex2f ( mRect.x - GUIED_GRABSIZE / 2 + mRect.w / 2, mRect.y - 1 ); qglEnd ( ); qglPolygonMode(GL_FRONT_AND_BACK, GL_FILL ); }
void R_DrawAliasShadows (entity_t **ents, int numents, void *meshbuffer) { if (r_shadows.value > 0.01f) { int i; qbool stateset = false; byte shadecolor[4] = {0, 0, 0, 128}; // extern int gl_stencilbits; for (i = 0; i < numents; i++) { entity_t *ent = ents[i]; glmatrix eshadow; if (!(ent->model->flags & MOD_NOSHADOW)) { aliasstate_t *state = &ent->aliasstate; aliashdr_t *hdr = Mod_Extradata (ent->model); float lheight = state->origin[2] - state->lightspot[2]; if (!stateset) { float *mesh = (float *) meshbuffer; qglDepthMask (GL_FALSE); qglEnable (GL_BLEND); GL_TexEnv (GL_TEXTURE1_ARB, GL_TEXTURE_2D, GL_NONE); GL_TexEnv (GL_TEXTURE0_ARB, GL_TEXTURE_2D, GL_NONE); qglColor4f (0, 0, 0, r_shadows.value); shadecolor[3] = BYTE_CLAMPF (r_shadows.value); /* if (gl_stencilbits) { qglEnable (GL_STENCIL_TEST); qglStencilFunc (GL_EQUAL, 1, 2); qglStencilOp (GL_KEEP, GL_KEEP, GL_INCR); } */ GL_SetStreamSource (GLSTREAM_POSITION, 3, GL_FLOAT, sizeof (float) * 4, mesh); GL_SetStreamSource (GLSTREAM_COLOR, 4, GL_UNSIGNED_BYTE, sizeof (float) * 4, &mesh[3]); GL_SetStreamSource (GLSTREAM_TEXCOORD0, 0, GL_NONE, 0, NULL); GL_SetStreamSource (GLSTREAM_TEXCOORD1, 0, GL_NONE, 0, NULL); GL_SetStreamSource (GLSTREAM_TEXCOORD2, 0, GL_NONE, 0, NULL); stateset = true; } GL_LoadMatrix (&eshadow, &r_world_matrix); if (state->origin[0] || state->origin[1] || state->origin[2]) GL_TranslateMatrix (&eshadow, state->origin[0], state->origin[1], state->origin[2]); GL_TranslateMatrix (&eshadow, 0, 0, -lheight); GL_MultiplyMatrix (&eshadow, &shadowmatrix, &eshadow); GL_TranslateMatrix (&eshadow, 0, 0, lheight); if (state->angles[1]) GL_RotateMatrix (&eshadow, state->angles[1], 0, 0, 1); GL_TranslateMatrix (&eshadow, hdr->scale_origin[0], hdr->scale_origin[1], hdr->scale_origin[2]); GL_ScaleMatrix (&eshadow, hdr->scale[0], hdr->scale[1], hdr->scale[2]); qglLoadMatrixf (eshadow.m16); R_DrawAliasShadow (ent, hdr, state, (float *) meshbuffer, (float *) shadecolor); } } if (stateset) { /* if (gl_stencilbits) qglDisable (GL_STENCIL_TEST); */ GL_TexEnv (GL_TEXTURE0_ARB, GL_TEXTURE_2D, GL_REPLACE); qglDisable (GL_BLEND); qglDepthMask (GL_TRUE); qglColor4f (1, 1, 1, 1); qglLoadMatrixf (r_world_matrix.m16); } } }
/* ================= RB_ShadowFinish Darken everything that is is a shadow volume. We have to delay this until everything has been shadowed, because otherwise shadows from different body parts would overlap and double darken. ================= */ void RB_ShadowFinish( void ) { if ( r_shadows->integer != 2 ) { return; } if ( glConfig.stencilBits < 4 ) { return; } #ifdef _DEBUG_STENCIL_SHADOWS return; #endif qglEnable( GL_STENCIL_TEST ); qglStencilFunc( GL_NOTEQUAL, 0, 255 ); qglStencilOp( GL_KEEP, GL_KEEP, GL_KEEP ); bool planeZeroBack = false; if (qglIsEnabled(GL_CLIP_PLANE0)) { planeZeroBack = true; qglDisable (GL_CLIP_PLANE0); } GL_Cull(CT_TWO_SIDED); //qglDisable (GL_CULL_FACE); GL_Bind( tr.whiteImage ); qglPushMatrix(); qglLoadIdentity (); // qglColor3f( 0.6f, 0.6f, 0.6f ); // GL_State( GLS_DEPTHMASK_TRUE | GLS_SRCBLEND_DST_COLOR | GLS_DSTBLEND_ZERO ); // qglColor3f( 1, 0, 0 ); // GL_State( GLS_DEPTHMASK_TRUE | GLS_SRCBLEND_ONE | GLS_DSTBLEND_ZERO ); qglColor4f( 0.0f, 0.0f, 0.0f, 0.5f ); //GL_State( GLS_DEPTHMASK_TRUE | GLS_SRCBLEND_SRC_ALPHA | GLS_DSTBLEND_ONE_MINUS_SRC_ALPHA ); GL_State( GLS_SRCBLEND_SRC_ALPHA | GLS_DSTBLEND_ONE_MINUS_SRC_ALPHA ); #ifdef HAVE_GLES GLfloat vtx[] = { -100, 100, -10, 100, 100, -10, 100, -100, -10, -100, -100, -10 }; GLboolean text = qglIsEnabled(GL_TEXTURE_COORD_ARRAY); GLboolean glcol = qglIsEnabled(GL_COLOR_ARRAY); if (text) qglDisableClientState( GL_TEXTURE_COORD_ARRAY ); if (glcol) qglDisableClientState( GL_COLOR_ARRAY ); qglVertexPointer ( 3, GL_FLOAT, 0, vtx ); qglDrawArrays( GL_TRIANGLE_FAN, 0, 4 ); if (text) qglEnableClientState( GL_TEXTURE_COORD_ARRAY ); if (glcol) qglEnableClientState( GL_COLOR_ARRAY ); #else qglBegin( GL_QUADS ); qglVertex3f( -100, 100, -10 ); qglVertex3f( 100, 100, -10 ); qglVertex3f( 100, -100, -10 ); qglVertex3f( -100, -100, -10 ); qglEnd (); #endif qglColor4f(1,1,1,1); qglDisable( GL_STENCIL_TEST ); if (planeZeroBack) { qglEnable (GL_CLIP_PLANE0); } qglPopMatrix(); }
/* ============= GL_DrawAliasFrameLerp interpolates between two frames and origins FIXME: batch lerp all vertexes ============= */ void GL_DrawAliasFrameLerp (dmdl_t *paliashdr, float backlerp) { float l; daliasframe_t *frame, *oldframe; dtrivertx_t *v, *ov, *verts; int *order; int count; float frontlerp; float alpha; vec3_t move, delta, vectors[3]; vec3_t frontv, backv; int i; int index_xyz; float *lerp; frame = (daliasframe_t *)((byte *)paliashdr + paliashdr->ofs_frames + currententity->frame * paliashdr->framesize); verts = v = frame->verts; oldframe = (daliasframe_t *)((byte *)paliashdr + paliashdr->ofs_frames + currententity->oldframe * paliashdr->framesize); ov = oldframe->verts; order = (int *)((byte *)paliashdr + paliashdr->ofs_glcmds); // glTranslatef (frame->translate[0], frame->translate[1], frame->translate[2]); // glScalef (frame->scale[0], frame->scale[1], frame->scale[2]); if (currententity->flags & RF_TRANSLUCENT) alpha = currententity->alpha; else alpha = 1.0; // PMM - added double shell if ( currententity->flags & ( RF_SHELL_RED | RF_SHELL_GREEN | RF_SHELL_BLUE | RF_SHELL_DOUBLE | RF_SHELL_HALF_DAM) ) qglDisable( GL_TEXTURE_2D ); frontlerp = 1.0 - backlerp; // move should be the delta back to the previous frame * backlerp VectorSubtract (currententity->oldorigin, currententity->origin, delta); AngleVectors (currententity->angles, vectors[0], vectors[1], vectors[2]); move[0] = DotProduct (delta, vectors[0]); // forward move[1] = -DotProduct (delta, vectors[1]); // left move[2] = DotProduct (delta, vectors[2]); // up VectorAdd (move, oldframe->translate, move); for (i=0 ; i<3 ; i++) { move[i] = backlerp*move[i] + frontlerp*frame->translate[i]; } for (i=0 ; i<3 ; i++) { frontv[i] = frontlerp*frame->scale[i]; backv[i] = backlerp*oldframe->scale[i]; } lerp = s_lerped[0]; GL_LerpVerts( paliashdr->num_xyz, v, ov, verts, lerp, move, frontv, backv ); if ( gl_vertex_arrays->value ) { float colorArray[MAX_VERTS*4]; qglEnableClientState( GL_VERTEX_ARRAY ); qglVertexPointer( 3, GL_FLOAT, 16, s_lerped ); // padded for SIMD // if ( currententity->flags & ( RF_SHELL_RED | RF_SHELL_GREEN | RF_SHELL_BLUE ) ) // PMM - added double damage shell if ( currententity->flags & ( RF_SHELL_RED | RF_SHELL_GREEN | RF_SHELL_BLUE | RF_SHELL_DOUBLE | RF_SHELL_HALF_DAM) ) { qglColor4f( shadelight[0], shadelight[1], shadelight[2], alpha ); } else { qglEnableClientState( GL_COLOR_ARRAY ); qglColorPointer( 3, GL_FLOAT, 0, colorArray ); // // pre light everything // for ( i = 0; i < paliashdr->num_xyz; i++ ) { float l = shadedots[verts[i].lightnormalindex]; colorArray[i*3+0] = l * shadelight[0]; colorArray[i*3+1] = l * shadelight[1]; colorArray[i*3+2] = l * shadelight[2]; } } if ( qglLockArraysEXT != 0 ) qglLockArraysEXT( 0, paliashdr->num_xyz ); while (1) { // get the vertex count and primitive type count = *order++; if (!count) break; // done if (count < 0) { count = -count; qglBegin (GL_TRIANGLE_FAN); } else { qglBegin (GL_TRIANGLE_STRIP); } // PMM - added double damage shell if ( currententity->flags & ( RF_SHELL_RED | RF_SHELL_GREEN | RF_SHELL_BLUE | RF_SHELL_DOUBLE | RF_SHELL_HALF_DAM) ) { do { index_xyz = order[2]; order += 3; qglVertex3fv( s_lerped[index_xyz] ); } while (--count); } else { do { // texture coordinates come from the draw list qglTexCoord2f (((float *)order)[0], ((float *)order)[1]); index_xyz = order[2]; order += 3; // normals and vertexes come from the frame list // l = shadedots[verts[index_xyz].lightnormalindex]; // qglColor4f (l* shadelight[0], l*shadelight[1], l*shadelight[2], alpha); qglArrayElement( index_xyz ); } while (--count); } qglEnd (); } if ( qglUnlockArraysEXT != 0 ) qglUnlockArraysEXT(); } else { while (1) { // get the vertex count and primitive type count = *order++; if (!count) break; // done if (count < 0) { count = -count; qglBegin (GL_TRIANGLE_FAN); } else { qglBegin (GL_TRIANGLE_STRIP); } if ( currententity->flags & ( RF_SHELL_RED | RF_SHELL_GREEN | RF_SHELL_BLUE ) ) { do { index_xyz = order[2]; order += 3; qglColor4f( shadelight[0], shadelight[1], shadelight[2], alpha); qglVertex3fv (s_lerped[index_xyz]); } while (--count); } else { do { // texture coordinates come from the draw list qglTexCoord2f (((float *)order)[0], ((float *)order)[1]); index_xyz = order[2]; order += 3; // normals and vertexes come from the frame list l = shadedots[verts[index_xyz].lightnormalindex]; qglColor4f (l* shadelight[0], l*shadelight[1], l*shadelight[2], alpha); qglVertex3fv (s_lerped[index_xyz]); } while (--count); } qglEnd (); } } // if ( currententity->flags & ( RF_SHELL_RED | RF_SHELL_GREEN | RF_SHELL_BLUE ) ) // PMM - added double damage shell if ( currententity->flags & ( RF_SHELL_RED | RF_SHELL_GREEN | RF_SHELL_BLUE | RF_SHELL_DOUBLE | RF_SHELL_HALF_DAM) ) qglEnable( GL_TEXTURE_2D ); }
/* ================= R_DrawAliasModel ================= */ void R_DrawAliasModel (entity_t *e) { int i; dmdl_t *paliashdr; float an; vec3_t bbox[8]; image_t *skin; if ( !( e->flags & RF_WEAPONMODEL ) ) { if ( R_CullAliasModel( bbox, e ) ) return; } if ( e->flags & RF_WEAPONMODEL ) { if ( r_lefthand->value == 2 ) return; } paliashdr = (dmdl_t *)currentmodel->extradata; // // get lighting information // // PMM - rewrote, reordered to handle new shells & mixing // if ( currententity->flags & ( RF_SHELL_HALF_DAM | RF_SHELL_GREEN | RF_SHELL_RED | RF_SHELL_BLUE | RF_SHELL_DOUBLE ) ) { // PMM -special case for godmode if ( (currententity->flags & RF_SHELL_RED) && (currententity->flags & RF_SHELL_BLUE) && (currententity->flags & RF_SHELL_GREEN) ) { for (i=0 ; i<3 ; i++) shadelight[i] = 1.0; } else if ( currententity->flags & ( RF_SHELL_RED | RF_SHELL_BLUE | RF_SHELL_DOUBLE ) ) { VectorClear (shadelight); if ( currententity->flags & RF_SHELL_RED ) { shadelight[0] = 1.0; if (currententity->flags & (RF_SHELL_BLUE|RF_SHELL_DOUBLE) ) shadelight[2] = 1.0; } else if ( currententity->flags & RF_SHELL_BLUE ) { if ( currententity->flags & RF_SHELL_DOUBLE ) { shadelight[1] = 1.0; shadelight[2] = 1.0; } else { shadelight[2] = 1.0; } } else if ( currententity->flags & RF_SHELL_DOUBLE ) { shadelight[0] = 0.9; shadelight[1] = 0.7; } } else if ( currententity->flags & ( RF_SHELL_HALF_DAM | RF_SHELL_GREEN ) ) { VectorClear (shadelight); // PMM - new colors if ( currententity->flags & RF_SHELL_HALF_DAM ) { shadelight[0] = 0.56; shadelight[1] = 0.59; shadelight[2] = 0.45; } if ( currententity->flags & RF_SHELL_GREEN ) { shadelight[1] = 1.0; } } } //PMM - ok, now flatten these down to range from 0 to 1.0. // max_shell_val = max(shadelight[0], max(shadelight[1], shadelight[2])); // if (max_shell_val > 0) // { // for (i=0; i<3; i++) // { // shadelight[i] = shadelight[i] / max_shell_val; // } // } // pmm else if ( currententity->flags & RF_FULLBRIGHT ) { for (i=0 ; i<3 ; i++) shadelight[i] = 1.0; } else { R_LightPoint (currententity->origin, shadelight); // player lighting hack for communication back to server // big hack! if ( currententity->flags & RF_WEAPONMODEL ) { // pick the greatest component, which should be the same // as the mono value returned by software if (shadelight[0] > shadelight[1]) { if (shadelight[0] > shadelight[2]) r_lightlevel->value = 150*shadelight[0]; else r_lightlevel->value = 150*shadelight[2]; } else { if (shadelight[1] > shadelight[2]) r_lightlevel->value = 150*shadelight[1]; else r_lightlevel->value = 150*shadelight[2]; } } if ( gl_monolightmap->string[0] != '0' ) { float s = shadelight[0]; if ( s < shadelight[1] ) s = shadelight[1]; if ( s < shadelight[2] ) s = shadelight[2]; shadelight[0] = s; shadelight[1] = s; shadelight[2] = s; } } if ( currententity->flags & RF_MINLIGHT ) { for (i=0 ; i<3 ; i++) if (shadelight[i] > 0.1) break; if (i == 3) { shadelight[0] = 0.1; shadelight[1] = 0.1; shadelight[2] = 0.1; } } if ( currententity->flags & RF_GLOW ) { // bonus items will pulse with time float scale; float min; scale = 0.1 * sin(r_newrefdef.time*7); for (i=0 ; i<3 ; i++) { min = shadelight[i] * 0.8; shadelight[i] += scale; if (shadelight[i] < min) shadelight[i] = min; } } // ================= // PGM ir goggles color override if ( r_newrefdef.rdflags & RDF_IRGOGGLES && currententity->flags & RF_IR_VISIBLE) { shadelight[0] = 1.0; shadelight[1] = 0.0; shadelight[2] = 0.0; } // PGM // ================= shadedots = r_avertexnormal_dots[((int)(currententity->angles[1] * (SHADEDOT_QUANT / 360.0))) & (SHADEDOT_QUANT - 1)]; an = currententity->angles[1]/180*M_PI; shadevector[0] = cos(-an); shadevector[1] = sin(-an); shadevector[2] = 1; VectorNormalize (shadevector); // // locate the proper data // c_alias_polys += paliashdr->num_tris; // // draw all the triangles // if (currententity->flags & RF_DEPTHHACK) // hack the depth range to prevent view model from poking into walls qglDepthRange (gldepthmin, gldepthmin + 0.3*(gldepthmax-gldepthmin)); if ( ( currententity->flags & RF_WEAPONMODEL ) && ( r_lefthand->value == 1.0F ) ) { extern void MYgluPerspective( GLdouble fovy, GLdouble aspect, GLdouble zNear, GLdouble zFar ); qglMatrixMode( GL_PROJECTION ); qglPushMatrix(); qglLoadIdentity(); qglScalef( -1, 1, 1 ); MYgluPerspective( r_newrefdef.fov_y, ( float ) r_newrefdef.width / r_newrefdef.height, 4, 4096); qglMatrixMode( GL_MODELVIEW ); qglCullFace( GL_BACK ); } qglPushMatrix (); e->angles[PITCH] = -e->angles[PITCH]; // sigh. R_RotateForEntity (e); e->angles[PITCH] = -e->angles[PITCH]; // sigh. // select skin if (currententity->skin) skin = currententity->skin; // custom player skin else { if (currententity->skinnum >= MAX_MD2SKINS) skin = currentmodel->skins[0]; else { skin = currentmodel->skins[currententity->skinnum]; if (!skin) skin = currentmodel->skins[0]; } } if (!skin) skin = r_notexture; // fallback... GL_Bind(skin->texnum); // draw it qglShadeModel (GL_SMOOTH); GL_TexEnv( GL_MODULATE ); if ( currententity->flags & RF_TRANSLUCENT ) { qglEnable (GL_BLEND); } if ( (currententity->frame >= paliashdr->num_frames) || (currententity->frame < 0) ) { ri.Con_Printf (PRINT_ALL, "R_DrawAliasModel %s: no such frame %d\n", currentmodel->name, currententity->frame); currententity->frame = 0; currententity->oldframe = 0; } if ( (currententity->oldframe >= paliashdr->num_frames) || (currententity->oldframe < 0)) { ri.Con_Printf (PRINT_ALL, "R_DrawAliasModel %s: no such oldframe %d\n", currentmodel->name, currententity->oldframe); currententity->frame = 0; currententity->oldframe = 0; } if ( !r_lerpmodels->value ) currententity->backlerp = 0; GL_DrawAliasFrameLerp (paliashdr, currententity->backlerp); GL_TexEnv( GL_REPLACE ); qglShadeModel (GL_FLAT); qglPopMatrix (); #if 0 qglDisable( GL_CULL_FACE ); qglPolygonMode( GL_FRONT_AND_BACK, GL_LINE ); qglDisable( GL_TEXTURE_2D ); qglBegin( GL_TRIANGLE_STRIP ); for ( i = 0; i < 8; i++ ) { qglVertex3fv( bbox[i] ); } qglEnd(); qglEnable( GL_TEXTURE_2D ); qglPolygonMode( GL_FRONT_AND_BACK, GL_FILL ); qglEnable( GL_CULL_FACE ); #endif if ( ( currententity->flags & RF_WEAPONMODEL ) && ( r_lefthand->value == 1.0F ) ) { qglMatrixMode( GL_PROJECTION ); qglPopMatrix(); qglMatrixMode( GL_MODELVIEW ); qglCullFace( GL_FRONT ); } if ( currententity->flags & RF_TRANSLUCENT ) { qglDisable (GL_BLEND); } if (currententity->flags & RF_DEPTHHACK) qglDepthRange (gldepthmin, gldepthmax); #if 1 if (gl_shadows->value && !(currententity->flags & (RF_TRANSLUCENT | RF_WEAPONMODEL))) { qglPushMatrix (); R_RotateForEntity (e); qglDisable (GL_TEXTURE_2D); qglEnable (GL_BLEND); qglColor4f (0,0,0,0.5); GL_DrawAliasShadow (paliashdr, currententity->frame ); qglEnable (GL_TEXTURE_2D); qglDisable (GL_BLEND); qglPopMatrix (); } #endif qglColor4f (1,1,1,1); }