From 0c3ec34db92be94354dd7e3e4e9a9955f14f718e Mon Sep 17 00:00:00 2001 From: Zack Middleton Date: Fri, 24 May 2013 22:02:52 -0500 Subject: [PATCH] Allow drawing sun in OpenGL1 renderer Removed #if 0 ... #endif around RB_DrawSun(). Merged improvements and changes from OpenGL2 renderer. --- code/renderergl1/tr_backend.c | 7 ++-- code/renderergl1/tr_local.h | 2 +- code/renderergl1/tr_sky.c | 63 ++++------------------------------- 3 files changed, 11 insertions(+), 61 deletions(-) diff --git a/code/renderergl1/tr_backend.c b/code/renderergl1/tr_backend.c index 5bff947b..60449261 100644 --- a/code/renderergl1/tr_backend.c +++ b/code/renderergl1/tr_backend.c @@ -668,9 +668,10 @@ void RB_RenderDrawSurfList( drawSurf_t *drawSurfs, int numDrawSurfs ) { qglDepthRange (0, 1); } -#if 0 - RB_DrawSun(); -#endif + if (r_drawSun->integer) { + RB_DrawSun(0.1, tr.sunShader); + } + // darken down any stencil shadows RB_ShadowFinish(); diff --git a/code/renderergl1/tr_local.h b/code/renderergl1/tr_local.h index 925dec29..dd292bc6 100644 --- a/code/renderergl1/tr_local.h +++ b/code/renderergl1/tr_local.h @@ -1326,7 +1326,7 @@ SKIES void R_BuildCloudData( shaderCommands_t *shader ); void R_InitSkyTexCoords( float cloudLayerHeight ); void R_DrawSkyBox( shaderCommands_t *shader ); -void RB_DrawSun( void ); +void RB_DrawSun( float scale, shader_t *shader ); void RB_ClipSkyPolygons( shaderCommands_t *shader ); /* diff --git a/code/renderergl1/tr_sky.c b/code/renderergl1/tr_sky.c index 3e774a31..daa5ff12 100644 --- a/code/renderergl1/tr_sky.c +++ b/code/renderergl1/tr_sky.c @@ -696,23 +696,21 @@ void R_InitSkyTexCoords( float heightCloud ) /* ** RB_DrawSun */ -void RB_DrawSun( void ) { +void RB_DrawSun( float scale, shader_t *shader ) { float size; float dist; vec3_t origin, vec1, vec2; - vec3_t temp; + byte sunColor[4] = { 255, 255, 255, 255 }; if ( !backEnd.skyRenderedThisView ) { return; } - if ( !r_drawSun->integer ) { - return; - } + qglLoadMatrixf( backEnd.viewParms.world.modelMatrix ); qglTranslatef (backEnd.viewParms.or.origin[0], backEnd.viewParms.or.origin[1], backEnd.viewParms.or.origin[2]); dist = backEnd.viewParms.zFar / 1.75; // div sqrt(3) - size = dist * 0.4; + size = dist * scale; VectorScale( tr.sunDirection, dist, origin ); PerpendicularVector( vec1, tr.sunDirection ); @@ -724,58 +722,9 @@ void RB_DrawSun( void ) { // farthest depth range qglDepthRange( 1.0, 1.0 ); - // FIXME: use quad stamp - RB_BeginSurface( tr.sunShader, tess.fogNum ); - VectorCopy( origin, temp ); - VectorSubtract( temp, vec1, temp ); - VectorSubtract( temp, vec2, temp ); - VectorCopy( temp, tess.xyz[tess.numVertexes] ); - tess.texCoords[tess.numVertexes][0][0] = 0; - tess.texCoords[tess.numVertexes][0][1] = 0; - tess.vertexColors[tess.numVertexes][0] = 255; - tess.vertexColors[tess.numVertexes][1] = 255; - tess.vertexColors[tess.numVertexes][2] = 255; - tess.numVertexes++; + RB_BeginSurface( shader, 0 ); - VectorCopy( origin, temp ); - VectorAdd( temp, vec1, temp ); - VectorSubtract( temp, vec2, temp ); - VectorCopy( temp, tess.xyz[tess.numVertexes] ); - tess.texCoords[tess.numVertexes][0][0] = 0; - tess.texCoords[tess.numVertexes][0][1] = 1; - tess.vertexColors[tess.numVertexes][0] = 255; - tess.vertexColors[tess.numVertexes][1] = 255; - tess.vertexColors[tess.numVertexes][2] = 255; - tess.numVertexes++; - - VectorCopy( origin, temp ); - VectorAdd( temp, vec1, temp ); - VectorAdd( temp, vec2, temp ); - VectorCopy( temp, tess.xyz[tess.numVertexes] ); - tess.texCoords[tess.numVertexes][0][0] = 1; - tess.texCoords[tess.numVertexes][0][1] = 1; - tess.vertexColors[tess.numVertexes][0] = 255; - tess.vertexColors[tess.numVertexes][1] = 255; - tess.vertexColors[tess.numVertexes][2] = 255; - tess.numVertexes++; - - VectorCopy( origin, temp ); - VectorSubtract( temp, vec1, temp ); - VectorAdd( temp, vec2, temp ); - VectorCopy( temp, tess.xyz[tess.numVertexes] ); - tess.texCoords[tess.numVertexes][0][0] = 1; - tess.texCoords[tess.numVertexes][0][1] = 0; - tess.vertexColors[tess.numVertexes][0] = 255; - tess.vertexColors[tess.numVertexes][1] = 255; - tess.vertexColors[tess.numVertexes][2] = 255; - tess.numVertexes++; - - tess.indexes[tess.numIndexes++] = 0; - tess.indexes[tess.numIndexes++] = 1; - tess.indexes[tess.numIndexes++] = 2; - tess.indexes[tess.numIndexes++] = 0; - tess.indexes[tess.numIndexes++] = 2; - tess.indexes[tess.numIndexes++] = 3; + RB_AddQuadStamp(origin, vec1, vec2, sunColor); RB_EndSurface();