]> git.tdb.fi Git - libs/gltk.git/blobdiff - source/graphic.cpp
Use triangle strips instead of quads
[libs/gltk.git] / source / graphic.cpp
index 0b0ba0e6ef055ee23251b3b40338479f34674a65..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
@@ -73,8 +78,7 @@ void Graphic::create_texcoords(float low, float high, float brd1, float brd2, fl
 
 
 Graphic::Loader::Loader(Graphic &g, Resources &r):
-       graph(g),
-       res(r)
+       DataFile::CollectionObjectLoader<Graphic, Resources>(g, &r)
 {
        add("texture", &Loader::texture);
        add("slice",   &Loader::slice);
@@ -85,23 +89,23 @@ Graphic::Loader::Loader(Graphic &g, Resources &r):
 
 void Graphic::Loader::texture(const string &n)
 {
-       graph.texture = &res.get<GL::Texture2D>(n);
-       graph.slice = Geometry(0, 0, graph.texture->get_width(), graph.texture->get_height());
+       obj.texture = &get_collection().get<GL::Texture2D>(n);
+       obj.slice = Geometry(0, 0, obj.texture->get_width(), obj.texture->get_height());
 }
 
 void Graphic::Loader::slice(unsigned x, unsigned y, unsigned w, unsigned h)
 {
-       graph.slice = Geometry(x, y, w, h);
+       obj.slice = Geometry(x, y, w, h);
 }
 
 void Graphic::Loader::border()
 {
-       load_sub(graph.border);
+       load_sub(obj.border);
 }
 
 void Graphic::Loader::shadow()
 {
-       load_sub(graph.shadow);
+       load_sub(obj.shadow);
 }
 
 } // namespace GLtk