diff --git a/source/src/menus.cpp b/source/src/menus.cpp index c3184c9b..3a78cb14 100644 --- a/source/src/menus.cpp +++ b/source/src/menus.cpp @@ -249,11 +249,11 @@ struct mitemimagemanual : mitemmanual glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glColor3f(1, 1, 1); xs = (FONTH*image->xs)/image->ys; - glBegin(GL_TRIANGLE_FAN); + glBegin(GL_TRIANGLE_STRIP); glTexCoord2f(0, 0); glVertex2f(x, y); glTexCoord2f(1, 0); glVertex2f(x+xs, y); - glTexCoord2f(1, 1); glVertex2f(x+xs, y+FONTH); glTexCoord2f(0, 1); glVertex2f(x, y+FONTH); + glTexCoord2f(1, 1); glVertex2f(x+xs, y+FONTH); glEnd(); xtraverts += 4; } @@ -281,11 +281,11 @@ struct mitemimagemanual : mitemmanual glBindTexture(GL_TEXTURE_2D, image->id); // I just copy&pasted this... glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // could pls someone with actual OpenGL-knowledge check this? glColor3f(1, 1, 1); - glBegin(GL_TRIANGLE_FAN); + glBegin(GL_TRIANGLE_STRIP); glTexCoord2f(0, 0); glVertex2f(x, y); glTexCoord2f(1, 0); glVertex2f(x+xs, y); - glTexCoord2f(1, 1); glVertex2f(x+xs, y+ys); glTexCoord2f(0, 1); glVertex2f(x, y+ys); + glTexCoord2f(1, 1); glVertex2f(x+xs, y+ys); glEnd(); xtraverts += 4; } diff --git a/source/src/rendergl.cpp b/source/src/rendergl.cpp index 3e0fbf09..15359144 100644 --- a/source/src/rendergl.cpp +++ b/source/src/rendergl.cpp @@ -174,11 +174,11 @@ void disablepolygonoffset(GLenum type, bool restore) void line(int x1, int y1, float z1, int x2, int y2, float z2) { - glBegin(GL_TRIANGLE_FAN); + glBegin(GL_TRIANGLE_STRIP); glVertex3f((float)x1, (float)y1, z1); glVertex3f((float)x1, y1+0.01f, z1); - glVertex3f((float)x2, y2+0.01f, z2); glVertex3f((float)x2, (float)y2, z2); + glVertex3f((float)x2, y2+0.01f, z2); glEnd(); xtraverts += 4; } @@ -203,11 +203,11 @@ void linestyle(float width, int r, int g, int b) void box(block &b, float z1, float z2, float z3, float z4) { - glBegin(GL_TRIANGLE_FAN); + glBegin(GL_TRIANGLE_STRIP); glVertex3f((float)b.x, (float)b.y, z1); glVertex3f((float)b.x+b.xs, (float)b.y, z2); - glVertex3f((float)b.x+b.xs, (float)b.y+b.ys, z3); glVertex3f((float)b.x, (float)b.y+b.ys, z4); + glVertex3f((float)b.x+b.xs, (float)b.y+b.ys, z3); glEnd(); xtraverts += 4; } @@ -216,11 +216,11 @@ void quad(GLuint tex, float x, float y, float s, float tx, float ty, float tsx, { if(!tsy) tsy = tsx; glBindTexture(GL_TEXTURE_2D, tex); - glBegin(GL_TRIANGLE_FAN); + glBegin(GL_TRIANGLE_STRIP); glTexCoord2f(tx, ty); glVertex2f(x, y); glTexCoord2f(tx+tsx, ty); glVertex2f(x+s, y); - glTexCoord2f(tx+tsx, ty+tsy); glVertex2f(x+s, y+s); glTexCoord2f(tx, ty+tsy); glVertex2f(x, y+s); + glTexCoord2f(tx+tsx, ty+tsy); glVertex2f(x+s, y+s); glEnd(); xtraverts += 4; } @@ -229,11 +229,11 @@ void quad(GLuint tex, const vec &c1, const vec &c2, float tx, float ty, float ts { if(!tsy) tsy = tsx; glBindTexture(GL_TEXTURE_2D, tex); - glBegin(GL_TRIANGLE_FAN); - glTexCoord2f(tx, ty); glVertex3f(c1.x, c1.y, c1.z); - glTexCoord2f(tx+tsx, ty); glVertex3f(c2.x, c1.y, c1.z); - glTexCoord2f(tx+tsx, ty+tsy); glVertex3f(c2.x, c2.y, c2.z); - glTexCoord2f(tx, ty+tsy); glVertex3f(c1.x, c2.y, c2.z); + glBegin(GL_TRIANGLE_STRIP); + glTexCoord2f(tx, ty); glVertex3f(c1.x, c1.y, c1.z); + glTexCoord2f(tx+tsx, ty); glVertex3f(c2.x, c1.y, c1.z); + glTexCoord2f(tx, ty+tsy); glVertex3f(c1.x, c2.y, c2.z); + glTexCoord2f(tx+tsx, ty+tsy); glVertex3f(c2.x, c2.y, c2.z); glEnd(); xtraverts += 4; } @@ -257,11 +257,11 @@ void circle(GLuint tex, float x, float y, float r, float tx, float ty, float tr, void dot(int x, int y, float z) { const float DOF = 0.1f; - glBegin(GL_TRIANGLE_FAN); + glBegin(GL_TRIANGLE_STRIP); glVertex3f(x-DOF, y-DOF, z); glVertex3f(x+DOF, y-DOF, z); - glVertex3f(x+DOF, y+DOF, z); glVertex3f(x-DOF, y+DOF, z); + glVertex3f(x+DOF, y+DOF, z); glEnd(); xtraverts += 4; } @@ -309,11 +309,11 @@ void blendbox(int x1, int y1, int x2, int y2, bool border, int tex, color *c) xtexcut = (float)(((i+1)*texw)-(x2-x1))/texw; } - glBegin(GL_TRIANGLE_FAN); + glBegin(GL_TRIANGLE_STRIP); glTexCoord2f(0, 0); glVertex2f((float)x1+texw*i, (float)y1+texh*j); glTexCoord2f(1-xtexcut, 0); glVertex2f(x1+texw*(i+1)-xboxcut, (float)y1+texh*j); - glTexCoord2f(1-xtexcut, 1-ytexcut); glVertex2f(x1+texw*(i+1)-xboxcut, (float)y1+texh*(j+1)-yboxcut); glTexCoord2f(0, 1-ytexcut); glVertex2f((float)x1+texw*i, y1+texh*(j+1)-yboxcut); + glTexCoord2f(1-xtexcut, 1-ytexcut); glVertex2f(x1+texw*(i+1)-xboxcut, (float)y1+texh*(j+1)-yboxcut); glEnd(); } } @@ -335,11 +335,11 @@ void blendbox(int x1, int y1, int x2, int y2, bool border, int tex, color *c) glColor3f(0.5f, 0.5f, 0.5f); } - glBegin(GL_TRIANGLE_FAN); + glBegin(GL_TRIANGLE_STRIP); glTexCoord2f(0, 0); glVertex2f(x1, y1); glTexCoord2f(1, 0); glVertex2f(x2, y1); - glTexCoord2f(1, 1); glVertex2f(x2, y2); glTexCoord2f(0, 1); glVertex2f(x1, y2); + glTexCoord2f(1, 1); glVertex2f(x2, y2); glEnd(); xtraverts += 4; } @@ -677,11 +677,11 @@ void drawreflection(float hf, int w, int h, float changelod, bool refract) glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glColor4ubv(hdr.watercolor); - glBegin(GL_TRIANGLE_FAN); + glBegin(GL_TRIANGLE_STRIP); glVertex2f(0, 1); glVertex2f(1, 1); - glVertex2f(1, 0); glVertex2f(0, 0); + glVertex2f(1, 0); glEnd(); glDisable(GL_BLEND); glEnable(GL_TEXTURE_2D); diff --git a/source/src/renderhud.cpp b/source/src/renderhud.cpp index de473087..e133ea53 100644 --- a/source/src/renderhud.cpp +++ b/source/src/renderhud.cpp @@ -82,59 +82,69 @@ 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", 3); - // 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; - float s1 = VIRTW/16, s2 = VIRTH/24; - glDisable(GL_BLEND); - - glBegin(GL_QUADS); - glColor3ub( 0, 0, 0); - //glColor3ub(255, 0, 0); - glVertex2f( 0, 0); - glVertex2f(VIRTW, 0); - glVertex2f(VIRTW, 4*s2); - glVertex2f( 0, 4*s2); - - glVertex2f( 0, 4*s2); - glVertex2f(3*s1, 4*s2); - glVertex2f(3*s1,20*s2); - glVertex2f( 0,20*s2); - - glVertex2f( 0, 20*s2); - glVertex2f(VIRTW, 20*s2); - glVertex2f(VIRTW, VIRTH); - glVertex2f( 0, VIRTH); - - glVertex2f(13*s1, 4*s2); - glVertex2f(VIRTW, 4*s2); - glVertex2f(VIRTW,20*s2); - glVertex2f(13*s1,20*s2); - glEnd(); - glBegin(GL_TRIANGLES); - glVertex2f( 3*s1, 3*s2); glVertex2f( 7*s1, 3*s2); glVertex2f( 3*s1, 9*s2); - glVertex2f( 9*s1, 3*s2); glVertex2f(14*s1, 3*s2); glVertex2f(14*s1, 9*s2); - glVertex2f(14*s1,15*s2); glVertex2f(14*s1,20*s2); glVertex2f( 9*s1,20*s2); - glVertex2f( 7*s1,20*s2); glVertex2f( 3*s1,20*s2); glVertex2f( 3*s1,15*s2); - glEnd(); - glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glBindTexture(GL_TEXTURE_2D, scopetex->id); glColor3ub(255, 255, 255); + + // figure out the bounds of the scope given the desired aspect ratio + float sz = min(VIRTW, VIRTH), + x1 = VIRTW/2 - sz/2, + x2 = VIRTW/2 + sz/2, + y1 = VIRTH/2 - sz/2, + y2 = VIRTH/2 + sz/2, + border = (512 - 64*2)/512.0f; + + // draw center viewport glBegin(GL_TRIANGLE_FAN); - glTexCoord2f(0, 0); glVertex2f(x1, 0); - glTexCoord2f(1, 0); glVertex2f(x2, 0); - glTexCoord2f(1, 1); glVertex2f(x2, VIRTH); - glTexCoord2f(0, 1); glVertex2f(x1, VIRTH); + glTexCoord2f(0.5f, 0.5f); + glVertex2f(x1 + 0.5f*sz, y1 + 0.5f*sz); + loopi(8+1) + { + float c = 0.5f*(1 + border*cosf(i*2*M_PI/8.0f)), s = 0.5f*(1 + border*sinf(i*2*M_PI/8.0f)); + glTexCoord2f(c, s); + glVertex2f(x1 + c*sz, y1 + s*sz); + } glEnd(); + + glDisable(GL_BLEND); + + // draw outer scope + glBegin(GL_TRIANGLE_STRIP); + loopi(8+1) + { + float c = 0.5f*(1 + border*cosf(i*2*M_PI/8.0f)), s = 0.5f*(1 + border*sinf(i*2*M_PI/8.0f)); + glTexCoord2f(c, s); + glVertex2f(x1 + c*sz, y1 + s*sz); + c = c < 0.4f ? 0 : (c > 0.6f ? 1 : 0.5f); + s = s < 0.4f ? 0 : (s > 0.6f ? 1 : 0.5f); + glTexCoord2f(c, s); + glVertex2f(x1 + c*sz, y1 + s*sz); + } + glEnd(); + + // fill unused space with border texels + if(x1 > 0 || x2 < VIRTW || y1 > 0 || y2 < VIRTH) + { + glBegin(GL_TRIANGLE_STRIP); + glTexCoord2f(0, 0); glVertex2f(0, 0); + glTexCoord2f(0, 0); glVertex2f(x1, y1); + glTexCoord2f(0, 1); glVertex2f(0, VIRTH); + glTexCoord2f(0, 1); glVertex2f(x1, y2); + + glTexCoord2f(1, 1); glVertex2f(VIRTW, VIRTH); + glTexCoord2f(1, 1); glVertex2f(x2, y2); + glTexCoord2f(1, 0); glVertex2f(VIRTW, 0); + glTexCoord2f(1, 0); glVertex2f(x2, y1); + + glTexCoord2f(0, 0); glVertex2f(0, 0); + glTexCoord2f(0, 0); glVertex2f(x1, y1); + glEnd(); + } + + glEnable(GL_BLEND); } const char *crosshairnames[CROSSHAIR_NUM] = { "default", "teammate", "scope" }; @@ -187,11 +197,11 @@ void drawcrosshair(playerent *p, int n, color *c, float size) } float s = size>0 ? size : (float)crosshairsize; float chsize = s * (p->weaponsel->type==GUN_ASSAULT && p->weaponsel->shots > 3 ? 1.4f : 1.0f) * (n==CROSSHAIR_TEAMMATE ? 2.0f : 1.0f); - glBegin(GL_TRIANGLE_FAN); + glBegin(GL_TRIANGLE_STRIP); glTexCoord2f(0, 0); glVertex2f(VIRTW/2 - chsize, VIRTH/2 - chsize); glTexCoord2f(1, 0); glVertex2f(VIRTW/2 + chsize, VIRTH/2 - chsize); - glTexCoord2f(1, 1); glVertex2f(VIRTW/2 + chsize, VIRTH/2 + chsize); glTexCoord2f(0, 1); glVertex2f(VIRTW/2 - chsize, VIRTH/2 + chsize); + glTexCoord2f(1, 1); glVertex2f(VIRTW/2 + chsize, VIRTH/2 + chsize); glEnd(); } @@ -527,11 +537,11 @@ void gl_drawhud(int w, int h, int curfps, int nquads, int curvert, bool underwat glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glColor4ub(hdr.watercolor[0], hdr.watercolor[1], hdr.watercolor[2], 102); - glBegin(GL_TRIANGLE_FAN); + glBegin(GL_TRIANGLE_STRIP); glVertex2f(0, 0); glVertex2f(VIRTW, 0); - glVertex2f(VIRTW, VIRTH); glVertex2f(0, VIRTH); + glVertex2f(VIRTW, VIRTH); glEnd(); } @@ -548,11 +558,11 @@ void gl_drawhud(int w, int h, int curfps, int nquads, int curvert, bool underwat fade *= float(damageblendmillis - lastmillis)/damagescreenfade; glColor4f(fade, fade, fade, fade); - glBegin(GL_TRIANGLE_FAN); + glBegin(GL_TRIANGLE_STRIP); glTexCoord2f(0, 0); glVertex2f(0, 0); glTexCoord2f(1, 0); glVertex2f(VIRTW, 0); - glTexCoord2f(1, 1); glVertex2f(VIRTW, VIRTH); glTexCoord2f(0, 1); glVertex2f(0, VIRTH); + glTexCoord2f(1, 1); glVertex2f(VIRTW, VIRTH); glEnd(); } diff --git a/source/src/shadow.cpp b/source/src/shadow.cpp index 58e74cef..04b8b6cb 100644 --- a/source/src/shadow.cpp +++ b/source/src/shadow.cpp @@ -271,11 +271,11 @@ static void rendershadowtiles() if(!shadowtile) { - glBegin(GL_TRIANGLE_FAN); + glBegin(GL_TRIANGLE_STRIP); glVertex2f(clipy1, clipx1); glVertex2f(clipy1, clipx2); - glVertex2f(clipy2, clipx2); glVertex2f(clipy2, clipx1); + glVertex2f(clipy2, clipx2); xtraverts += 4; glEnd(); return; diff --git a/source/src/texture.cpp b/source/src/texture.cpp index e7ac7af0..6963f026 100644 --- a/source/src/texture.cpp +++ b/source/src/texture.cpp @@ -481,11 +481,11 @@ void draw_envbox_face(float s0, float t0, float x0, float y0, float z0, Texture *tex) { glBindTexture(GL_TEXTURE_2D, tex->id); - glBegin(GL_TRIANGLE_FAN); + glBegin(GL_TRIANGLE_STRIP); glTexCoord2f(s3, t3); glVertex3f(x3, y3, z3); glTexCoord2f(s2, t2); glVertex3f(x2, y2, z2); - glTexCoord2f(s1, t1); glVertex3f(x1, y1, z1); glTexCoord2f(s0, t0); glVertex3f(x0, y0, z0); + glTexCoord2f(s1, t1); glVertex3f(x1, y1, z1); glEnd(); xtraverts += 4; }