2 #include <msp/graphics/simplewindow.h>
3 #include <msp/gl/framebuffer.h>
4 #include <msp/gl/matrix.h>
5 #include <msp/gl/mesh.h>
6 #include <msp/gl/meshbuilder.h>
7 #include <msp/gl/projection.h>
8 #include <msp/gl/texenv.h>
9 #include <msp/gl/texture2d.h>
10 #include <msp/gl/texturing.h>
11 #include <msp/time/timestamp.h>
12 #include <msp/time/utils.h>
13 #include <msp/time/units.h>
19 Graphics::SimpleGLWindow wnd(400, 400);
24 unsigned char *data = new unsigned char[256*256*4];
25 for(unsigned y=0; y<256; ++y)
26 for(unsigned x=0; x<256; ++x)
28 unsigned i = (x+y*256)*3;
30 data[i+1] = (((x/32)+(y/32))&1 ? 255 : 0);
33 tex1.storage(GL::RGB, 256, 256);
34 tex1.set_min_filter(GL::LINEAR);
35 tex1.image(0, GL::RGB, GL::UNSIGNED_BYTE, data);
37 for(unsigned y=0; y<256; ++y)
38 for(unsigned x=0; x<256; ++x)
40 unsigned i = (x+y*256)*4;
41 data[i] = data[i+1] = data[i+2] = 0;
42 data[i+3] = (((x/32)+(y/32))&1 ? 255 : 0);
44 tex2.storage(GL::RGBA, 256, 256);
45 tex2.set_min_filter(GL::LINEAR);
46 tex2.image(0, GL::RGBA, GL::UNSIGNED_BYTE, data);
49 GL::Texturing texturing;
50 texturing.attach(0, tex1);
52 texenv.set_mode(GL::DECAL);
53 texturing.attach(1, tex2, texenv);
55 GL::MatrixStack::projection() = GL::Matrix::frustum_centered(0.2, 0.2, 0.2, 10);
56 GL::MatrixStack::modelview() = GL::Matrix::translation(0, 0, -3);
57 GL::MatrixStack::modelview() *= GL::Matrix::rotation(-45, 1, 0, 0);
59 GL::Mesh mesh((GL::TEXCOORD2, GL::TEXCOORD2,1, GL::VERTEX3));
60 GL::MeshBuilder bld(mesh);
63 bld.multitexcoord(1, -0.2071, 0.5);
66 bld.multitexcoord(1, 0.5, -0.2071);
69 bld.multitexcoord(1, 1.2071, 0.5);
72 bld.multitexcoord(1, 0.5, 1.2071);
81 for(unsigned i=0; i<4; ++i)
83 float *v = mesh.modify_vertex(i);
84 v[2] = 0.5+sin(angle)*0.1+cos(angle+i*M_PI/2)*0.7071;
85 v[3] = 0.5+cos(angle)*0.1+sin(angle+i*M_PI/2)*0.7071;
87 wnd.get_display().tick();
88 GL::Framebuffer::system().clear(GL::COLOR_BUFFER_BIT);
90 GL::Bind bind_tex(texturing);
94 Time::TimeStamp t = Time::now();
96 angle += 0.5*((t-last)/Time::sec);