/* * ================ Draw_Char * * Draws one 8*8 graphics character with 0 being transparent. It can be clipped * to the top of the screen to allow the console to be smoothly scrolled off. * ================ */ void Draw_Char(int x, int y, int num, int alpha) { int row, col; float frow, fcol, size; num &= 255; if (alpha >= 254) alpha = 254; else if (alpha <= 1) alpha = 1; if ((num & 127) == 32) return; /* space */ if (y <= -8) return; /* totally off screen */ row = num >> 4; col = num & 15; frow = row * 0.0625; fcol = col * 0.0625; size = 0.0625; { /* GLSTATE_DISABLE_ALPHATEST */ qglDisable(GL_ALPHA_TEST); GL_TexEnv(GL_MODULATE); qglColor4ub(255, 255, 255, alpha); /* GLSTATE_ENABLE_BLEND */ qglEnable(GL_BLEND); qglDepthMask(false); } GL_Bind(draw_chars->texnum); qglBegin(GL_QUADS); qglTexCoord2f(fcol, frow); qglVertex2f(x, y); qglTexCoord2f(fcol + size, frow); qglVertex2f(x + 8, y); qglTexCoord2f(fcol + size, frow + size); qglVertex2f(x + 8, y + 8); qglTexCoord2f(fcol, frow + size); qglVertex2f(x, y + 8); qglEnd(); { qglDepthMask(true); GL_TexEnv(GL_REPLACE); /* GLSTATE_DISABLE_BLEND */ qglDisable(GL_BLEND); qglColor4f(1,1,1,1); /* GLSTATE_ENABLE_ALPHATEST */ qglEnable(GL_ALPHA_TEST); } }
/* * ============= Draw_StretchPic -- only used for drawing console... * ============= */ void Draw_StretchPic(int x, int y, int w, int h, char *pic, float alpha) { image_t *gl; gl = Draw_FindPic(pic); if (!gl) { ri.Con_Printf(PRINT_ALL, "Can't find pic: %s\n", pic); return; } if (scrap_dirty) Scrap_Upload(); if (((gl_config.renderer == GL_RENDERER_MCD) || (gl_config.renderer & GL_RENDERER_RENDITION)) && !gl->has_alpha) qglDisable(GL_ALPHA_TEST); /* add alpha support */ if (gl->has_alpha || alpha < 1) { qglDisable(GL_ALPHA_TEST); GL_Bind(gl->texnum); GL_TexEnv(GL_MODULATE); qglColor4f(1, 1, 1, alpha); qglEnable(GL_BLEND); qglDepthMask(false); } else GL_Bind(gl->texnum); qglBegin(GL_QUADS); qglTexCoord2f(gl->sl, gl->tl); qglVertex2f(x, y); qglTexCoord2f(gl->sh, gl->tl); qglVertex2f(x + w, y); qglTexCoord2f(gl->sh, gl->th); qglVertex2f(x + w, y + h); qglTexCoord2f(gl->sl, gl->th); qglVertex2f(x, y + h); qglEnd(); /* add alpha support */ if (gl->has_alpha || alpha < 1) { qglDepthMask(true); GL_TexEnv(GL_REPLACE); qglDisable(GL_BLEND); qglColor4f(1, 1, 1, 1); qglEnable(GL_ALPHA_TEST); } if (((gl_config.renderer == GL_RENDERER_MCD) || (gl_config.renderer & GL_RENDERER_RENDITION)) && !gl->has_alpha) qglEnable(GL_ALPHA_TEST); }
/* * ============= Draw_Pic ============= */ void Draw_Pic(int x, int y, char *pic, float alpha) { image_t *gl; gl = Draw_FindPic(pic); if (!gl) { ri.Con_Printf(PRINT_ALL, "Can't find pic: %s\n", pic); return; } if (scrap_dirty) Scrap_Upload(); if (((gl_config.renderer == GL_RENDERER_MCD) || (gl_config.renderer & GL_RENDERER_RENDITION)) && !gl->has_alpha) qglDisable(GL_ALPHA_TEST); /* add alpha support */ { qglDisable(GL_ALPHA_TEST); qglBindTexture(GL_TEXTURE_2D, gl->texnum); GL_TexEnv(GL_MODULATE); qglColor4f(1, 1, 1, 0.999); /* need <1 for trans to work */ qglEnable(GL_BLEND); qglDepthMask(false); } GL_Bind(gl->texnum); qglBegin(GL_QUADS); qglTexCoord2f(gl->sl, gl->tl); qglVertex2f(x, y); qglTexCoord2f(gl->sh, gl->tl); qglVertex2f(x + gl->width, y); qglTexCoord2f(gl->sh, gl->th); qglVertex2f(x + gl->width, y + gl->height); qglTexCoord2f(gl->sl, gl->th); qglVertex2f(x, y + gl->height); qglEnd(); /* add alpha support */ { qglDepthMask(true); GL_TexEnv(GL_REPLACE); qglDisable(GL_BLEND); qglColor4f(1, 1, 1, 1); qglEnable(GL_ALPHA_TEST); } if (((gl_config.renderer == GL_RENDERER_MCD) || (gl_config.renderer & GL_RENDERER_RENDITION)) && !gl->has_alpha) qglEnable(GL_ALPHA_TEST); }
void Gui_Render() { const text_shader_description *shader = renderer.shaderManager->getTextShader(); screenSize[0] = screen_info.w; screenSize[1] = screen_info.h; qglUseProgramObjectARB(shader->program); qglUniform1iARB(shader->sampler, 0); qglUniform2fvARB(shader->screenSize, 1, screenSize); qglUniform1fARB(shader->colorReplace, 0.0f); qglPushAttrib(GL_ENABLE_BIT | GL_PIXEL_MODE_BIT | GL_COLOR_BUFFER_BIT); qglPushClientAttrib(GL_CLIENT_PIXEL_STORE_BIT | GL_CLIENT_VERTEX_ARRAY_BIT); qglEnableClientState(GL_TEXTURE_COORD_ARRAY); qglPolygonMode(GL_FRONT, GL_FILL); qglFrontFace(GL_CCW); qglEnable(GL_BLEND); qglBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); qglDisable(GL_ALPHA_TEST); if(World_GetPlayer() && main_inventory_manager) { Gui_DrawInventory(engine_frame_time); } Gui_DrawNotifier(engine_frame_time); qglUseProgramObjectARB(shader->program); qglDepthMask(GL_FALSE); qglPixelStorei(GL_UNPACK_LSB_FIRST, GL_FALSE); qglPixelStorei(GL_UNPACK_ALIGNMENT, 1); if(screen_info.crosshair != 0) { Gui_DrawCrosshair(); } Gui_DrawBars(); qglUniform1fARB(shader->colorReplace, 1.0f); GLText_RenderStrings(); Con_Draw(engine_frame_time); qglUniform1fARB(shader->colorReplace, 0.0f); qglDepthMask(GL_TRUE); qglPopClientAttrib(); qglPopAttrib(); }
/* ** 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.faceCulling = CT_TWO_SIDED; glState.faceCullFront = qtrue; glState.currentProgram = 0; qglUseProgramObjectARB(0); if (glRefConfig.vertexArrayObject) qglBindVertexArrayARB(0); qglBindBufferARB(GL_ARRAY_BUFFER_ARB, 0); qglBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 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 }
/* ====================== 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 ); } } }
/* ** 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 ); qglColorMask( GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE ); qglClearColor( 0.0f, 0.0f, 0.0f, 1.0f ); qglClearDepth( 1.0 ); qglDrawBuffer( GL_FRONT ); #ifdef IOS qglClear( GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT|GL_STENCIL_BUFFER_BIT ); #else qglClear( GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT|GL_ACCUM_BUFFER_BIT|GL_STENCIL_BUFFER_BIT ); #endif qglDrawBuffer( GL_BACK ); #ifdef IOS qglClear( GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT|GL_STENCIL_BUFFER_BIT ); #else qglClear( GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT|GL_ACCUM_BUFFER_BIT|GL_STENCIL_BUFFER_BIT ); #endif }
/* ** 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; 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 ); qglColorMask( GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE ); qglClearColor( 0.0f, 0.0f, 0.0f, 1.0f ); qglClearDepth( 1.0 ); qglDrawBuffer( GL_FRONT ); qglClear( GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT|GL_ACCUM_BUFFER_BIT|GL_STENCIL_BUFFER_BIT ); qglDrawBuffer( GL_BACK ); qglClear( GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT|GL_ACCUM_BUFFER_BIT|GL_STENCIL_BUFFER_BIT ); }
/* ================== GL_DepthMask ================== */ void GL_DepthMask (bool mask){ if (glState.depthMask == mask) return; glState.depthMask = mask; qglDepthMask(mask); }
void Sky_DepthClipEnd (void) { qglColorMask (GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); qglColor4f (1, 1, 1, 1); GL_TexEnv (GL_TEXTURE0_ARB, GL_TEXTURE_2D, GL_REPLACE); // invert the depth function so that the sky will actually draw qglDepthFunc (GL_GEQUAL); qglDepthMask (0); }
void Gui_DrawLoadScreen(int value) { qglClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); qglPushAttrib(GL_ENABLE_BIT | GL_PIXEL_MODE_BIT | GL_COLOR_BUFFER_BIT); qglPushClientAttrib(GL_CLIENT_PIXEL_STORE_BIT); qglPixelStorei(GL_UNPACK_LSB_FIRST, GL_FALSE); qglPixelStorei(GL_UNPACK_ALIGNMENT, 1); qglEnableClientState(GL_VERTEX_ARRAY); qglEnableClientState(GL_TEXTURE_COORD_ARRAY); qglEnableClientState(GL_COLOR_ARRAY); qglDisableClientState(GL_NORMAL_ARRAY); qglEnable(GL_BLEND); qglEnable(GL_TEXTURE_2D); qglDisable(GL_ALPHA_TEST); qglDepthMask(GL_FALSE); qglPolygonMode(GL_FRONT, GL_FILL); qglFrontFace(GL_CCW); const GLfloat color_w[4] = {1.0f, 1.0f, 1.0f, 1.0f}; const text_shader_description *shader = renderer.shaderManager->getTextShader(); screenSize[0] = screen_info.w; screenSize[1] = screen_info.h; qglUseProgramObjectARB(shader->program); qglUniform1iARB(shader->sampler, 0); qglUniform2fvARB(shader->screenSize, 1, screenSize); Gui_DrawRect(0.0, 0.0, screen_info.w, screen_info.h, color_w, color_w, color_w, color_w, BM_OPAQUE, load_screen_tex); if(value >= 0) { Bar[BAR_LOADING].Show(value); } qglDepthMask(GL_TRUE); qglPopClientAttrib(); qglPopAttrib(); Engine_GLSwapWindow(); }
/* ** 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 }
/* ** 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); }
void RB_MaskTessEnd( void ) { shaderCommands_t *input; input = &tess; //qglClear( GL_COLOR_BUFFER_BIT ); qglColorMask(GL_FALSE,GL_FALSE,GL_FALSE,GL_FALSE); qglDepthMask(GL_FALSE); qglEnable(GL_STENCIL_TEST); qglClearStencil(0); qglClear(GL_STENCIL_BUFFER_BIT); qglStencilFunc(GL_ALWAYS,1,1); qglStencilOp(GL_KEEP,GL_KEEP,GL_REPLACE); tess.currentStageIteratorFunc(); qglDepthMask(GL_TRUE); qglColorMask(GL_TRUE,GL_TRUE,GL_TRUE,GL_TRUE); qglStencilFunc(GL_EQUAL,1,1); qglStencilOp(GL_KEEP,GL_KEEP,GL_KEEP); }
/* ================== 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; glPixelStorei(GL_PACK_ALIGNMENT, 1); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); //*SEB* ? not the best place ! glLockArraysEXT = NULL; glUnlockArraysEXT = NULL; qglDepthMask(GL_TRUE); qglDisable(GL_DEPTH_TEST); qglEnable(GL_SCISSOR_TEST); qglDisable(GL_CULL_FACE); qglDisable(GL_BLEND); }
/* * RB_SetGLDefaults */ static void RB_SetGLDefaults( void ) { int i; qglClearColor( 1, 0, 0.5, 0.5 ); if( glConfig.stencilEnabled ) { qglStencilMask( ( GLuint ) ~0 ); qglStencilFunc( GL_EQUAL, 128, 0xFF ); qglStencilOp( GL_KEEP, GL_KEEP, GL_INCR ); } // properly disable multitexturing at startup for( i = glConfig.maxTextureUnits-1; i >= 0; i-- ) { RB_SelectTextureUnit( i ); qglDisable( GL_TEXTURE_2D ); } qglEnable( GL_TEXTURE_2D ); qglDisable( GL_CULL_FACE ); qglFrontFace( GL_CCW ); qglEnable( GL_SCISSOR_TEST ); qglDisable( GL_BLEND ); qglDisable( GL_ALPHA_TEST ); qglDepthFunc( GL_LEQUAL ); qglDepthMask( GL_FALSE ); qglDisable( GL_POLYGON_OFFSET_FILL ); qglColorMask( GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE ); qglEnable( GL_DEPTH_TEST ); qglShadeModel( GL_SMOOTH ); if( qglPolygonMode ) { qglPolygonMode( GL_FRONT_AND_BACK, GL_FILL ); } qglFrontFace( GL_CCW ); rb.gl.state = 0; rb.gl.frontFace = qfalse; rb.gl.currentTMU = -1; rb.gl.faceCull = 0; rb.gl.polygonOffset[0] = rb.gl.polygonOffset[1] = 0; memset( rb.gl.currentTextures, 0, sizeof( rb.gl.currentTextures ) ); }
void RadiantRun( void ) { static bool exceptionErr = false; int show = ::IsWindowVisible(win32.hWnd); try { if (!exceptionErr && !show) { //qglPushAttrib(GL_ALL_ATTRIB_BITS); qglDepthMask(true); theApp.Run(); //qglPopAttrib(); //qwglMakeCurrent(0, 0); renderDevice->BindDeviceToWindow(win32.hDC); } } catch( idException &ex ) { ::MessageBox(NULL, ex.error, "Exception error", MB_OK); RadiantShutdown(); } }
/* * RB_SetGLDefaults */ static void RB_SetGLDefaults( void ) { if( glConfig.stencilBits ) { qglStencilMask( ( GLuint ) ~0 ); qglStencilFunc( GL_EQUAL, 128, 0xFF ); qglStencilOp( GL_KEEP, GL_KEEP, GL_INCR ); } qglDisable( GL_CULL_FACE ); qglFrontFace( GL_CCW ); qglDisable( GL_BLEND ); qglDepthFunc( GL_LEQUAL ); qglDepthMask( GL_FALSE ); qglDisable( GL_POLYGON_OFFSET_FILL ); qglPolygonOffset( -1.0f, 0.0f ); // units will be handled by RB_DepthOffset qglColorMask( GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE ); qglEnable( GL_DEPTH_TEST ); #ifndef GL_ES_VERSION_2_0 qglPolygonMode( GL_FRONT_AND_BACK, GL_FILL ); #endif qglFrontFace( GL_CCW ); }
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_SetState */ void RB_SetState( int state ) { int diff; diff = rb.gl.state ^ state; if( !diff ) return; if( diff & GLSTATE_BLEND_MASK ) { if( state & GLSTATE_BLEND_MASK ) { int blendsrc, blenddst; switch( state & GLSTATE_SRCBLEND_MASK ) { case GLSTATE_SRCBLEND_ZERO: blendsrc = GL_ZERO; break; case GLSTATE_SRCBLEND_DST_COLOR: blendsrc = GL_DST_COLOR; break; case GLSTATE_SRCBLEND_ONE_MINUS_DST_COLOR: blendsrc = GL_ONE_MINUS_DST_COLOR; break; case GLSTATE_SRCBLEND_SRC_ALPHA: blendsrc = GL_SRC_ALPHA; break; case GLSTATE_SRCBLEND_ONE_MINUS_SRC_ALPHA: blendsrc = GL_ONE_MINUS_SRC_ALPHA; break; case GLSTATE_SRCBLEND_DST_ALPHA: blendsrc = GL_DST_ALPHA; break; case GLSTATE_SRCBLEND_ONE_MINUS_DST_ALPHA: blendsrc = GL_ONE_MINUS_DST_ALPHA; break; default: case GLSTATE_SRCBLEND_ONE: blendsrc = GL_ONE; break; } switch( state & GLSTATE_DSTBLEND_MASK ) { case GLSTATE_DSTBLEND_ONE: blenddst = GL_ONE; break; case GLSTATE_DSTBLEND_SRC_COLOR: blenddst = GL_SRC_COLOR; break; case GLSTATE_DSTBLEND_ONE_MINUS_SRC_COLOR: blenddst = GL_ONE_MINUS_SRC_COLOR; break; case GLSTATE_DSTBLEND_SRC_ALPHA: blenddst = GL_SRC_ALPHA; break; case GLSTATE_DSTBLEND_ONE_MINUS_SRC_ALPHA: blenddst = GL_ONE_MINUS_SRC_ALPHA; break; case GLSTATE_DSTBLEND_DST_ALPHA: blenddst = GL_DST_ALPHA; break; case GLSTATE_DSTBLEND_ONE_MINUS_DST_ALPHA: blenddst = GL_ONE_MINUS_DST_ALPHA; break; default: case GLSTATE_DSTBLEND_ZERO: blenddst = GL_ZERO; break; } if( !( rb.gl.state & GLSTATE_BLEND_MASK ) ) qglEnable( GL_BLEND ); qglBlendFuncSeparateEXT( blendsrc, blenddst, GL_ONE, GL_ONE ); } else { qglDisable( GL_BLEND ); } } if( diff & (GLSTATE_NO_COLORWRITE|GLSTATE_ALPHAWRITE) ) { if( state & GLSTATE_NO_COLORWRITE ) qglColorMask( GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE ); else qglColorMask( GL_TRUE, GL_TRUE, GL_TRUE, ( state & GLSTATE_ALPHAWRITE ) ? GL_TRUE : GL_FALSE ); } if( diff & (GLSTATE_DEPTHFUNC_EQ|GLSTATE_DEPTHFUNC_GT) ) { if( state & GLSTATE_DEPTHFUNC_EQ ) qglDepthFunc( GL_EQUAL ); else if( state & GLSTATE_DEPTHFUNC_GT ) qglDepthFunc( GL_GREATER ); else qglDepthFunc( GL_LEQUAL ); } if( diff & GLSTATE_DEPTHWRITE ) { if( state & GLSTATE_DEPTHWRITE ) qglDepthMask( GL_TRUE ); else qglDepthMask( GL_FALSE ); } if( diff & GLSTATE_NO_DEPTH_TEST ) { if( state & GLSTATE_NO_DEPTH_TEST ) qglDisable( GL_DEPTH_TEST ); else qglEnable( GL_DEPTH_TEST ); } if( diff & GLSTATE_OFFSET_FILL ) { if( state & GLSTATE_OFFSET_FILL ) { qglEnable( GL_POLYGON_OFFSET_FILL ); RB_DepthOffset( true ); } else { qglDisable( GL_POLYGON_OFFSET_FILL ); RB_DepthOffset( false ); } } if( diff & GLSTATE_STENCIL_TEST ) { if( glConfig.stencilBits ) { if( state & GLSTATE_STENCIL_TEST ) qglEnable( GL_STENCIL_TEST ); else qglDisable( GL_STENCIL_TEST ); } } if( diff & GLSTATE_ALPHATEST ) { if( glConfig.ext.multisample ) { if( state & GLSTATE_ALPHATEST ) qglEnable( GL_SAMPLE_ALPHA_TO_COVERAGE_ARB ); else qglDisable( GL_SAMPLE_ALPHA_TO_COVERAGE_ARB ); } } rb.gl.state = state; }
/* * RB_SetState */ void RB_SetState( int state ) { int diff; diff = rb.gl.state ^ state; if( !diff ) return; if( diff & ( GLSTATE_SRCBLEND_MASK|GLSTATE_DSTBLEND_MASK ) ) { if( state & ( GLSTATE_SRCBLEND_MASK|GLSTATE_DSTBLEND_MASK ) ) { int blendsrc, blenddst; switch( state & GLSTATE_SRCBLEND_MASK ) { case GLSTATE_SRCBLEND_ZERO: blendsrc = GL_ZERO; break; case GLSTATE_SRCBLEND_DST_COLOR: blendsrc = GL_DST_COLOR; break; case GLSTATE_SRCBLEND_ONE_MINUS_DST_COLOR: blendsrc = GL_ONE_MINUS_DST_COLOR; break; case GLSTATE_SRCBLEND_SRC_ALPHA: blendsrc = GL_SRC_ALPHA; break; case GLSTATE_SRCBLEND_ONE_MINUS_SRC_ALPHA: blendsrc = GL_ONE_MINUS_SRC_ALPHA; break; case GLSTATE_SRCBLEND_DST_ALPHA: blendsrc = GL_DST_ALPHA; break; case GLSTATE_SRCBLEND_ONE_MINUS_DST_ALPHA: blendsrc = GL_ONE_MINUS_DST_ALPHA; break; default: case GLSTATE_SRCBLEND_ONE: blendsrc = GL_ONE; break; } switch( state & GLSTATE_DSTBLEND_MASK ) { case GLSTATE_DSTBLEND_ONE: blenddst = GL_ONE; break; case GLSTATE_DSTBLEND_SRC_COLOR: blenddst = GL_SRC_COLOR; break; case GLSTATE_DSTBLEND_ONE_MINUS_SRC_COLOR: blenddst = GL_ONE_MINUS_SRC_COLOR; break; case GLSTATE_DSTBLEND_SRC_ALPHA: blenddst = GL_SRC_ALPHA; break; case GLSTATE_DSTBLEND_ONE_MINUS_SRC_ALPHA: blenddst = GL_ONE_MINUS_SRC_ALPHA; break; case GLSTATE_DSTBLEND_DST_ALPHA: blenddst = GL_DST_ALPHA; break; case GLSTATE_DSTBLEND_ONE_MINUS_DST_ALPHA: blenddst = GL_ONE_MINUS_DST_ALPHA; break; default: case GLSTATE_DSTBLEND_ZERO: blenddst = GL_ZERO; break; } qglEnable( GL_BLEND ); qglBlendFunc( blendsrc, blenddst ); } else { qglDisable( GL_BLEND ); } } if( diff & GLSTATE_ALPHAFUNC ) { int alphafunc = state & GLSTATE_ALPHAFUNC; if( alphafunc ) { qglEnable( GL_ALPHA_TEST ); if( alphafunc == GLSTATE_AFUNC_GT0 ) qglAlphaFunc( GL_GREATER, 0 ); else if( alphafunc == GLSTATE_AFUNC_LT128 ) qglAlphaFunc( GL_LESS, 0.5f ); else qglAlphaFunc( GL_GEQUAL, 0.5f ); } else { qglDisable( GL_ALPHA_TEST ); } } if( diff & GLSTATE_NO_COLORWRITE ) { if( state & GLSTATE_NO_COLORWRITE ) { qglShadeModel( GL_FLAT ); qglColorMask( GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE ); } else { qglShadeModel( GL_SMOOTH ); qglColorMask( GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE ); } } if( diff & GLSTATE_DEPTHFUNC_EQ ) { if( state & GLSTATE_DEPTHFUNC_EQ ) qglDepthFunc( GL_EQUAL ); else qglDepthFunc( GL_LEQUAL ); } if( diff & GLSTATE_DEPTHWRITE ) { if( state & GLSTATE_DEPTHWRITE ) qglDepthMask( GL_TRUE ); else qglDepthMask( GL_FALSE ); } if( diff & GLSTATE_NO_DEPTH_TEST ) { if( state & GLSTATE_NO_DEPTH_TEST ) qglDisable( GL_DEPTH_TEST ); else qglEnable( GL_DEPTH_TEST ); } if( diff & GLSTATE_OFFSET_FILL ) { if( state & GLSTATE_OFFSET_FILL ) qglEnable( GL_POLYGON_OFFSET_FILL ); else qglDisable( GL_POLYGON_OFFSET_FILL ); } if( diff & GLSTATE_STENCIL_TEST ) { if( glConfig.stencilEnabled ) { if( state & GLSTATE_STENCIL_TEST ) qglEnable( GL_STENCIL_TEST ); else qglDisable( GL_STENCIL_TEST ); } } rb.gl.state = state; }
/* ** GL_State ** ** This routine is responsible for setting the most commonly changed state ** in Q3. */ void GL_State( unsigned long stateBits ) { unsigned long diff = stateBits ^ glState.glStateBits; if ( !diff ) { return; } // // check depthFunc bits // if ( diff & GLS_DEPTHFUNC_BITS ) { if ( stateBits & GLS_DEPTHFUNC_EQUAL ) { qglDepthFunc( GL_EQUAL ); } else if ( stateBits & GLS_DEPTHFUNC_GREATER) { qglDepthFunc( GL_GREATER ); } else { qglDepthFunc( GL_LEQUAL ); } } // // check blend bits // if ( diff & ( GLS_SRCBLEND_BITS | GLS_DSTBLEND_BITS ) ) { uint32_t oldState = glState.glStateBits & ( GLS_SRCBLEND_BITS | GLS_DSTBLEND_BITS ); uint32_t newState = stateBits & ( GLS_SRCBLEND_BITS | GLS_DSTBLEND_BITS ); uint32_t storedState = glState.storedGlState & ( GLS_SRCBLEND_BITS | GLS_DSTBLEND_BITS ); if (oldState == 0) { qglEnable( GL_BLEND ); } else if (newState == 0) { qglDisable( GL_BLEND ); } if (newState != 0 && storedState != newState) { GLenum srcFactor = GL_ONE, dstFactor = GL_ONE; glState.storedGlState &= ~( GLS_SRCBLEND_BITS | GLS_DSTBLEND_BITS ); glState.storedGlState |= newState; switch ( stateBits & GLS_SRCBLEND_BITS ) { case GLS_SRCBLEND_ZERO: srcFactor = GL_ZERO; break; case GLS_SRCBLEND_ONE: srcFactor = GL_ONE; break; case GLS_SRCBLEND_DST_COLOR: srcFactor = GL_DST_COLOR; break; case GLS_SRCBLEND_ONE_MINUS_DST_COLOR: srcFactor = GL_ONE_MINUS_DST_COLOR; break; case GLS_SRCBLEND_SRC_ALPHA: srcFactor = GL_SRC_ALPHA; break; case GLS_SRCBLEND_ONE_MINUS_SRC_ALPHA: srcFactor = GL_ONE_MINUS_SRC_ALPHA; break; case GLS_SRCBLEND_DST_ALPHA: srcFactor = GL_DST_ALPHA; break; case GLS_SRCBLEND_ONE_MINUS_DST_ALPHA: srcFactor = GL_ONE_MINUS_DST_ALPHA; break; case GLS_SRCBLEND_ALPHA_SATURATE: srcFactor = GL_SRC_ALPHA_SATURATE; break; default: ri.Error( ERR_DROP, "GL_State: invalid src blend state bits" ); break; } switch ( stateBits & GLS_DSTBLEND_BITS ) { case GLS_DSTBLEND_ZERO: dstFactor = GL_ZERO; break; case GLS_DSTBLEND_ONE: dstFactor = GL_ONE; break; case GLS_DSTBLEND_SRC_COLOR: dstFactor = GL_SRC_COLOR; break; case GLS_DSTBLEND_ONE_MINUS_SRC_COLOR: dstFactor = GL_ONE_MINUS_SRC_COLOR; break; case GLS_DSTBLEND_SRC_ALPHA: dstFactor = GL_SRC_ALPHA; break; case GLS_DSTBLEND_ONE_MINUS_SRC_ALPHA: dstFactor = GL_ONE_MINUS_SRC_ALPHA; break; case GLS_DSTBLEND_DST_ALPHA: dstFactor = GL_DST_ALPHA; break; case GLS_DSTBLEND_ONE_MINUS_DST_ALPHA: dstFactor = GL_ONE_MINUS_DST_ALPHA; break; default: ri.Error( ERR_DROP, "GL_State: invalid dst blend state bits" ); break; } qglBlendFunc( srcFactor, dstFactor ); } } // // check depthmask // if ( diff & GLS_DEPTHMASK_TRUE ) { if ( stateBits & GLS_DEPTHMASK_TRUE ) { qglDepthMask( GL_TRUE ); } else { qglDepthMask( GL_FALSE ); } } // // fill/line mode // if ( diff & GLS_POLYMODE_LINE ) { if ( stateBits & GLS_POLYMODE_LINE ) { qglPolygonMode( GL_FRONT_AND_BACK, GL_LINE ); } else { qglPolygonMode( GL_FRONT_AND_BACK, GL_FILL ); } } // // depthtest // if ( diff & GLS_DEPTHTEST_DISABLE ) { if ( stateBits & GLS_DEPTHTEST_DISABLE ) { qglDisable( GL_DEPTH_TEST ); } else { qglEnable( GL_DEPTH_TEST ); } } // // alpha test // if ( diff & GLS_ATEST_BITS ) { uint32_t oldState = glState.glStateBits & GLS_ATEST_BITS; uint32_t newState = stateBits & GLS_ATEST_BITS; uint32_t storedState = glState.storedGlState & GLS_ATEST_BITS; if (oldState == 0) { qglEnable(GL_ALPHA_TEST); } else if (newState == 0) { qglDisable(GL_ALPHA_TEST); } if (newState != 0 && storedState != newState) { glState.storedGlState &= ~GLS_ATEST_BITS; glState.storedGlState |= newState; switch ( newState ) { case GLS_ATEST_GT_0: qglAlphaFunc( GL_GREATER, 0.0f ); break; case GLS_ATEST_LT_80: qglAlphaFunc( GL_LESS, 0.5f ); break; case GLS_ATEST_GE_80: qglAlphaFunc( GL_GEQUAL, 0.5f ); break; } } } glState.glStateBits = stateBits; }
void Sky_DepthClipEnd2 (void) { // restore the correct depth func qglDepthFunc (GL_LEQUAL); qglDepthMask (1); }
void Draw_ScaledPic(int x, int y, float scale, float alpha, char *pic, float red, float green, float blue, qboolean fixcoords, qboolean repscale) { float xoff, yoff; image_t *gl; gl = Draw_FindPic(pic); if (!gl) { ri.Con_Printf(PRINT_ALL, "Can't find pic: %s\n", pic); return; } if (scrap_dirty) Scrap_Upload(); if (((gl_config.renderer == GL_RENDERER_MCD) || (gl_config.renderer & GL_RENDERER_RENDITION)) && !gl->has_alpha) qglDisable(GL_ALPHA_TEST); /* add alpha support */ { qglDisable(GL_ALPHA_TEST); qglBindTexture(GL_TEXTURE_2D, gl->texnum); GL_TexEnv(GL_MODULATE); qglColor4f(red, green, blue, alpha); qglEnable(GL_BLEND); qglDepthMask(false); } /* NOTE: replace this with shaders as soon as they are supported */ if (repscale) scale *= gl->replace_scale; /* scale down if replacing a pcx image */ if (fixcoords) { /* Knightmare- whether to adjust coordinates for scaling */ xoff = (gl->width * scale - gl->width) / 2; yoff = (gl->height * scale - gl->height) / 2; GL_Bind(gl->texnum); qglBegin(GL_QUADS); qglTexCoord2f(gl->sl, gl->tl); qglVertex2f(x - xoff, y - yoff); qglTexCoord2f(gl->sh, gl->tl); qglVertex2f(x + gl->width + xoff, y - yoff); qglTexCoord2f(gl->sh, gl->th); qglVertex2f(x + gl->width + xoff, y + gl->height + yoff); qglTexCoord2f(gl->sl, gl->th); qglVertex2f(x - xoff, y + gl->height + yoff); qglEnd(); } else { xoff = gl->width * scale - gl->width; yoff = gl->height * scale - gl->height; GL_Bind(gl->texnum); qglBegin(GL_QUADS); qglTexCoord2f(gl->sl, gl->tl); qglVertex2f(x, y); qglTexCoord2f(gl->sh, gl->tl); qglVertex2f(x + gl->width + xoff, y); qglTexCoord2f(gl->sh, gl->th); qglVertex2f(x + gl->width + xoff, y + gl->height + yoff); qglTexCoord2f(gl->sl, gl->th); qglVertex2f(x, y + gl->height + yoff); qglEnd(); } /* add alpha support */ { qglDepthMask(true); GL_TexEnv(GL_REPLACE); qglDisable(GL_BLEND); qglColor4f(1, 1, 1, 1); qglEnable(GL_ALPHA_TEST); } if (((gl_config.renderer == GL_RENDERER_MCD) || (gl_config.renderer & GL_RENDERER_RENDITION)) && !gl->has_alpha) qglEnable(GL_ALPHA_TEST); }
/* ============== RenderBumpFlat_f ============== */ void RenderBumpFlat_f( const idCmdArgs &args ) { int width, height; idStr source; int i; idBounds bounds; srfTriangles_t *mesh; // update the screen as we print common->SetRefreshOnPrint( true ); width = height = 256; // check options for ( i = 1 ; i < args.Argc() - 1; i++ ) { const char *s; s = args.Argv( i ); if ( s[0] == '-' ) { i++; s = args.Argv( i ); } if ( !idStr::Icmp( s, "size" ) ) { if ( i + 2 >= args.Argc() ) { i = args.Argc(); break; } width = atoi( args.Argv( i + 1 ) ); height = atoi( args.Argv( i + 2 ) ); i += 2; } else { common->Printf( "WARNING: Unknown option \"%s\"\n", s ); break; } } if ( i != ( args.Argc() - 1 ) ) { common->Error( "usage: renderBumpFlat [-size width height] asefile" ); return; } common->Printf( "Final image size: %i, %i\n", width, height ); // load the source in "fastload" mode, because we don't // need tangent and shadow information source = args.Argv( i ); idRenderModel *highPolyModel = renderModelManager->AllocModel(); highPolyModel->PartialInitFromFile( source ); if ( highPolyModel->IsDefaultModel() ) { common->Error( "failed to load %s", source.c_str() ); } // combine the high poly model into a single polyset if ( highPolyModel->NumSurfaces() != 1 ) { highPolyModel = CombineModelSurfaces( highPolyModel ); } // create normals if not present in file const modelSurface_t *surf = highPolyModel->Surface( 0 ); mesh = surf->geometry; // bound the entire file R_BoundTriSurf( mesh ); bounds = mesh->bounds; SaveWindow(); ResizeWindow( width, height ); // for small images, the viewport may be less than the minimum window qglViewport( 0, 0, width, height ); qglEnable( GL_CULL_FACE ); qglCullFace( GL_FRONT ); qglDisable( GL_STENCIL_TEST ); qglDisable( GL_SCISSOR_TEST ); qglDisable( GL_ALPHA_TEST ); qglDisable( GL_BLEND ); qglEnable( GL_DEPTH_TEST ); qglDisable( GL_TEXTURE_2D ); qglDepthMask( GL_TRUE ); qglDepthFunc( GL_LEQUAL ); qglColor3f( 1, 1, 1 ); qglMatrixMode( GL_PROJECTION ); qglLoadIdentity(); qglOrtho( bounds[0][0], bounds[1][0], bounds[0][2], bounds[1][2], -( bounds[0][1] - 1 ), -( bounds[1][1] + 1 ) ); qglMatrixMode( GL_MODELVIEW ); qglLoadIdentity(); // flat maps are automatically anti-aliased idStr filename; int j, k, c; byte *buffer; int *sumBuffer, *colorSumBuffer; bool flat; int sample; sumBuffer = (int *)Mem_Alloc( width * height * 4 * 4 ); memset( sumBuffer, 0, width * height * 4 * 4 ); buffer = (byte *)Mem_Alloc( width * height * 4 ); colorSumBuffer = (int *)Mem_Alloc( width * height * 4 * 4 ); memset( sumBuffer, 0, width * height * 4 * 4 ); flat = false; //flat = true; for ( sample = 0 ; sample < 16 ; sample++ ) { float xOff, yOff; xOff = ( ( sample & 3 ) / 4.0 ) * ( bounds[1][0] - bounds[0][0] ) / width; yOff = ( ( sample / 4 ) / 4.0 ) * ( bounds[1][2] - bounds[0][2] ) / height; for ( int colorPass = 0 ; colorPass < 2 ; colorPass++ ) { qglClearColor(0.5,0.5,0.5,0); qglClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); qglBegin( GL_TRIANGLES ); for ( i = 0 ; i < highPolyModel->NumSurfaces() ; i++ ) { const modelSurface_t *surf = highPolyModel->Surface( i ); mesh = surf->geometry; if ( colorPass ) { // just render the surface color for artist visualization for ( j = 0 ; j < mesh->numIndexes ; j+=3 ) { for ( k = 0 ; k < 3 ; k++ ) { int v; float *a; v = mesh->indexes[j+k]; qglColor3ubv( mesh->verts[v].color ); a = mesh->verts[v].xyz.ToFloatPtr(); qglVertex3f( a[0] + xOff, a[2] + yOff, a[1] ); } } } else { // render as normal map // we can either flat shade from the plane, // or smooth shade from the vertex normals for ( j = 0 ; j < mesh->numIndexes ; j+=3 ) { if ( flat ) { idPlane plane; idVec3 *a, *b, *c; int v1, v2, v3; v1 = mesh->indexes[j+0]; v2 = mesh->indexes[j+1]; v3 = mesh->indexes[j+2]; a = &mesh->verts[ v1 ].xyz; b = &mesh->verts[ v2 ].xyz; c = &mesh->verts[ v3 ].xyz; plane.FromPoints( *a, *b, *c ); // NULLNORMAL is used by the artists to force an area to reflect no // light at all if ( surf->shader->GetSurfaceFlags() & SURF_NULLNORMAL ) { qglColor3f( 0.5, 0.5, 0.5 ); } else { qglColor3f( 0.5 + 0.5*plane[0], 0.5 - 0.5*plane[2], 0.5 - 0.5*plane[1] ); } qglVertex3f( (*a)[0] + xOff, (*a)[2] + yOff, (*a)[1] ); qglVertex3f( (*b)[0] + xOff, (*b)[2] + yOff, (*b)[1] ); qglVertex3f( (*c)[0] + xOff, (*c)[2] + yOff, (*c)[1] ); } else { for ( k = 0 ; k < 3 ; k++ ) { int v; float *n; float *a; v = mesh->indexes[j+k]; n = mesh->verts[v].normal.ToFloatPtr(); // NULLNORMAL is used by the artists to force an area to reflect no // light at all if ( surf->shader->GetSurfaceFlags() & SURF_NULLNORMAL ) { qglColor3f( 0.5, 0.5, 0.5 ); } else { // we are going to flip the normal Z direction qglColor3f( 0.5 + 0.5*n[0], 0.5 - 0.5*n[2], 0.5 - 0.5*n[1] ); } a = mesh->verts[v].xyz.ToFloatPtr(); qglVertex3f( a[0] + xOff, a[2] + yOff, a[1] ); } } } } } qglEnd(); qglFlush(); GLimp_SwapBuffers(); qglReadPixels( 0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, buffer ); c = width * height; if ( colorPass ) { // add to the sum buffer for ( i = 0 ; i < c ; i++ ) { colorSumBuffer[i*4+0] += buffer[i*4+0]; colorSumBuffer[i*4+1] += buffer[i*4+1]; colorSumBuffer[i*4+2] += buffer[i*4+2]; colorSumBuffer[i*4+3] += buffer[i*4+3]; } } else { // normalize for ( i = 0 ; i < c ; i++ ) { idVec3 v; v[0] = ( buffer[i*4+0] - 128 ) / 127.0; v[1] = ( buffer[i*4+1] - 128 ) / 127.0; v[2] = ( buffer[i*4+2] - 128 ) / 127.0; v.Normalize(); buffer[i*4+0] = 128 + 127 * v[0]; buffer[i*4+1] = 128 + 127 * v[1]; buffer[i*4+2] = 128 + 127 * v[2]; } // outline into non-drawn areas for ( i = 0 ; i < 8 ; i++ ) { OutlineNormalMap( buffer, width, height, 128, 128, 128 ); } // add to the sum buffer for ( i = 0 ; i < c ; i++ ) { sumBuffer[i*4+0] += buffer[i*4+0]; sumBuffer[i*4+1] += buffer[i*4+1]; sumBuffer[i*4+2] += buffer[i*4+2]; sumBuffer[i*4+3] += buffer[i*4+3]; } } } } c = width * height; // save out the color map for ( i = 0 ; i < c ; i++ ) { buffer[i*4+0] = colorSumBuffer[i*4+0] / 16; buffer[i*4+1] = colorSumBuffer[i*4+1] / 16; buffer[i*4+2] = colorSumBuffer[i*4+2] / 16; buffer[i*4+3] = colorSumBuffer[i*4+3] / 16; } filename = source; filename.StripFileExtension(); filename.Append( "_color.tga" ); R_VerticalFlip( buffer, width, height ); R_WriteTGA( filename, buffer, width, height ); // save out the local map // scale the sum buffer back down to the sample buffer // we allow this to denormalize for ( i = 0 ; i < c ; i++ ) { buffer[i*4+0] = sumBuffer[i*4+0] / 16; buffer[i*4+1] = sumBuffer[i*4+1] / 16; buffer[i*4+2] = sumBuffer[i*4+2] / 16; buffer[i*4+3] = sumBuffer[i*4+3] / 16; } filename = source; filename.StripFileExtension(); filename.Append( "_local.tga" ); common->Printf( "writing %s (%i,%i)\n", filename.c_str(), width, height ); R_VerticalFlip( buffer, width, height ); R_WriteTGA( filename, buffer, width, height ); // free the model renderModelManager->FreeModel( highPolyModel ); // free our work buffer Mem_Free( buffer ); Mem_Free( sumBuffer ); Mem_Free( colorSumBuffer ); RestoreWindow(); // stop updating the screen as we print common->SetRefreshOnPrint( false ); common->Error( "Completed." ); }
/* ==================== GL_State This routine is responsible for setting the most commonly changed state ==================== */ void GL_State( int stateBits ) { int diff; if ( !r_useStateCaching.GetBool() || backEnd.glState.forceGlState ) { // make sure everything is set all the time, so we // can see if our delta checking is screwing up diff = -1; backEnd.glState.forceGlState = false; } else { diff = stateBits ^ backEnd.glState.glStateBits; if ( !diff ) { return; } } // // check depthFunc bits // if ( diff & ( GLS_DEPTHFUNC_EQUAL | GLS_DEPTHFUNC_LESS | GLS_DEPTHFUNC_ALWAYS ) ) { if ( stateBits & GLS_DEPTHFUNC_EQUAL ) { qglDepthFunc( GL_EQUAL ); } else if ( stateBits & GLS_DEPTHFUNC_ALWAYS ) { qglDepthFunc( GL_ALWAYS ); } else { qglDepthFunc( GL_LEQUAL ); } } // // check blend bits // if ( diff & ( GLS_SRCBLEND_BITS | GLS_DSTBLEND_BITS ) ) { GLenum srcFactor, dstFactor; switch ( stateBits & GLS_SRCBLEND_BITS ) { case GLS_SRCBLEND_ZERO: srcFactor = GL_ZERO; break; case GLS_SRCBLEND_ONE: srcFactor = GL_ONE; break; case GLS_SRCBLEND_DST_COLOR: srcFactor = GL_DST_COLOR; break; case GLS_SRCBLEND_ONE_MINUS_DST_COLOR: srcFactor = GL_ONE_MINUS_DST_COLOR; break; case GLS_SRCBLEND_SRC_ALPHA: srcFactor = GL_SRC_ALPHA; break; case GLS_SRCBLEND_ONE_MINUS_SRC_ALPHA: srcFactor = GL_ONE_MINUS_SRC_ALPHA; break; case GLS_SRCBLEND_DST_ALPHA: srcFactor = GL_DST_ALPHA; break; case GLS_SRCBLEND_ONE_MINUS_DST_ALPHA: srcFactor = GL_ONE_MINUS_DST_ALPHA; break; case GLS_SRCBLEND_ALPHA_SATURATE: srcFactor = GL_SRC_ALPHA_SATURATE; break; default: srcFactor = GL_ONE; // to get warning to shut up common->Error( "GL_State: invalid src blend state bits\n" ); break; } switch ( stateBits & GLS_DSTBLEND_BITS ) { case GLS_DSTBLEND_ZERO: dstFactor = GL_ZERO; break; case GLS_DSTBLEND_ONE: dstFactor = GL_ONE; break; case GLS_DSTBLEND_SRC_COLOR: dstFactor = GL_SRC_COLOR; break; case GLS_DSTBLEND_ONE_MINUS_SRC_COLOR: dstFactor = GL_ONE_MINUS_SRC_COLOR; break; case GLS_DSTBLEND_SRC_ALPHA: dstFactor = GL_SRC_ALPHA; break; case GLS_DSTBLEND_ONE_MINUS_SRC_ALPHA: dstFactor = GL_ONE_MINUS_SRC_ALPHA; break; case GLS_DSTBLEND_DST_ALPHA: dstFactor = GL_DST_ALPHA; break; case GLS_DSTBLEND_ONE_MINUS_DST_ALPHA: dstFactor = GL_ONE_MINUS_DST_ALPHA; break; default: dstFactor = GL_ONE; // to get warning to shut up common->Error( "GL_State: invalid dst blend state bits\n" ); break; } qglBlendFunc( srcFactor, dstFactor ); } // // check depthmask // if ( diff & GLS_DEPTHMASK ) { if ( stateBits & GLS_DEPTHMASK ) { qglDepthMask( GL_FALSE ); } else { qglDepthMask( GL_TRUE ); } } // // check colormask // if ( diff & (GLS_REDMASK|GLS_GREENMASK|GLS_BLUEMASK|GLS_ALPHAMASK) ) { GLboolean r, g, b, a; r = ( stateBits & GLS_REDMASK ) ? 0 : 1; g = ( stateBits & GLS_GREENMASK ) ? 0 : 1; b = ( stateBits & GLS_BLUEMASK ) ? 0 : 1; a = ( stateBits & GLS_ALPHAMASK ) ? 0 : 1; qglColorMask( r, g, b, a ); } // // fill/line mode // if ( diff & GLS_POLYMODE_LINE ) { if ( stateBits & GLS_POLYMODE_LINE ) { qglPolygonMode( GL_FRONT_AND_BACK, GL_LINE ); } else { qglPolygonMode( GL_FRONT_AND_BACK, GL_FILL ); } } // // alpha test // if ( diff & GLS_ATEST_BITS ) { switch ( stateBits & GLS_ATEST_BITS ) { case 0: qglDisable( GL_ALPHA_TEST ); break; case GLS_ATEST_EQ_255: qglEnable( GL_ALPHA_TEST ); qglAlphaFunc( GL_EQUAL, 1 ); break; case GLS_ATEST_LT_128: qglEnable( GL_ALPHA_TEST ); qglAlphaFunc( GL_LESS, 0.5 ); break; case GLS_ATEST_GE_128: qglEnable( GL_ALPHA_TEST ); qglAlphaFunc( GL_GEQUAL, 0.5 ); break; default: assert( 0 ); break; } } backEnd.glState.glStateBits = stateBits; }
/* ** GL_State ** ** This routine is responsible for setting the most commonly changed state ** in Q3. */ void GL_State( unsigned long stateBits ) { unsigned long diff = stateBits ^ glState.glStateBits; if ( !diff ) { return; } // // check depthFunc bits // if ( diff & GLS_DEPTHFUNC_EQUAL ) { if ( stateBits & GLS_DEPTHFUNC_EQUAL ) { qglDepthFunc( GL_EQUAL ); } else { qglDepthFunc( GL_LEQUAL ); } } // // check blend bits // if ( diff & ( GLS_SRCBLEND_BITS | GLS_DSTBLEND_BITS ) ) { GLenum srcFactor, dstFactor; if ( stateBits & ( GLS_SRCBLEND_BITS | GLS_DSTBLEND_BITS ) ) { switch ( stateBits & GLS_SRCBLEND_BITS ) { case GLS_SRCBLEND_ZERO: srcFactor = GL_ZERO; break; case GLS_SRCBLEND_ONE: srcFactor = GL_ONE; break; case GLS_SRCBLEND_DST_COLOR: srcFactor = GL_DST_COLOR; break; case GLS_SRCBLEND_ONE_MINUS_DST_COLOR: srcFactor = GL_ONE_MINUS_DST_COLOR; break; case GLS_SRCBLEND_SRC_ALPHA: srcFactor = GL_SRC_ALPHA; break; case GLS_SRCBLEND_ONE_MINUS_SRC_ALPHA: srcFactor = GL_ONE_MINUS_SRC_ALPHA; break; case GLS_SRCBLEND_DST_ALPHA: srcFactor = GL_DST_ALPHA; break; case GLS_SRCBLEND_ONE_MINUS_DST_ALPHA: srcFactor = GL_ONE_MINUS_DST_ALPHA; break; case GLS_SRCBLEND_ALPHA_SATURATE: srcFactor = GL_SRC_ALPHA_SATURATE; break; default: srcFactor = GL_ONE; // to get warning to shut up ri.Error( ERR_DROP, "GL_State: invalid src blend state bits\n" ); break; } switch ( stateBits & GLS_DSTBLEND_BITS ) { case GLS_DSTBLEND_ZERO: dstFactor = GL_ZERO; break; case GLS_DSTBLEND_ONE: dstFactor = GL_ONE; break; case GLS_DSTBLEND_SRC_COLOR: dstFactor = GL_SRC_COLOR; break; case GLS_DSTBLEND_ONE_MINUS_SRC_COLOR: dstFactor = GL_ONE_MINUS_SRC_COLOR; break; case GLS_DSTBLEND_SRC_ALPHA: dstFactor = GL_SRC_ALPHA; break; case GLS_DSTBLEND_ONE_MINUS_SRC_ALPHA: dstFactor = GL_ONE_MINUS_SRC_ALPHA; break; case GLS_DSTBLEND_DST_ALPHA: dstFactor = GL_DST_ALPHA; break; case GLS_DSTBLEND_ONE_MINUS_DST_ALPHA: dstFactor = GL_ONE_MINUS_DST_ALPHA; break; default: dstFactor = GL_ONE; // to get warning to shut up ri.Error( ERR_DROP, "GL_State: invalid dst blend state bits\n" ); break; } qglEnable( GL_BLEND ); qglBlendFunc( srcFactor, dstFactor ); } else { qglDisable( GL_BLEND ); } } // // check depthmask // if ( diff & GLS_DEPTHMASK_TRUE ) { if ( stateBits & GLS_DEPTHMASK_TRUE ) { qglDepthMask( GL_TRUE ); } else { qglDepthMask( GL_FALSE ); } } // // fill/line mode // if ( diff & GLS_POLYMODE_LINE ) { if ( stateBits & GLS_POLYMODE_LINE ) { qglPolygonMode( GL_FRONT_AND_BACK, GL_LINE ); } else { qglPolygonMode( GL_FRONT_AND_BACK, GL_FILL ); } } // // depthtest // if ( diff & GLS_DEPTHTEST_DISABLE ) { if ( stateBits & GLS_DEPTHTEST_DISABLE ) { qglDisable( GL_DEPTH_TEST ); } else { qglEnable( GL_DEPTH_TEST ); } } // // alpha test // if ( diff & GLS_ATEST_BITS ) { switch ( stateBits & GLS_ATEST_BITS ) { case 0: qglDisable( GL_ALPHA_TEST ); break; case GLS_ATEST_GT_0: qglEnable( GL_ALPHA_TEST ); qglAlphaFunc( GL_GREATER, 0.0f ); break; case GLS_ATEST_LT_80: qglEnable( GL_ALPHA_TEST ); qglAlphaFunc( GL_LESS, 0.5f ); break; case GLS_ATEST_GE_80: qglEnable( GL_ALPHA_TEST ); qglAlphaFunc( GL_GEQUAL, 0.5f ); break; default: assert( 0 ); break; } } glState.glStateBits = stateBits; }
/* ** 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); } }
/* ================== GL_SetDefaultState ================== */ void GL_SetDefaultState (){ int i; QGL_LogPrintf("---------- GL_SetDefaultState ----------\n"); // Reset the state manager glState.projectionMatrixIdentity = true; glState.modelviewMatrixIdentity = true; for (i = 0; i < MAX_TEXTURE_UNITS; i++) glState.textureMatrixIdentity[i] = true; for (i = 0; i < MAX_TEXTURE_UNITS; i++) glState.texture[i] = NULL; glState.program = NULL; glState.indexBuffer = NULL; glState.vertexBuffer = NULL; glState.viewportX = 0; glState.viewportY = 0; glState.viewportWidth = glConfig.videoWidth; glState.viewportHeight = glConfig.videoHeight; glState.scissorX = 0; glState.scissorY = 0; glState.scissorWidth = glConfig.videoWidth; glState.scissorHeight = glConfig.videoHeight; glState.depthBoundsMin = 0.0f; glState.depthBoundsMax = 1.0f; glState.texUnit = 0; for (i = 0; i < MAX_TEXTURE_UNITS; i++){ glState.texTarget[i] = 0; glState.texEnv[i] = GL_MODULATE; glState.texGen[i][0] = GL_OBJECT_LINEAR; glState.texGen[i][1] = GL_OBJECT_LINEAR; glState.texGen[i][2] = GL_OBJECT_LINEAR; glState.texGen[i][3] = GL_OBJECT_LINEAR; } glState.cullFace = false; glState.polygonOffsetFill = false; glState.polygonOffsetLine = false; glState.blend = false; glState.alphaTest = false; glState.depthTest = false; glState.stencilTest = false; for (i = 0; i < MAX_TEXTURE_UNITS; i++){ glState.textureGen[i][0] = false; glState.textureGen[i][1] = false; glState.textureGen[i][2] = false; glState.textureGen[i][3] = false; } glState.cullMode = GL_FRONT; glState.polygonMode = GL_FILL; glState.polygonOffsetFactor = 0.0f; glState.polygonOffsetUnits = 0.0f; glState.blendSrc = GL_ONE; glState.blendDst = GL_ZERO; glState.blendMode = GL_FUNC_ADD; glState.alphaFunc = GL_GREATER; glState.alphaFuncRef = 0.0f; glState.depthFunc = GL_LEQUAL; glState.stencilFunc[0] = GL_ALWAYS; glState.stencilFunc[1] = GL_ALWAYS; glState.stencilFuncRef[0] = 0; glState.stencilFuncRef[1] = 0; glState.stencilFuncMask[0] = 255; glState.stencilFuncMask[1] = 255; glState.stencilOpFail[0] = GL_KEEP; glState.stencilOpFail[1] = GL_KEEP; glState.stencilOpZFail[0] = GL_KEEP; glState.stencilOpZFail[1] = GL_KEEP; glState.stencilOpZPass[0] = GL_KEEP; glState.stencilOpZPass[1] = GL_KEEP; glState.depthMin = 0.0f; glState.depthMax = 1.0f; glState.colorMask[0] = GL_TRUE; glState.colorMask[1] = GL_TRUE; glState.colorMask[2] = GL_TRUE; glState.colorMask[3] = GL_TRUE; glState.depthMask = GL_TRUE; glState.stencilMask[0] = 255; glState.stencilMask[1] = 255; // Set default state qglMatrixMode(GL_PROJECTION); qglLoadIdentity(); qglMatrixMode(GL_MODELVIEW); qglLoadIdentity(); for (i = MAX_TEXTURE_UNITS - 1; i >= 0; i--){ if (i >= glConfig.maxTextureImageUnits) continue; if (i >= glConfig.maxTextureUnits){ qglActiveTexture(GL_TEXTURE0 + i); qglBindTexture(GL_TEXTURE_2D, 0); qglBindTexture(GL_TEXTURE_3D, 0); qglBindTexture(GL_TEXTURE_CUBE_MAP, 0); qglBindTexture(GL_TEXTURE_2D_ARRAY, 0); continue; } qglActiveTexture(GL_TEXTURE0 + i); qglMatrixMode(GL_TEXTURE); qglLoadIdentity(); qglDisable(GL_TEXTURE_2D); qglDisable(GL_TEXTURE_3D); qglDisable(GL_TEXTURE_CUBE_MAP); qglDisable(GL_TEXTURE_2D_ARRAY); qglBindTexture(GL_TEXTURE_2D, 0); qglBindTexture(GL_TEXTURE_3D, 0); qglBindTexture(GL_TEXTURE_CUBE_MAP, 0); qglBindTexture(GL_TEXTURE_2D_ARRAY, 0); qglTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); qglDisable(GL_TEXTURE_GEN_S); qglDisable(GL_TEXTURE_GEN_T); qglDisable(GL_TEXTURE_GEN_R); qglDisable(GL_TEXTURE_GEN_Q); qglTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR); qglTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR); qglTexGeni(GL_R, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR); qglTexGeni(GL_Q, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR); } qglDisable(GL_TEXTURE_CUBE_MAP_SEAMLESS); qglUseProgram(0); qglBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); qglBindBuffer(GL_ARRAY_BUFFER, 0); qglViewport(0, 0, glConfig.videoWidth, glConfig.videoHeight); qglEnable(GL_SCISSOR_TEST); qglScissor(0, 0, glConfig.videoWidth, glConfig.videoHeight); qglEnable(GL_DEPTH_BOUNDS_TEST_EXT); qglDepthBoundsEXT(0.0f, 1.0f); qglFrontFace(GL_CCW); qglShadeModel(GL_SMOOTH); qglPolygonMode(GL_FRONT_AND_BACK, GL_FILL); qglDisable(GL_CULL_FACE); qglCullFace(GL_FRONT); qglDisable(GL_POLYGON_OFFSET_FILL); qglDisable(GL_POLYGON_OFFSET_LINE); qglPolygonOffset(0.0f, 0.0f); qglDisable(GL_BLEND); qglBlendFunc(GL_ONE, GL_ZERO); qglBlendEquation(GL_FUNC_ADD); qglDisable(GL_ALPHA_TEST); qglAlphaFunc(GL_GREATER, 0.0f); qglDisable(GL_DEPTH_TEST); qglDepthFunc(GL_LEQUAL); qglDisable(GL_STENCIL_TEST); qglStencilFunc(GL_ALWAYS, 128, 255); qglStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); qglDepthRange(0.0f, 1.0f); qglColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); qglDepthMask(GL_TRUE); qglStencilMask(255); qglDisable(GL_DEPTH_CLAMP); qglDisable(GL_CLIP_PLANE0); if (glConfig.multiSamples > 1){ qglDisable(GL_MULTISAMPLE); qglDisable(GL_SAMPLE_ALPHA_TO_COVERAGE); } qglClearColor(0.0f, 0.0f, 0.0f, 1.0f); qglClearDepth(1.0f); qglClearStencil(128); qglEnableClientState(GL_VERTEX_ARRAY); qglDisableVertexAttribArray(GL_ATTRIB_NORMAL); qglDisableVertexAttribArray(GL_ATTRIB_TANGENT1); qglDisableVertexAttribArray(GL_ATTRIB_TANGENT2); qglDisableVertexAttribArray(GL_ATTRIB_TEXCOORD); qglDisableVertexAttribArray(GL_ATTRIB_COLOR); QGL_LogPrintf("--------------------\n"); }