1 #include <msp/gl/immediate.h>
14 void Graphic::render(unsigned wd, unsigned ht) const
21 x[0]=0.0f-shadow.left;
22 x[1]=x[0]+border.left;
24 x[2]=x[3]-border.right;
26 y[0]=0.0f-shadow.bottom;
27 y[1]=y[0]+border.bottom;
31 const unsigned twidth=texture->get_width();
32 u[0]=static_cast<float>(slice.x)/twidth;
33 u[1]=static_cast<float>(slice.x+border.left)/twidth;
34 u[2]=static_cast<float>(slice.x+slice.w-border.right)/twidth;
35 u[3]=static_cast<float>(slice.x+slice.w)/twidth;
37 const unsigned theight=texture->get_height();
38 v[0]=static_cast<float>(slice.y)/theight;
39 v[1]=static_cast<float>(slice.y+border.bottom)/theight;
40 v[2]=static_cast<float>(slice.y+slice.h-border.top)/theight;
41 v[3]=static_cast<float>(slice.y+slice.h)/theight;
44 unsigned xmin=border.left ? 0 : 1;
45 unsigned xmax=border.right ? 3 : 2;
46 unsigned ymin=border.bottom ? 0 : 1;
47 unsigned ymax=border.top ? 3 : 2;
49 GL::Immediate imm((GL::TEXCOORD2,GL::VERTEX2));
50 for(unsigned i=ymin; i<ymax; ++i)
52 imm.begin(GL::QUAD_STRIP);
53 for(unsigned j=xmin; j<=xmax; ++j)
55 imm.texcoord(u[j], v[i]);
56 imm.vertex(x[j], y[i]);
57 imm.texcoord(u[j], v[i+1]);
58 imm.vertex(x[j], y[i+1]);
65 Graphic::Loader::Loader(Graphic &g, Resources &r):
69 add("texture", &Loader::texture);
70 add("slice", &Loader::slice);
71 add("border", &Loader::border);
72 add("shadow", &Loader::shadow);
75 void Graphic::Loader::texture(const string &n)
77 graph.texture=&res.get<GL::Texture2D>(n);
78 graph.slice=Geometry(0, 0, graph.texture->get_width(), graph.texture->get_height());
81 void Graphic::Loader::slice(unsigned x, unsigned y, unsigned w, unsigned h)
83 graph.slice=Geometry(x, y, w, h);
86 void Graphic::Loader::border()
88 load_sub(graph.border);
91 void Graphic::Loader::shadow()
93 load_sub(graph.shadow);