|
Mailto: vic@captured.com
For some odd reason
Quake2 has very dark textures. If you load a map with console variables
"intensity" and "gl_modulate" set to "1" you
will hardly see anything! Setting "intensity" and
"gl_modulate" to values higher than "1" will surely
brighten textures by scaling the colour of each texel, making textures
("intensity") and lightmaps ("gl_modulate") look crappy.
This tutorial will show how to use advances of modern video cards, which can
brighten textures using OpenGL extensions, such as GL_ARB_texture_env_combine.
First of all,
we need to declare some variables. Open qgl.h and find line
extern int GL_TEXTURE0, GL_TEXTURE1; |
|
Add the
following below this line:
// Vic - begin #ifndef GL_EXT_texture_env_combine #define GL_COMBINE_EXT 0x8570 #define GL_COMBINE_RGB_EXT 0x8571 #define GL_COMBINE_ALPHA_EXT 0x8572 #define GL_RGB_SCALE_EXT 0x8573 #define GL_ADD_SIGNED_EXT 0x8574 #define GL_INTERPOLATE_EXT 0x8575 #define GL_CONSTANT_EXT 0x8576 #define GL_PRIMARY_COLOR_EXT 0x8577 #define GL_PREVIOUS_EXT 0x8578 #define GL_SOURCE0_RGB_EXT 0x8580 #define GL_SOURCE1_RGB_EXT 0x8581 #define GL_SOURCE2_RGB_EXT 0x8582 #define GL_SOURCE3_RGB_EXT 0x8583 #define GL_SOURCE4_RGB_EXT 0x8584 #define GL_SOURCE5_RGB_EXT 0x8585 #define GL_SOURCE6_RGB_EXT 0x8586 #define GL_SOURCE7_RGB_EXT 0x8587 #define GL_SOURCE0_ALPHA_EXT 0x8588 #define GL_SOURCE1_ALPHA_EXT 0x8589 #define GL_SOURCE2_ALPHA_EXT 0x858A #define GL_SOURCE3_ALPHA_EXT 0x858B #define GL_SOURCE4_ALPHA_EXT 0x858C #define GL_SOURCE5_ALPHA_EXT 0x858D #define GL_SOURCE6_ALPHA_EXT 0x858E #define GL_SOURCE7_ALPHA_EXT 0x858F #define GL_OPERAND0_RGB_EXT 0x8590 #define GL_OPERAND1_RGB_EXT 0x8591 #define GL_OPERAND2_RGB_EXT 0x8592 #define GL_OPERAND3_RGB_EXT 0x8593 #define GL_OPERAND4_RGB_EXT 0x8594 #define GL_OPERAND5_RGB_EXT 0x8595 #define GL_OPERAND6_RGB_EXT 0x8596 #define GL_OPERAND7_RGB_EXT 0x8597 #define GL_OPERAND0_ALPHA_EXT 0x8598 #define GL_OPERAND1_ALPHA_EXT 0x8599 #define GL_OPERAND2_ALPHA_EXT 0x859A #define GL_OPERAND3_ALPHA_EXT 0x859B #define GL_OPERAND4_ALPHA_EXT 0x859C #define GL_OPERAND5_ALPHA_EXT 0x859D #define GL_OPERAND6_ALPHA_EXT 0x859E #define GL_OPERAND7_ALPHA_EXT 0x859F #endif // Vic - end |
|
Now, we need to
declare console variables, which will control our overbright rendering.
Open gl_local.g and find line:
extern cvar_t *r_lightlevel; // FIXME: This is a HACK to get the client's light level |
|
and add after
it:
// Vic - begin extern cvar_t *r_overbrightbits; // Vic - end |
|
Scroll down a
bit and stop at the following line:
extern cvar_t *gl_ext_compiled_vertex_array; |
|
Insert this
code after it:
// Vic - begin extern cvar_t *gl_ext_mtexcombine; // Vic - end |
|
And finally,
look for the declaration of glconfig_t structure nearly at the bottom of
gl_local.h and add the following line after the declaration of
glconfig_t-member 'allow_cds':
// Vic - begin qboolean mtexcombine; // Vic - end |
|
We're done
with gl_local.h!
Now, we must
create our console variables. Open gl_rmain.c and find line:
cvar_t *r_lightlevel; // FIXME: This is a HACK to get the client's light level |
|
Insert the
following after it:
// Vic - begin cvar_t *r_overbrightbits; // Vic - end |
|
Do the same
with the line:
cvar_t *gl_ext_compiled_vertex_array; |
|
and block:
// Vic - begin cvar_t *gl_ext_mtexcombine; // Vic - end |
|
Ok, now find R_Register
function in gl_rmain.c and and the following code somewhere inside it:
// Vic - begin r_overbrightbits = ri.Cvar_Get( "r_overbrightbits", "2", CVAR_ARCHIVE ); // Vic - end |
|
and
// Vic - begin gl_ext_mtexcombine = ri.Cvar_Get( "gl_ext_mtexcombine", "1", CVAR_ARCHIVE ); // Vic - end |
|
Now, it's time
to explain what each new console variable will do. gl_ext_mtexcombine will
indicate if we want to use multitexture combining extensions. r_overbrightbits
will control the brightness.
We need to
tell our engine that it can use multitexture combining if it is present in
the list of extensions and is enabled by user. Find function R_Init in
gl_rmain.c and find lines:
else { ri.Con_Printf( PRINT_ALL, "...GL_SGIS_multitexture not found\n" ); } |
|
Insert the
following after it:
// Vic - begin gl_config.mtexcombine = false; if ( strstr( gl_config.extensions_string, "GL_ARB_texture_env_combine" ) ) { if ( gl_ext_mtexcombine->value ) { Com_Printf( "...using GL_ARB_texture_env_combine\n" ); gl_config.mtexcombine = true; } else { Com_Printf( "...ignoring GL_ARB_texture_env_combine\n" ); } } else { Com_Printf( "...GL_ARB_texture_env_combine not found\n" ); } if ( !gl_config.mtexcombine ) { if ( strstr( gl_config.extensions_string, "GL_EXT_texture_env_combine" ) ) { if ( gl_ext_mtexcombine->value ) { Com_Printf( "...using GL_EXT_texture_env_combine\n" ); gl_config.mtexcombine = true; } else { Com_Printf( "...ignoring GL_EXT_texture_env_combine\n" ); } } else { Com_Printf( "...GL_EXT_texture_env_combine not found\n" ); } } // Vic - end |
|
Now, overbrights
themselves! Open gl_rsurf.c and find function R_DrawBrushModel and scroll
down to the line:
GL_SelectTexture( GL_TEXTURE0); |
|
Replace the
next three lines with the following code:
// Vic - begin if ( !gl_config.mtexcombine ) { GL_TexEnv( GL_REPLACE ); GL_SelectTexture( GL_TEXTURE1); if ( gl_lightmap->value ) GL_TexEnv( GL_REPLACE ); else GL_TexEnv( GL_MODULATE ); } else { GL_TexEnv ( GL_COMBINE_EXT ); qglTexEnvi ( GL_TEXTURE_ENV, GL_COMBINE_RGB_EXT, GL_REPLACE ); qglTexEnvi ( GL_TEXTURE_ENV, GL_SOURCE0_RGB_EXT, GL_TEXTURE ); qglTexEnvi ( GL_TEXTURE_ENV, GL_COMBINE_ALPHA_EXT, GL_REPLACE ); qglTexEnvi ( GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_EXT, GL_TEXTURE ); GL_SelectTexture( GL_TEXTURE1 ); GL_TexEnv ( GL_COMBINE_EXT ); if ( gl_lightmap->value ) { qglTexEnvi ( GL_TEXTURE_ENV, GL_COMBINE_RGB_EXT, GL_REPLACE ); qglTexEnvi ( GL_TEXTURE_ENV, GL_SOURCE0_RGB_EXT, GL_TEXTURE ); qglTexEnvi ( GL_TEXTURE_ENV, GL_COMBINE_ALPHA_EXT, GL_REPLACE ); qglTexEnvi ( GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_EXT, GL_TEXTURE ); } else { qglTexEnvi ( GL_TEXTURE_ENV, GL_COMBINE_RGB_EXT, GL_MODULATE ); qglTexEnvi ( GL_TEXTURE_ENV, GL_SOURCE0_RGB_EXT, GL_TEXTURE ); qglTexEnvi ( GL_TEXTURE_ENV, GL_SOURCE1_RGB_EXT, GL_PREVIOUS_EXT ); qglTexEnvi ( GL_TEXTURE_ENV, GL_COMBINE_ALPHA_EXT, GL_MODULATE ); qglTexEnvi ( GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_EXT, GL_TEXTURE ); qglTexEnvi ( GL_TEXTURE_ENV, GL_SOURCE1_ALPHA_EXT, GL_PREVIOUS_EXT ); } if ( r_overbrightbits->value ) { qglTexEnvi ( GL_TEXTURE_ENV, GL_RGB_SCALE_EXT, r_overbrightbits->value ); } } // Vic - end |
|
Now, we must
do the same thing in R_DrawWorld function. Find line:
GL_SelectTexture( GL_TEXTURE0); |
|
inside of it
and replace these lines after it:
GL_TexEnv( GL_REPLACE ); GL_SelectTexture( GL_TEXTURE1); if ( gl_lightmap->value ) GL_TexEnv( GL_REPLACE ); else GL_TexEnv( GL_MODULATE ); |
|
with the
following code:
// Vic - begin if ( !gl_config.mtexcombine ) { GL_TexEnv( GL_REPLACE ); GL_SelectTexture( GL_TEXTURE1); if ( gl_lightmap->value ) GL_TexEnv( GL_REPLACE ); else GL_TexEnv( GL_MODULATE ); } else { GL_TexEnv ( GL_COMBINE_EXT ); qglTexEnvi ( GL_TEXTURE_ENV, GL_COMBINE_RGB_EXT, GL_REPLACE ); qglTexEnvi ( GL_TEXTURE_ENV, GL_SOURCE0_RGB_EXT, GL_TEXTURE ); qglTexEnvi ( GL_TEXTURE_ENV, GL_COMBINE_ALPHA_EXT, GL_REPLACE ); qglTexEnvi ( GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_EXT, GL_TEXTURE ); GL_SelectTexture( GL_TEXTURE1 ); GL_TexEnv ( GL_COMBINE_EXT ); if ( gl_lightmap->value ) { qglTexEnvi ( GL_TEXTURE_ENV, GL_COMBINE_RGB_EXT, GL_REPLACE ); qglTexEnvi ( GL_TEXTURE_ENV, GL_SOURCE0_RGB_EXT, GL_TEXTURE ); qglTexEnvi ( GL_TEXTURE_ENV, GL_COMBINE_ALPHA_EXT, GL_REPLACE ); qglTexEnvi ( GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_EXT, GL_TEXTURE ); } else { qglTexEnvi ( GL_TEXTURE_ENV, GL_COMBINE_RGB_EXT, GL_MODULATE ); qglTexEnvi ( GL_TEXTURE_ENV, GL_SOURCE0_RGB_EXT, GL_TEXTURE ); qglTexEnvi ( GL_TEXTURE_ENV, GL_SOURCE1_RGB_EXT, GL_PREVIOUS_EXT ); qglTexEnvi ( GL_TEXTURE_ENV, GL_COMBINE_ALPHA_EXT, GL_MODULATE ); qglTexEnvi ( GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_EXT, GL_TEXTURE ); qglTexEnvi ( GL_TEXTURE_ENV, GL_SOURCE1_ALPHA_EXT, GL_PREVIOUS_EXT ); } if ( r_overbrightbits->value ) { qglTexEnvi ( GL_TEXTURE_ENV, GL_RGB_SCALE_EXT, r_overbrightbits->value ); } } // Vic - end |
|
We are almost
done! Now open gl_image.c and find function GL_InitImages. Since we can use
overbrights for rendering, there's no need to scale colour of textures
(setting "intensity" to values higher than 1), making them look
worse.
Comment the line:
intensity = ri.Cvar_Get ("intensity", "2", 0); |
|
inside that
function and insert the following after it:
// Vic - begin if ( gl_config.mtexcombine ) intensity = ri.Cvar_Get ("intensity", "1", 0); else intensity = ri.Cvar_Get ("intensity", "2", 0);// Vic - end |
|
Now save
everything, compile and enjoy new nicer look of the game!
|