3 #include <msp/graphics/simplewindow.h>
4 #include <msp/gl/capsule.h>
5 #include <msp/gl/framebuffer.h>
6 #include <msp/gl/light.h>
7 #include <msp/gl/lighting.h>
8 #include <msp/gl/material.h>
9 #include <msp/gl/matrix.h>
10 #include <msp/gl/mesh.h>
11 #include <msp/gl/meshbuilder.h>
12 #include <msp/gl/program.h>
13 #include <msp/gl/programdata.h>
14 #include <msp/gl/renderer.h>
15 #include <msp/gl/tests.h>
16 #include <msp/gl/texture2d.h>
17 #include <msp/gl/texturing.h>
18 #include <msp/time/timestamp.h>
19 #include <msp/time/utils.h>
20 #include <msp/time/units.h>
27 Graphics::SimpleGLWindow wnd(800, 800);
32 char *data = new char[256*256*3];
33 for(unsigned y=0; y<256; ++y)
34 for(unsigned x=0; x<256; ++x)
37 data[i] = ((x/16+y/16)&1 ? 255 : 128);
39 tex1.storage(GL::LUMINANCE, 256, 256);
40 tex1.set_min_filter(GL::LINEAR);
41 tex1.image(0, GL::LUMINANCE, GL::UNSIGNED_BYTE, data);
43 for(unsigned y=0; y<256; ++y)
44 for(unsigned x=0; x<256; ++x)
46 float yf = (y%16)/40.0-0.2;
47 float xf = (x%16)/40.0-0.2;
48 unsigned i = (x+y*256)*3;
49 float l = sqrt(xf*xf+yf*yf+1);
50 data[i] = static_cast<unsigned>((1+xf/l)*127);
51 data[i+1] = static_cast<unsigned>((1+yf/l)*127);
52 data[i+2] = static_cast<unsigned>((1+1/l)*127);
54 tex2.storage(GL::RGB, 256, 256);
55 tex2.set_min_filter(GL::LINEAR);
56 tex2.image(0, GL::RGB, GL::UNSIGNED_BYTE, data);
59 GL::Mesh mesh((GL::VERTEX3, GL::NORMAL3, GL::TEXCOORD2, GL::COLOR4_UBYTE, GL::TANGENT3, GL::BINORMAL3));
60 GL::MeshBuilder bld(mesh);
61 bld.color(0.5f, 1.0f, 0.0f);
62 GL::CapsuleBuilder(1, 0.72498, 32, 17).texture_fit(GL::GeometryBuilder::WRAP).tbn().build(bld);
64 mat.set_diffuse(GL::Color(0.5, 1.0, 0.0));
65 mat.set_specular(GL::Color(0.45, 0.5, 0.4));
66 mat.set_shininess(50);
67 vector<GL::Program *> programs;
68 for(unsigned i=0; i<12; ++i)
70 GL::ProgramBuilder::StandardFeatures feat;
71 feat.material = i/4>0;
73 feat.lighting = i%4>0;
74 feat.normalmap = i%4>1;
75 feat.specular = i%4>2;
76 programs.push_back(new GL::Program(feat));
79 GL::ProgramData progdata;
80 progdata.uniform("texture", 0);
81 progdata.uniform("normalmap", 1);
83 GL::Lighting lighting;
85 light.set_position(GL::Vector4(0, -0.781, 0.625, 0));
86 lighting.attach(0, light);
88 GL::Texturing texturing;
89 texturing.attach(0, tex1);
90 texturing.attach(1, tex2);
92 GL::MatrixStack::projection() = GL::Matrix::frustum(-0.1, 0.1, -0.1, 0.1, 0.2, 20);
93 GL::MatrixStack::modelview() = GL::Matrix::translation(0, 0, -10);
94 GL::MatrixStack::modelview() *= GL::Matrix::rotation_deg(85, -1, 0, 0);
101 wnd.get_display().tick();
102 GL::Framebuffer::system().clear(GL::COLOR_BUFFER_BIT|GL::DEPTH_BUFFER_BIT);
104 GL::Bind bind_depth(GL::DepthTest::lequal());
105 GL::Renderer renderer(0);
106 renderer.set_lighting(&lighting);
107 renderer.set_material(&mat);
108 renderer.set_texturing(&texturing);
109 renderer.add_shader_data(progdata);
110 for(unsigned i=0; i<12; ++i)
112 GL::Renderer::Push push(renderer);
113 renderer.set_shader_program(programs[i]);
114 renderer.transform(GL::Matrix::translation(-3.3+(i%4)*2.2, 0, -3.5+(i/4)*3.0));
115 renderer.transform(GL::Matrix::rotation(angle, 0, 0, 1));
120 Time::TimeStamp t = Time::now();
122 angle += 0.5*((t-last)/Time::sec);