]> git.tdb.fi Git - libs/gltk.git/blobdiff - source/graphic.cpp
Derive Resources from DataFile::Collection
[libs/gltk.git] / source / graphic.cpp
index d05123ab890f0f342f858840f97f82cc4e68a6c0..3579610bf7a640696e4f97bbf928f828b252168f 100644 (file)
@@ -1,16 +1,13 @@
+#include <msp/gl/immediate.h>
 #include "graphic.h"
 #include "resources.h"
 
 using namespace std;
 
-#include <iostream>
-
 namespace Msp {
 namespace GLtk {
 
-Graphic::Graphic(const Resources &r, const string &n):
-       res(r),
-       name(n),
+Graphic::Graphic():
        texture(0)
 { }
 
@@ -49,23 +46,25 @@ void Graphic::render(unsigned wd, unsigned ht) const
        unsigned ymin=border.bottom ? 0 : 1;
        unsigned ymax=border.top ? 3 : 2;
 
+       GL::Immediate imm((GL::TEXCOORD2,GL::VERTEX2));
        for(unsigned i=ymin; i<ymax; ++i)
        {
-               glBegin(GL_QUAD_STRIP);
+               imm.begin(GL::QUAD_STRIP);
                for(unsigned j=xmin; j<=xmax; ++j)
                {
-                       glTexCoord2f(u[j], v[i]);
-                       glVertex2f(x[j], y[i]);
-                       glTexCoord2f(u[j], v[i+1]);
-                       glVertex2f(x[j], y[i+1]);
+                       imm.texcoord(u[j], v[i]);
+                       imm.vertex(x[j], y[i]);
+                       imm.texcoord(u[j], v[i+1]);
+                       imm.vertex(x[j], y[i+1]);
                }
-               glEnd();
+               imm.end();
        }
 }
 
 
-Graphic::Loader::Loader(Graphic &g):
-       graph(g)
+Graphic::Loader::Loader(Graphic &g, Resources &r):
+       graph(g),
+       res(r)
 {
        add("texture", &Loader::texture);
        add("slice",   &Loader::slice);
@@ -75,7 +74,7 @@ Graphic::Loader::Loader(Graphic &g):
 
 void Graphic::Loader::texture(const string &n)
 {
-       graph.texture=&graph.res.get_texture(n);
+       graph.texture=&res.get<GL::Texture2D>(n);
        graph.slice=Geometry(0, 0, graph.texture->get_width(), graph.texture->get_height());
 }