From: Mikko Rasa <tdb@tdb.fi>
Date: Thu, 13 Nov 2014 20:52:18 +0000 (+0200)
Subject: Use triangle strips instead of quads
X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=b3234ca0277c5e282a2a0a2558b58edb25750653;p=libs%2Fgltk.git

Use triangle strips instead of quads
---

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 && j<x.size()-2))
+			{
+				if(j>xmin)
+					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<float> &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();
 	}
 }