Exemple #1
0
PDGL_API void pdglMatrixMode(GLenum mode)
{
	if(pglMatrixMode)
		{ pglMatrixMode(mode); return; }
	pglMatrixMode=pdglGetProcAddress("glMatrixMode");
	pglMatrixMode(mode);
}
Exemple #2
0
/*
===============
R_Set2DMode
===============
*/
void R_Set2DMode( qboolean enable )
{
	if( enable )
	{
		if( glState.in2DMode )
			return;

		// set 2D virtual screen size
		pglScissor( 0, 0, glState.width, glState.height );
		pglViewport( 0, 0, glState.width, glState.height );
		pglMatrixMode( GL_PROJECTION );
		pglLoadIdentity();
		pglOrtho( 0, glState.width, glState.height, 0, -99999, 99999 );
		pglMatrixMode( GL_MODELVIEW );
		pglLoadIdentity();

		GL_Cull( 0 );

		pglDepthMask( GL_FALSE );
		pglDisable( GL_DEPTH_TEST );
		pglColor4f( 1.0f, 1.0f, 1.0f, 1.0f );

		glState.in2DMode = true;
		RI.currententity = NULL;
		RI.currentmodel = NULL;
	}
	else
	{
		pglDepthMask( GL_TRUE );
		pglEnable( GL_DEPTH_TEST );
		pglMatrixMode( GL_MODELVIEW );
		glState.in2DMode = false;
	}
}
Exemple #3
0
/*
=============
R_ShadowPassSetupGL
=============
*/
static void R_ShadowPassSetupGL( const plight_t *pl )
{
	// matrices already computed
	RI.worldviewMatrix = pl->modelviewMatrix;
	RI.projectionMatrix = pl->projectionMatrix;
	RI.worldviewProjectionMatrix = RI.projectionMatrix.Concat( RI.worldviewMatrix );

	GLfloat dest[16];

	// tell engine about worldviewprojection matrix so TriWorldToScreen and TriScreenToWorld
	// will be working properly
	RI.worldviewProjectionMatrix.CopyToArray( dest );
	SET_ENGINE_WORLDVIEW_MATRIX( dest );

	pglScissor( RI.scissor[0], RI.scissor[1], RI.scissor[2], RI.scissor[3] );
	pglViewport( RI.viewport[0], RI.viewport[1], RI.viewport[2], RI.viewport[3] );

	pglMatrixMode( GL_PROJECTION );
	GL_LoadMatrix( RI.projectionMatrix );

	pglMatrixMode( GL_MODELVIEW );
	GL_LoadMatrix( RI.worldviewMatrix );

	GL_Cull( GL_FRONT );

	pglColor4f( 1.0f, 1.0f, 1.0f, 1.0f );
	pglColorMask( GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE );
	pglEnable( GL_POLYGON_OFFSET_FILL );
	pglDisable( GL_TEXTURE_2D );
	pglDepthMask( GL_TRUE );
	pglPolygonOffset( 8, 30 );
	pglEnable( GL_DEPTH_TEST );
	pglDisable( GL_ALPHA_TEST );
	pglDisable( GL_BLEND );
}
/*
=============
R_SetupGL
=============
*/
static void R_SetupGL( void )
{
	if( RI.refdef.waterlevel >= 3 )
	{
		float	f;
		f = sin( cl.time * 0.4f * ( M_PI * 2.7f ));
		RI.refdef.fov_x += f;
		RI.refdef.fov_y -= f;
	}

	R_SetupModelviewMatrix( &RI.refdef, RI.worldviewMatrix );
	R_SetupProjectionMatrix( &RI.refdef, RI.projectionMatrix );
//	if( RI.params & RP_MIRRORVIEW ) RI.projectionMatrix[0][0] = -RI.projectionMatrix[0][0];

	Matrix4x4_Concat( RI.worldviewProjectionMatrix, RI.projectionMatrix, RI.worldviewMatrix );

	pglScissor( RI.scissor[0], RI.scissor[1], RI.scissor[2], RI.scissor[3] );
	pglViewport( RI.viewport[0], RI.viewport[1], RI.viewport[2], RI.viewport[3] );

	pglMatrixMode( GL_PROJECTION );
	GL_LoadMatrix( RI.projectionMatrix );

	pglMatrixMode( GL_MODELVIEW );
	GL_LoadMatrix( RI.worldviewMatrix );

	if( RI.params & RP_CLIPPLANE )
	{
		GLdouble	clip[4];
		mplane_t	*p = &RI.clipPlane;

		clip[0] = p->normal[0];
		clip[1] = p->normal[1];
		clip[2] = p->normal[2];
		clip[3] = -p->dist;

		pglClipPlane( GL_CLIP_PLANE0, clip );
		pglEnable( GL_CLIP_PLANE0 );
	}

	if( RI.params & RP_FLIPFRONTFACE )
		GL_FrontFace( !glState.frontFace );

	GL_Cull( GL_FRONT );

	pglDisable( GL_BLEND );
	pglDisable( GL_ALPHA_TEST );
	pglColor4f( 1.0f, 1.0f, 1.0f, 1.0f );
}
Exemple #5
0
/*
=================
GL_LoadTexMatrixExt
=================
*/
void GL_LoadTexMatrixExt( const float *glmatrix )
{
	ASSERT( glmatrix != NULL );
	pglMatrixMode( GL_TEXTURE );
	pglLoadMatrixf( glmatrix );
	glState.texIdentityMatrix[glState.activeTMU] = false;
}
// Set texture matrix
static inline void gfxSetTextureMatrix2(Matrix12 *pMatrix)
{
  pglMatrixMode( GL_TEXTURE);
  if(pMatrix==NULL) {
    pglLoadIdentity();
  } else {
    Matrix16 mrot16;
    Matrix16 mtra16;
    CreateOpenGLMatrix(*pMatrix,mrot16);

    Matrix12 mtr12;
    SetMatrixDiagonal(mtr12,1);
    CreateOpenGLMatrix(mtr12,mtra16);
    pglLoadMatrixf(mtra16);
    pglMultMatrixf(mrot16);
  }
  pglMatrixMode(GL_MODELVIEW);
}
Exemple #7
0
/*
=================
GL_LoadIdentityTexMatrix
=================
*/
void GL_LoadIdentityTexMatrix( void )
{
	if( glState.texIdentityMatrix[glState.activeTMU] )
		return;

	pglMatrixMode( GL_TEXTURE );
	pglLoadIdentity();
	glState.texIdentityMatrix[glState.activeTMU] = true;
}
Exemple #8
0
/*
=============
R_LoadIdentity
=============
*/
void R_LoadIdentity( void )
{
	if( tr.modelviewIdentity ) return;

	Matrix4x4_LoadIdentity( RI.objectMatrix );
	Matrix4x4_Copy( RI.modelviewMatrix, RI.worldviewMatrix );

	pglMatrixMode( GL_MODELVIEW );
	GL_LoadMatrix( RI.modelviewMatrix );
	tr.modelviewIdentity = true;
}
// set texture matrix
static void ogl_SetTextureMatrix( const FLOAT *pfMatrix/*=NULL*/)
{
  // check API
  ASSERT( _pGfx->gl_eCurrentAPI==GAT_OGL);

  _sfStats.StartTimer(CStatForm::STI_GFXAPI);

  // set matrix
  pglMatrixMode(GL_TEXTURE);
  if( pfMatrix!=NULL) pglLoadMatrixf(pfMatrix);
  else pglLoadIdentity();
  OGL_CHECKERROR;

  _sfStats.StopTimer(CStatForm::STI_GFXAPI);
}
// set view matrix 
static void ogl_SetViewMatrix( const FLOAT *pfMatrix/*=NULL*/)
{
  // check API
  ASSERT( _pGfx->gl_eCurrentAPI==GAT_OGL);

  // cached? (only identity matrix)
  if( pfMatrix==NULL && GFX_bViewMatrix==NONE && gap_bOptimizeStateChanges) return;
  GFX_bViewMatrix = (pfMatrix!=NULL);

  _sfStats.StartTimer(CStatForm::STI_GFXAPI);

  // set matrix
  pglMatrixMode( GL_MODELVIEW);
  if( pfMatrix!=NULL) pglLoadMatrixf(pfMatrix);
  else pglLoadIdentity();
  OGL_CHECKERROR;

  _sfStats.StopTimer(CStatForm::STI_GFXAPI);
}
Exemple #11
0
/*
=============
R_TranslateForEntity
=============
*/
void R_TranslateForEntity( cl_entity_t *e )
{
	float	scale = 1.0f;

	if( e == clgame.entities || R_StaticEntity( e ))
	{
		R_LoadIdentity();
		return;
	}

	if( e->model->type != mod_brush && e->curstate.scale > 0.0f )
		scale = e->curstate.scale;

	Matrix4x4_CreateFromEntity( RI.objectMatrix, vec3_origin, e->origin, scale );
	Matrix4x4_ConcatTransforms( RI.modelviewMatrix, RI.worldviewMatrix, RI.objectMatrix );

	pglMatrixMode( GL_MODELVIEW );
	GL_LoadMatrix( RI.modelviewMatrix );
	tr.modelviewIdentity = false;
}
// set frustrum matrix
static void ogl_SetFrustum( const FLOAT fLeft, const FLOAT fRight,
                            const FLOAT fTop,  const FLOAT fBottom,
                            const FLOAT fNear, const FLOAT fFar)
{
  // check API
  ASSERT( _pGfx->gl_eCurrentAPI==GAT_OGL);

  // cached?
  if( GFX_fLastL==-fLeft  && GFX_fLastT==-fTop    && GFX_fLastN==-fNear
   && GFX_fLastR==-fRight && GFX_fLastB==-fBottom && GFX_fLastF==-fFar && gap_bOptimizeStateChanges) return;
  GFX_fLastL = -fLeft;   GFX_fLastT = -fTop;     GFX_fLastN = -fNear;
  GFX_fLastR = -fRight;  GFX_fLastB = -fBottom;  GFX_fLastF = -fFar;

  _sfStats.StartTimer(CStatForm::STI_GFXAPI);

  // set matrix
  pglMatrixMode( GL_PROJECTION);
  pglLoadIdentity();
  pglFrustum( fLeft, fRight, fBottom, fTop, fNear, fFar);
  OGL_CHECKERROR;

  _sfStats.StopTimer(CStatForm::STI_GFXAPI);
}
// set orthographic matrix
static void ogl_SetOrtho( const FLOAT fLeft,   const FLOAT fRight, const FLOAT fTop,
                          const FLOAT fBottom, const FLOAT fNear,  const FLOAT fFar,
                          const BOOL bSubPixelAdjust/*=FALSE*/)
{
  // check API and matrix type
  ASSERT( _pGfx->gl_eCurrentAPI==GAT_OGL);

  // cached?
  if( GFX_fLastL==fLeft  && GFX_fLastT==fTop    && GFX_fLastN==fNear
   && GFX_fLastR==fRight && GFX_fLastB==fBottom && GFX_fLastF==fFar && gap_bOptimizeStateChanges) return;
  GFX_fLastL = fLeft;   GFX_fLastT = fTop;     GFX_fLastN = fNear;
  GFX_fLastR = fRight;  GFX_fLastB = fBottom;  GFX_fLastF = fFar;

  _sfStats.StartTimer(CStatForm::STI_GFXAPI);

  // set matrix
  pglMatrixMode( GL_PROJECTION);
  pglLoadIdentity();
  pglOrtho( fLeft, fRight, fBottom, fTop, fNear, fFar);
  OGL_CHECKERROR;

  _sfStats.StopTimer(CStatForm::STI_GFXAPI);
}
Exemple #14
0
/*
=================
R_Bloom_GeneratexDiamonds
=================
*/
static void R_Bloom_GeneratexDiamonds( void )
{
    int i, j;
    float intensity;

    // set up sample size workspace
    pglScissor( 0, 0, sample_width, sample_height );
    pglViewport( 0, 0, sample_width, sample_height );
    pglMatrixMode( GL_PROJECTION );
    pglLoadIdentity();
    pglOrtho( 0, sample_width, sample_height, 0, -10, 100 );
    pglMatrixMode( GL_MODELVIEW );
    pglLoadIdentity();

    // copy small scene into r_bloomeffecttexture
    GL_Bind( GL_TEXTURE0, r_bloomeffecttexture );
    pglCopyTexSubImage2D( GL_TEXTURE_2D, 0, 0, 0, 0, 0, sample_width, sample_height );

    // start modifying the small scene corner
    pglColor4f( 1.0f, 1.0f, 1.0f, 1.0f );
    pglEnable( GL_BLEND );

    // darkening passes
    if( r_bloom_darken->value )
    {
        pglTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
        pglBlendFunc( GL_DST_COLOR, GL_ZERO );

        for( i = 0; i < (int)r_bloom_darken->value; i++ )
            R_Bloom_SamplePass( 0, 0 );

        pglCopyTexSubImage2D( GL_TEXTURE_2D, 0, 0, 0, 0, 0, sample_width, sample_height );
    }

    // bluring passes
    pglBlendFunc( GL_ONE, GL_ONE_MINUS_SRC_COLOR );

    if( r_bloom_diamond_size->value > 7.0f || r_bloom_diamond_size->value <= 3.0f )
    {
        if( r_bloom_diamond_size->value != 8.0f )
            CVAR_SET_FLOAT( "r_bloom_diamond_size", 8.0f );

        for( i = 0; i < r_bloom_diamond_size->value; i++ )
        {
            for( j = 0; j < r_bloom_diamond_size->value; j++ )
            {
                intensity = r_bloom_intensity->value * 0.3f * Diamond8x[i][j];
                if( intensity < 0.01f ) continue;
                pglColor4f( intensity, intensity, intensity, 1.0f );
                R_Bloom_SamplePass( i-4, j-4 );
            }
        }
    }
    else if( r_bloom_diamond_size->value > 5.0f )
    {
        if( r_bloom_diamond_size->value != 6.0f )
            CVAR_SET_FLOAT( "r_bloom_diamond_size", 6.0f );

        for( i = 0; i < r_bloom_diamond_size->value; i++ )
        {
            for( j = 0; j < r_bloom_diamond_size->value; j++ )
            {
                intensity = r_bloom_intensity->value * 0.5f * Diamond6x[i][j];
                if( intensity < 0.01f ) continue;
                pglColor4f( intensity, intensity, intensity, 1.0f );
                R_Bloom_SamplePass( i-3, j-3 );
            }
        }
    }
    else if( r_bloom_diamond_size->value > 3.0f )
    {
        if( r_bloom_diamond_size->value != 4.0f )
            CVAR_SET_FLOAT( "r_bloom_diamond_size", 4.0f );

        for( i = 0; i < r_bloom_diamond_size->value; i++ )
        {
            for( j = 0; j < r_bloom_diamond_size->value; j++ )
            {
                intensity = r_bloom_intensity->value * 0.8f * Diamond4x[i][j];
                if( intensity < 0.01f ) continue;
                pglColor4f( intensity, intensity, intensity, 1.0f );
                R_Bloom_SamplePass( i-2, j-2 );
            }
        }
    }

    pglCopyTexSubImage2D( GL_TEXTURE_2D, 0, 0, 0, 0, 0, sample_width, sample_height );

    // restore full screen workspace
    pglScissor( 0, 0, glState.width, glState.height );
    pglViewport( 0, 0, glState.width, glState.height );
    pglMatrixMode( GL_PROJECTION );
    pglLoadIdentity();
    pglOrtho( 0, glState.width, glState.height, 0, -10, 100 );
    pglMatrixMode( GL_MODELVIEW );
    pglLoadIdentity();
}
Exemple #15
0
/*
=============
R_SetupGL
=============
*/
static void R_SetupGL( void )
{
	if( r_underwater_distortion->value && RI.refdef.waterlevel >= 3 )
	{
		float	f;
		f = sin( cl.time * r_underwater_distortion->value * ( M_PI * 2.7f ));
		RI.refdef.fov_x += f;
		RI.refdef.fov_y -= f;
	}

	R_SetupModelviewMatrix( &RI.refdef, RI.worldviewMatrix );
	R_SetupProjectionMatrix( &RI.refdef, RI.projectionMatrix );
//	if( RI.params & RP_MIRRORVIEW ) RI.projectionMatrix[0][0] = -RI.projectionMatrix[0][0];

	Matrix4x4_Concat( RI.worldviewProjectionMatrix, RI.projectionMatrix, RI.worldviewMatrix );

	if( RP_NORMALPASS( ))
	{
		int	x, x2, y, y2;

		// set up viewport (main, playersetup)
		x = floor( RI.viewport[0] * glState.width / glState.width );
		x2 = ceil(( RI.viewport[0] + RI.viewport[2] ) * glState.width / glState.width );
		y = floor( glState.height - RI.viewport[1] * glState.height / glState.height );
		y2 = ceil( glState.height - ( RI.viewport[1] + RI.viewport[3] ) * glState.height / glState.height );

		pglViewport( x, y2, x2 - x, y - y2 );
	}
	else
	{
		// envpass, mirrorpass
		pglViewport( RI.viewport[0], RI.viewport[1], RI.viewport[2], RI.viewport[3] );
	}

	pglMatrixMode( GL_PROJECTION );
	GL_LoadMatrix( RI.projectionMatrix );

	pglMatrixMode( GL_MODELVIEW );
	GL_LoadMatrix( RI.worldviewMatrix );

	if( RI.params & RP_CLIPPLANE )
	{
		GLdouble	clip[4];
		mplane_t	*p = &RI.clipPlane;

		clip[0] = p->normal[0];
		clip[1] = p->normal[1];
		clip[2] = p->normal[2];
		clip[3] = -p->dist;

		pglClipPlane( GL_CLIP_PLANE0, clip );
		pglEnable( GL_CLIP_PLANE0 );
	}

	if( RI.params & RP_FLIPFRONTFACE )
		GL_FrontFace( !glState.frontFace );

	GL_Cull( GL_FRONT );

	pglDisable( GL_BLEND );
	pglDisable( GL_ALPHA_TEST );
	pglColor4f( 1.0f, 1.0f, 1.0f, 1.0f );
}
Exemple #16
0
/*
=================
R_BloomBlend
=================
*/
void R_BloomBlend( const ref_params_t *fd )
{
    if( !r_bloom->value )
        return;

    if( !BLOOM_SIZE )
        R_Bloom_InitTextures();

    if( screen_texture_width < BLOOM_SIZE || screen_texture_height < BLOOM_SIZE )
        return;

    // set up full screen workspace
    pglScissor( 0, 0, glState.width, glState.height );
    pglViewport( 0, 0, glState.width, glState.height );
    pglMatrixMode( GL_PROJECTION );
    pglLoadIdentity();

    pglOrtho( 0, glState.width, glState.height, 0, -10, 100 );

    pglMatrixMode( GL_MODELVIEW );
    pglLoadIdentity();

    pglDisable( GL_DEPTH_TEST );
    pglDisable( GL_ALPHA_TEST );
    pglDepthMask( GL_FALSE );
    pglDisable( GL_BLEND );

    GL_Cull( 0 );
    pglColor4f( 1.0f, 1.0f, 1.0f, 1.0f );
    pglTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );

    // set up current sizes
    curView_x = fd->viewport[0];
    curView_y = fd->viewport[1];
    curView_width = fd->viewport[2];
    curView_height = fd->viewport[3];

    screenTex_tcw = ( (float)curView_width / (float)screen_texture_width );
    screenTex_tch = ( (float)curView_height / (float)screen_texture_height );
    if( curView_height > curView_width )
    {
        sampleText_tcw = ( (float)curView_width / (float)curView_height );
        sampleText_tch = 1.0f;
    }
    else
    {
        sampleText_tcw = 1.0f;
        sampleText_tch = ( (float)curView_height / (float)curView_width );
    }

    sample_width = ( BLOOM_SIZE * sampleText_tcw );
    sample_height = ( BLOOM_SIZE * sampleText_tch );

    // copy the screen space we'll use to work into the backup texture
    GL_Bind( GL_TEXTURE0, r_bloombackuptexture );
    pglCopyTexSubImage2D( GL_TEXTURE_2D, 0, 0, 0, 0, 0, r_screenbackuptexture_width * sampleText_tcw, r_screenbackuptexture_height * sampleText_tch );

    // create the bloom image
    R_Bloom_DownsampleView();
    R_Bloom_GeneratexDiamonds();

    pglDisable( GL_BLEND );
    // restore the screen-backup to the screen
    GL_Bind( GL_TEXTURE0, r_bloombackuptexture );

    pglColor4f( 1, 1, 1, 1 );

    R_Bloom_Quad( 0,
                  glState.height - (r_screenbackuptexture_height * sampleText_tch),
                  r_screenbackuptexture_width * sampleText_tcw,
                  r_screenbackuptexture_height * sampleText_tch,
                  sampleText_tcw, sampleText_tch );

    pglScissor( RI.scissor[0], RI.scissor[1], RI.scissor[2], RI.scissor[3] );

    R_Bloom_DrawEffect();

    pglViewport( RI.viewport[0], RI.viewport[1], RI.viewport[2], RI.viewport[3] );

    pglMatrixMode( GL_PROJECTION );
    GL_LoadMatrix( RI.projectionMatrix );

    pglMatrixMode( GL_MODELVIEW );
    GL_LoadMatrix( RI.worldviewMatrix );

    pglEnable( GL_DEPTH_TEST );
    pglDepthMask( GL_TRUE );
    pglDisable( GL_BLEND );
    GL_Cull( GL_FRONT );
}
Exemple #17
0
/*
================
R_EndDrawMirror

Restore identity texmatrix
================
*/
void R_EndDrawMirror( void )
{
	GL_CleanUpTextureUnits( 0 );
	pglMatrixMode( GL_MODELVIEW );
}
Exemple #18
0
/*
=================
GL_LoadTexMatrix
=================
*/
void GL_LoadTexMatrix( cmatrix4x4 m )
{
	pglMatrixMode( GL_TEXTURE );
	GL_LoadMatrix( m );
	glState.texIdentityMatrix[glState.activeTMU] = false;
}