+++ /dev/null
-#include <cstdlib>
-#include <msp/gl/box.h>
-#include <msp/gl/cylinder.h>
-#include <msp/gl/framebuffer.h>
-#include <msp/gl/light.h>
-#include <msp/gl/lighting.h>
-#include <msp/gl/material.h>
-#include <msp/gl/mesh.h>
-#include <msp/gl/meshbuilder.h>
-#include <msp/gl/program.h>
-#include <msp/gl/programdata.h>
-#include <msp/gl/renderer.h>
-#include <msp/gl/tests.h>
-#include <msp/gl/texturecube.h>
-#include <msp/graphics/simplewindow.h>
-
-using namespace Msp;
-
-void create_face_texture(GL::TextureCube &texture, GL::TextureCubeFace face)
-{
- unsigned char *pixels = new unsigned char[128*128*3];
- for(int y=0; y<128; ++y)
- for(int x=0; x<128; ++x)
- {
- unsigned i = (x+y*128)*3;
- GL::Vector3 v = texture.get_texel_direction(face, x, y);
- if(v.y>0)
- {
- pixels[i] = 96-48*v.y;
- pixels[i+1] = 168-84*v.y;
- pixels[i+2] = 255;
- }
- else
- {
- pixels[i] = rand()%32;
- pixels[i+1] = 128-rand()%32;
- pixels[i+2] = rand()%32;
- }
- }
- texture.image(face, 0, GL::RGB, GL::UNSIGNED_BYTE, pixels);
- delete[] pixels;
-}
-
-int main()
-{
- Graphics::SimpleGLWindow window(600, 400);
-
- GL::TextureCube texture;
- texture.storage(GL::RGB, 128);
- texture.set_min_filter(GL::LINEAR);
- texture.set_wrap(GL::CLAMP_TO_EDGE);
- for(unsigned i=0; i<6; ++i)
- create_face_texture(texture, texture.enumerate_faces(i));
-
- GL::Mesh skybox((GL::VERTEX3, GL::TEXCOORD3));
- GL::BoxBuilder(10, 10, 10).build(skybox);
- for(unsigned i=0; i<skybox.get_n_vertices(); ++i)
- {
- float *v = skybox.modify_vertex(i);
- for(unsigned j=0; j<3; ++j)
- v[3+j] = v[j];
- }
-
- GL::Mesh box((GL::VERTEX3, GL::NORMAL3));
- GL::BoxBuilder(2, 2, 2).build(box);
-
- GL::Mesh cylinder((GL::VERTEX3, GL::NORMAL3));
- GL::CylinderBuilder(1, 2, 32).build(cylinder);
-
- GL::Lighting lighting;
- lighting.set_ambient(GL::Color(0.3));
- GL::Light light0;
- light0.set_diffuse(GL::Color(0.6));
- light0.set_position(GL::Vector4(-1, 1, 1, 0));
- lighting.attach(0, light0);
- GL::Light light1;
- light1.set_diffuse(GL::Color(0.2));
- light1.set_position(GL::Vector4(1, 1, 0, 0));
- lighting.attach(1, light1);
-
- GL::Material material;
- material.set_diffuse(GL::Color(0.4));
- material.set_ambient(GL::Color(0.4));
- material.set_specular(GL::Color(1.0));
- material.set_shininess(100);
-
- GL::ProgramBuilder::StandardFeatures features;
- features.lighting = true;
- features.specular = true;
- features.material = true;
- features.reflection = true;
- GL::Program shprog(features);
- GL::ProgramData shdata;
- shdata.uniform("environment", 0);
- shdata.uniform("reflectivity", 0.5f);
- float env_mat[9] = { 1, 0, 0, 0, 1, 0, 0, 0, 1 };
- shdata.uniform_matrix3("env_eye_matrix", env_mat);
-
- GL::MatrixStack::projection() = GL::Matrix::frustum_centered(0.15, 0.1, 0.1, 10);
-
- window.show();
- float angle = 0;
- while(1)
- {
- window.tick();
- GL::Framebuffer::system().clear(GL::COLOR_BUFFER_BIT|GL::DEPTH_BUFFER_BIT);
- {
- GL::Renderer renderer(0);
- renderer.set_texture(&texture);
- skybox.draw(renderer);
- }
- {
- GL::Bind bind_light(lighting);
- GL::Bind bind_depth(GL::DepthTest::lequal());
- GL::Renderer renderer(0);
- renderer.set_material(&material);
- renderer.set_shader_program(&shprog, &shdata);
- renderer.set_texture(&texture);
- renderer.transform(GL::Matrix::translation(0, 0, -7));
- {
- GL::Renderer::Push _push(renderer);
- renderer.transform(GL::Matrix::translation(-2, 0, 0));
- renderer.transform(GL::Matrix::rotation(angle/2.3, 0, 1, 0));
- renderer.transform(GL::Matrix::rotation(angle, 1, 0.25, 0));
- box.draw(renderer);
- }
- {
- GL::Renderer::Push _push(renderer);
- renderer.transform(GL::Matrix::translation(2, 0, 0));
- renderer.transform(GL::Matrix::rotation(-angle/2.3, 0, 1, 0));
- renderer.transform(GL::Matrix::rotation(angle, 1, 0.25, 0));
- cylinder.draw(renderer);
- }
- }
- window.swap_buffers();
- angle += 0.0001;
- }
-
- return 0;
-}
+++ /dev/null
-#include <vector>
-#include <cmath>
-#include <msp/graphics/simplewindow.h>
-#include <msp/gl/capsule.h>
-#include <msp/gl/framebuffer.h>
-#include <msp/gl/light.h>
-#include <msp/gl/lighting.h>
-#include <msp/gl/material.h>
-#include <msp/gl/matrix.h>
-#include <msp/gl/mesh.h>
-#include <msp/gl/meshbuilder.h>
-#include <msp/gl/program.h>
-#include <msp/gl/programdata.h>
-#include <msp/gl/renderer.h>
-#include <msp/gl/tests.h>
-#include <msp/gl/texture2d.h>
-#include <msp/gl/texturing.h>
-#include <msp/time/timestamp.h>
-#include <msp/time/timedelta.h>
-#include <msp/time/utils.h>
-
-using namespace std;
-using namespace Msp;
-
-int main()
-{
- Graphics::SimpleGLWindow wnd(800, 800);
-
- GL::Texture2D tex1;
- GL::Texture2D tex2;
-
- char *data = new char[256*256*3];
- for(unsigned y=0; y<256; ++y)
- for(unsigned x=0; x<256; ++x)
- {
- unsigned i = x+y*256;
- data[i] = ((x/16+y/16)&1 ? 255 : 128);
- }
- tex1.storage(GL::LUMINANCE, 256, 256);
- tex1.set_min_filter(GL::LINEAR);
- tex1.image(0, GL::LUMINANCE, GL::UNSIGNED_BYTE, data);
-
- for(unsigned y=0; y<256; ++y)
- for(unsigned x=0; x<256; ++x)
- {
- float yf = (y%16)/40.0-0.2;
- float xf = (x%16)/40.0-0.2;
- unsigned i = (x+y*256)*3;
- float l = sqrt(xf*xf+yf*yf+1);
- data[i] = static_cast<unsigned>((1+xf/l)*127);
- data[i+1] = static_cast<unsigned>((1+yf/l)*127);
- data[i+2] = static_cast<unsigned>((1+1/l)*127);
- }
- tex2.storage(GL::RGB, 256, 256);
- tex2.set_min_filter(GL::LINEAR);
- tex2.image(0, GL::RGB, GL::UNSIGNED_BYTE, data);
- delete[] data;
-
- GL::Mesh mesh((GL::VERTEX3, GL::NORMAL3, GL::TEXCOORD2, GL::COLOR4_UBYTE, GL::TANGENT3, GL::BINORMAL3));
- GL::MeshBuilder bld(mesh);
- bld.color(0.5f, 1.0f, 0.0f);
- GL::CapsuleBuilder(1, 0.72498, 32, 17).texture_fit(GL::GeometryBuilder::WRAP).tbn().build(bld);
- GL::Material mat;
- mat.set_diffuse(GL::Color(0.5, 1.0, 0.0));
- mat.set_specular(GL::Color(0.45, 0.5, 0.4));
- mat.set_shininess(50);
- vector<GL::Program *> programs;
- for(unsigned i=0; i<12; ++i)
- {
- GL::ProgramBuilder::StandardFeatures feat;
- feat.material = i/4>0;
- feat.texture = i/4>1;
- feat.lighting = i%4>0;
- feat.normal_map = i%4>1;
- feat.specular = i%4>2;
- programs.push_back(new GL::Program(feat));
- }
-
- GL::ProgramData progdata;
- progdata.uniform("texture", 0);
- progdata.uniform("normalmap", 1);
-
- GL::Lighting lighting;
- GL::Light light;
- light.set_position(GL::Vector4(0, -0.781, 0.625, 0));
- lighting.attach(0, light);
-
- GL::Texturing texturing;
- texturing.attach(0, tex1);
- texturing.attach(1, tex2);
-
- GL::MatrixStack::projection() = GL::Matrix::frustum(-0.1, 0.1, -0.1, 0.1, 0.2, 20);
- GL::MatrixStack::modelview() = GL::Matrix::translation(0, 0, -10);
- GL::MatrixStack::modelview() *= GL::Matrix::rotation_deg(85, -1, 0, 0);
-
- wnd.show();
- float angle = 0.0;
- Time::TimeStamp last;
- while(1)
- {
- wnd.get_display().tick();
- GL::Framebuffer::system().clear(GL::COLOR_BUFFER_BIT|GL::DEPTH_BUFFER_BIT);
- {
- GL::Bind bind_depth(GL::DepthTest::lequal());
- GL::Renderer renderer(0);
- renderer.set_lighting(&lighting);
- renderer.set_material(&mat);
- renderer.set_texturing(&texturing);
- renderer.add_shader_data(progdata);
- for(unsigned i=0; i<12; ++i)
- {
- GL::Renderer::Push push(renderer);
- renderer.set_shader_program(programs[i]);
- renderer.transform(GL::Matrix::translation(-3.3+(i%4)*2.2, 0, -3.5+(i/4)*3.0));
- renderer.transform(GL::Matrix::rotation(angle, 0, 0, 1));
- mesh.draw(renderer);
- }
- }
- wnd.swap_buffers();
- Time::TimeStamp t = Time::now();
- if(last)
- angle += 0.5*((t-last)/Time::sec);
- last = t;
- }
-
- return 0;
-}