]> git.tdb.fi Git - libs/gltk.git/commitdiff
Use triangle strips instead of quads
authorMikko Rasa <tdb@tdb.fi>
Thu, 13 Nov 2014 20:52:18 +0000 (22:52 +0200)
committerMikko Rasa <tdb@tdb.fi>
Thu, 13 Nov 2014 20:52:18 +0000 (22:52 +0200)
source/button.cpp
source/graphic.cpp
source/image.cpp

index 57e5fa42f57981cfb3398576b5a6563b3d5b4843..86b73c9daa0c3f8ba9a689ebf628f102667c97f7 100644 (file)
@@ -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();
                }
        }
index 5fc27ef3d153e5c2061ff5e891bab10a2eea5f0c..75e10888ecde2eebef7202659aaf21320520fba8 100644 (file)
@@ -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
index 5dcb2e3f5b84b8e727a98b3aa6180c3642b35a24..f1180c39e1664491fd239560d59f251b8194074a 100644 (file)
@@ -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();
        }
 }