X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;ds=sidebyside;f=source%2Fgraphic.cpp;h=fb3f8893d2460112b88d0b71a6ce6c9790c92b61;hb=aa9b8db38efb9e97460c76e27cecc4d1591b23e5;hp=0b0ba0e6ef055ee23251b3b40338479f34674a65;hpb=1aa6cd9b865e366737dcc9d2d36c4f8faed5bc4f;p=libs%2Fgltk.git diff --git a/source/graphic.cpp b/source/graphic.cpp index 0b0ba0e..fb3f889 100644 --- a/source/graphic.cpp +++ b/source/graphic.cpp @@ -6,11 +6,6 @@ using namespace std; namespace Msp { namespace GLtk { -Graphic::Graphic(): - texture(0), - repeat(false) -{ } - void Graphic::build(unsigned wd, unsigned ht, GL::PrimitiveBuilder &bld) const { vector x, y; @@ -21,30 +16,35 @@ void Graphic::build(unsigned wd, unsigned ht, GL::PrimitiveBuilder &bld) const create_texcoords(slice.x, slice.x+slice.w, border.left, border.right, texture->get_width(), u); create_texcoords(slice.y, slice.y+slice.h, border.bottom, border.top, texture->get_height(), v); - unsigned xmin = border.left ? 0 : 1; - unsigned xmax = x.size()-(border.right ? 2 : 3); - unsigned ymin = border.bottom ? 0 : 1; - unsigned ymax = y.size()-(border.top ? 2 : 3); + size_t xmin = border.left ? 0 : 1; + size_t xmax = x.size()-(border.right ? 2 : 3); + size_t ymin = border.bottom ? 0 : 1; + size_t 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) + for(size_t i=ymin; i<=ymax; ++i) { - unsigned i2 = (i==0 ? 0 : i==y.size()-2 ? 2 : 1); - for(unsigned j=xmin; j<=xmax; ++j) + size_t i2 = (i==0 ? 0 : i==y.size()-2 ? 2 : 1); + for(size_t 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]); + size_t j2 = (j==0 ? 0 : j==x.size()-2 ? 2 : 1); + 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 @@ -73,8 +73,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(g, &r) { add("texture", &Loader::texture); add("slice", &Loader::slice); @@ -85,23 +84,23 @@ Graphic::Loader::Loader(Graphic &g, Resources &r): void Graphic::Loader::texture(const string &n) { - graph.texture = &res.get(n); - graph.slice = Geometry(0, 0, graph.texture->get_width(), graph.texture->get_height()); + obj.texture = &get_collection().get(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