From 73e3aa6ef6668740826dc4b6c878a49b63ddab9e Mon Sep 17 00:00:00 2001 From: Lee Salzman Date: Fri, 18 Apr 2008 11:30:35 +0000 Subject: [PATCH] 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 --- source/src/renderhud.cpp | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/source/src/renderhud.cpp b/source/src/renderhud.cpp index 8e90df79..d6a5d8a4 100644 --- a/source/src/renderhud.cpp +++ b/source/src/renderhud.cpp @@ -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(); }