This repository has been archived on 2022-06-27. You can view files and clone it, but cannot push or open issues or pull requests.
Xash3DArchive/engine/client/gl_draw.c

234 lines
5.4 KiB
C
Raw Normal View History

2011-05-09 22:00:00 +02:00
/*
gl_draw.c - orthogonal drawing stuff
Copyright (C) 2010 Uncle Mike
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
*/
2010-11-28 22:00:00 +01:00
#include "common.h"
#include "client.h"
#include "gl_local.h"
2010-12-02 22:00:00 +01:00
/*
=============
R_GetImageParms
=============
*/
void R_GetTextureParms( int *w, int *h, int texnum )
{
gltexture_t *glt;
glt = R_GetTexture( texnum );
if( w ) *w = glt->srcWidth;
if( h ) *h = glt->srcHeight;
}
/*
=============
R_GetSpriteParms
same as GetImageParms but used
for sprite models
=============
*/
void R_GetSpriteParms( int *frameWidth, int *frameHeight, int *numFrames, int currentFrame, const model_t *pSprite )
{
mspriteframe_t *pFrame;
if( !pSprite || pSprite->type != mod_sprite ) return; // bad model ?
pFrame = R_GetSpriteFrame( pSprite, currentFrame, 0.0f );
if( frameWidth ) *frameWidth = pFrame->width;
if( frameHeight ) *frameHeight = pFrame->height;
if( numFrames ) *numFrames = pSprite->numframes;
}
int R_GetSpriteTexture( const model_t *m_pSpriteModel, int frame )
{
if( !m_pSpriteModel || m_pSpriteModel->type != mod_sprite || !m_pSpriteModel->cache.data )
return 0;
return R_GetSpriteFrame( m_pSpriteModel, frame, 0.0f )->gl_texturenum;
}
2010-11-29 22:00:00 +01:00
/*
=============
R_DrawStretchPic
=============
*/
void R_DrawStretchPic( float x, float y, float w, float h, float s1, float t1, float s2, float t2, int texnum )
{
GL_Bind( GL_TEXTURE0, texnum );
2010-11-28 22:00:00 +01:00
2010-11-29 22:00:00 +01:00
pglBegin( GL_QUADS );
pglTexCoord2f( s1, t1 );
pglVertex2f( x, y );
2010-11-28 22:00:00 +01:00
2010-11-29 22:00:00 +01:00
pglTexCoord2f( s2, t1 );
pglVertex2f( x + w, y );
2010-11-28 22:00:00 +01:00
2010-11-29 22:00:00 +01:00
pglTexCoord2f( s2, t2 );
pglVertex2f( x + w, y + h );
2010-11-28 22:00:00 +01:00
2010-11-29 22:00:00 +01:00
pglTexCoord2f( s1, t2 );
pglVertex2f( x, y + h );
pglEnd();
2010-11-28 22:00:00 +01:00
}
2011-09-19 22:00:00 +02:00
/*
=============
Draw_TileClear
This repeats a 64*64 tile graphic to fill the screen around a sized down
refresh window.
=============
*/
void R_DrawTileClear( int x, int y, int w, int h )
{
float tw, th;
gltexture_t *glt;
GL_SetRenderMode( kRenderNormal );
pglColor4f( 1.0f, 1.0f, 1.0f, 1.0f );
GL_Bind( GL_TEXTURE0, cls.tileImage );
glt = R_GetTexture( cls.tileImage );
tw = glt->srcWidth;
th = glt->srcHeight;
pglBegin( GL_QUADS );
pglTexCoord2f( x / tw, y / th );
pglVertex2f( x, y );
pglTexCoord2f((x + w) / tw, y / th );
pglVertex2f( x + w, y );
pglTexCoord2f((x + w) / tw, (y + h) / th );
pglVertex2f( x + w, y + h );
pglTexCoord2f( x / tw, (y + h) / th );
pglVertex2f( x, y + h );
pglEnd ();
}
2010-11-28 22:00:00 +01:00
/*
=============
R_DrawStretchRaw
=============
*/
void R_DrawStretchRaw( float x, float y, float w, float h, int cols, int rows, const byte *data, qboolean dirty )
{
2010-11-29 22:00:00 +01:00
byte *raw;
gltexture_t *tex;
2010-11-28 22:00:00 +01:00
if( !GL_Support( GL_ARB_TEXTURE_NPOT_EXT ))
{
int width = 1, height = 1;
// check the dimensions
2010-12-27 22:00:00 +01:00
width = NearestPOW( cols, true );
height = NearestPOW( rows, false );
2010-11-28 22:00:00 +01:00
if( cols != width || rows != height )
{
2010-11-29 22:00:00 +01:00
raw = GL_ResampleTexture( data, cols, rows, width, height, false );
2010-11-28 22:00:00 +01:00
cols = width;
rows = height;
}
}
else
{
raw = (byte *)data;
}
if( cols > glConfig.max_2d_texture_size )
2010-11-29 22:00:00 +01:00
Host_Error( "R_DrawStretchRaw: size %i exceeds hardware limits\n", cols );
2010-11-28 22:00:00 +01:00
if( rows > glConfig.max_2d_texture_size )
2010-11-29 22:00:00 +01:00
Host_Error( "R_DrawStretchRaw: size %i exceeds hardware limits\n", rows );
2010-11-28 22:00:00 +01:00
2011-04-08 22:00:00 +02:00
pglDisable( GL_BLEND );
pglDisable( GL_ALPHA_TEST );
pglTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE );
2010-11-29 22:00:00 +01:00
tex = R_GetTexture( tr.cinTexture );
2010-12-27 22:00:00 +01:00
GL_Bind( GL_TEXTURE0, tr.cinTexture );
2010-11-28 22:00:00 +01:00
2010-11-29 22:00:00 +01:00
if( cols == tex->width && rows == tex->height )
2010-11-28 22:00:00 +01:00
{
2010-11-29 22:00:00 +01:00
if( dirty )
{
pglTexSubImage2D( GL_TEXTURE_2D, 0, 0, 0, cols, rows, GL_BGRA, GL_UNSIGNED_BYTE, raw );
}
2010-11-28 22:00:00 +01:00
}
else
{
2010-11-29 22:00:00 +01:00
tex->width = cols;
tex->height = rows;
if( dirty )
{
pglTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, cols, rows, 0, GL_BGRA, GL_UNSIGNED_BYTE, raw );
}
2010-11-28 22:00:00 +01:00
}
pglBegin( GL_QUADS );
pglTexCoord2f( 0, 0 );
pglVertex2f( x, y );
pglTexCoord2f( 1, 0 );
pglVertex2f( x + w, y );
pglTexCoord2f( 1, 1 );
pglVertex2f( x + w, y + h );
pglTexCoord2f( 0, 1 );
pglVertex2f( x, y + h );
pglEnd();
2010-11-29 22:00:00 +01:00
}
/*
===============
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 );
2011-09-28 22:00:00 +02:00
pglLoadIdentity();
pglOrtho( 0, glState.width, glState.height, 0, -99999, 99999 );
2010-11-29 22:00:00 +01:00
pglMatrixMode( GL_MODELVIEW );
pglLoadIdentity();
GL_Cull( 0 );
2011-02-25 22:00:00 +01:00
pglDepthMask( GL_FALSE );
pglDisable( GL_DEPTH_TEST );
2010-11-29 22:00:00 +01:00
pglColor4f( 1.0f, 1.0f, 1.0f, 1.0f );
glState.in2DMode = true;
RI.currententity = NULL;
RI.currentmodel = NULL;
}
else
{
2011-02-26 22:00:00 +01:00
pglDepthMask( GL_TRUE );
2011-02-25 22:00:00 +01:00
pglEnable( GL_DEPTH_TEST );
2010-11-29 22:00:00 +01:00
glState.in2DMode = false;
2011-09-28 22:00:00 +02:00
pglMatrixMode( GL_PROJECTION );
GL_LoadMatrix( RI.projectionMatrix );
pglMatrixMode( GL_MODELVIEW );
GL_LoadMatrix( RI.worldviewMatrix );
2010-11-29 22:00:00 +01:00
}
2010-11-28 22:00:00 +01:00
}