ensure scope is always drawn at correct aspect ratio

git-svn-id: svn://svn.code.sf.net/p/actiongame/code/trunk/ac@1803 e016b1c5-ed68-44aa-a2f7-31cac88cffde
This commit is contained in:
Lee Salzman
2008-04-18 11:30:35 +00:00
parent 241dfc3401
commit 73e3aa6ef6
+29 -4
View File
@@ -64,6 +64,9 @@ VAR(showmap, 0, 0, 1);
void drawscope()
{
// this may need to change depending on the aspect ratio at which the scope image is drawn at
const float scopeaspect = 4.0f/3.0f;
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
static Texture *scopetex = NULL;
if(!scopetex) scopetex = textureload("packages/misc/scope.png");
@@ -71,10 +74,32 @@ void drawscope()
glBegin(GL_QUADS);
glColor3ub(255,255,255);
glTexCoord2i(0, 0); glVertex2i(0, 0);
glTexCoord2i(1, 0); glVertex2i(VIRTW, 0);
glTexCoord2i(1, 1); glVertex2i(VIRTW, VIRTH);
glTexCoord2i(0, 1); glVertex2i(0, VIRTH);
// figure out the bounds of the scope given the desired aspect ratio
float w = min(scopeaspect*VIRTH, float(VIRTW)),
x1 = VIRTW/2 - w/2,
x2 = VIRTW/2 + w/2;
glTexCoord2i(0, 0); glVertex2f(x1, 0);
glTexCoord2i(1, 0); glVertex2f(x2, 0);
glTexCoord2i(1, 1); glVertex2f(x2, VIRTH);
glTexCoord2i(0, 1); glVertex2f(x1, VIRTH);
// fill unused space with border texels
if(x1 > 0)
{
glTexCoord2i(0, 0); glVertex2f(0, 0);
glTexCoord2i(0, 0); glVertex2f(x1, 0);
glTexCoord2i(0, 1); glVertex2f(x1, VIRTH);
glTexCoord2i(0, 1); glVertex2f(0, VIRTH);
}
if(x2 < VIRTW)
{
glTexCoord2i(1, 0); glVertex2f(x2, 0);
glTexCoord2i(1, 0); glVertex2f(VIRTW, 0);
glTexCoord2i(1, 1); glVertex2f(VIRTW, VIRTH);
glTexCoord2i(1, 1); glVertex2f(x2, VIRTH);
}
glEnd();
}