From b3234ca0277c5e282a2a0a2558b58edb25750653 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Thu, 13 Nov 2014 22:52:18 +0200 Subject: [PATCH] Use triangle strips instead of quads --- source/button.cpp | 10 +++++----- source/graphic.cpp | 21 +++++++++++++-------- source/image.cpp | 10 +++++----- 3 files changed, 23 insertions(+), 18 deletions(-) diff --git a/source/button.cpp b/source/button.cpp index 57e5fa4..86b73c9 100644 --- a/source/button.cpp +++ b/source/button.cpp @@ -56,15 +56,15 @@ void Button::rebuild_special(const Part &part) GL::MeshBuilder bld(part_cache.create_mesh(part, *icon)); bld.color(1.0f, 1.0f, 1.0f); - bld.begin(GL::QUADS); + bld.begin(GL::TRIANGLE_STRIP); + bld.texcoord(0, 1); + bld.vertex(rgeom.x, rgeom.y+rgeom.h); bld.texcoord(0, 0); bld.vertex(rgeom.x, rgeom.y); - bld.texcoord(1, 0); - bld.vertex(rgeom.x+rgeom.w, rgeom.y); bld.texcoord(1, 1); bld.vertex(rgeom.x+rgeom.w, rgeom.y+rgeom.h); - bld.texcoord(0, 1); - bld.vertex(rgeom.x, rgeom.y+rgeom.h); + bld.texcoord(1, 0); + bld.vertex(rgeom.x+rgeom.w, rgeom.y); bld.end(); } } diff --git a/source/graphic.cpp b/source/graphic.cpp index 5fc27ef..75e1088 100644 --- a/source/graphic.cpp +++ b/source/graphic.cpp @@ -27,24 +27,29 @@ void Graphic::build(unsigned wd, unsigned ht, GL::PrimitiveBuilder &bld) const unsigned ymax = y.size()-(border.top ? 2 : 3); bld.color(1.0f, 1.0f, 1.0f); - bld.begin(GL::QUADS); for(unsigned i=ymin; i<=ymax; ++i) { unsigned i2 = (i==0 ? 0 : i==y.size()-2 ? 2 : 1); for(unsigned j=xmin; j<=xmax; ++j) { unsigned j2 = (j==0 ? 0 : j==x.size()-2 ? 2 : 1); - bld.texcoord(u[j2], v[i2]); - bld.vertex(x[j], y[i]); - bld.texcoord(u[j2+1], v[i2]); - bld.vertex(x[j+1], y[i]); + if(j==xmin || (j>1 && jxmin) + bld.end(); + bld.begin(GL::TRIANGLE_STRIP); + bld.texcoord(u[j2], v[i2+1]); + bld.vertex(x[j], y[i+1]); + bld.texcoord(u[j2], v[i2]); + bld.vertex(x[j], y[i]); + } bld.texcoord(u[j2+1], v[i2+1]); bld.vertex(x[j+1], y[i+1]); - bld.texcoord(u[j2], v[i2+1]); - bld.vertex(x[j], y[i+1]); + bld.texcoord(u[j2+1], v[i2]); + bld.vertex(x[j+1], y[i]); } + bld.end(); } - bld.end(); } void Graphic::create_coords(float low, float high, float brd1, float brd2, float block, vector &coords) const diff --git a/source/image.cpp b/source/image.cpp index 5dcb2e3..f1180c3 100644 --- a/source/image.cpp +++ b/source/image.cpp @@ -76,15 +76,15 @@ void Image::rebuild_special(const Part &part) GL::MeshBuilder bld(part_cache.create_mesh(part, *image)); bld.color(1.0f, 1.0f, 1.0f); - bld.begin(GL::QUADS); + bld.begin(GL::TRIANGLE_STRIP); + bld.texcoord(0.0, 1.0); + bld.vertex(rgeom.x, rgeom.y+rgeom.h); bld.texcoord(0.0, 0.0); bld.vertex(rgeom.x, rgeom.y); - bld.texcoord(1.0, 0.0); - bld.vertex(rgeom.x+rgeom.w, rgeom.y); bld.texcoord(1.0, 1.0); bld.vertex(rgeom.x+rgeom.w, rgeom.y+rgeom.h); - bld.texcoord(0.0, 1.0); - bld.vertex(rgeom.x, rgeom.y+rgeom.h); + bld.texcoord(1.0, 0.0); + bld.vertex(rgeom.x+rgeom.w, rgeom.y); bld.end(); } } -- 2.45.2