X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=blobdiff_plain;f=demos%2Fshaders.cpp;h=44d0b440795cad881dc8f4c6cad7916f96a070c9;hp=1b9c64724f78bd394ab9051458bfcfe496136d63;hb=HEAD;hpb=01d2500733766710f4a11f49216a5b3dcc75a4a3 diff --git a/demos/shaders.cpp b/demos/shaders.cpp deleted file mode 100644 index 1b9c6472..00000000 --- a/demos/shaders.cpp +++ /dev/null @@ -1,134 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -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((1+xf/l)*127); - data[i+1] = static_cast((1+yf/l)*127); - data[i+2] = static_cast((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::ATTRIB3,4, GL::ATTRIB3,5)); - GL::MeshBuilder bld(mesh); - bld.color(0.5f, 1.0f, 0.0f); - GL::CapsuleBuilder(1, 0.72498, 32, 17).texture_fit(GL::GeometryBuilder::WRAP).tangent(4).binormal(5).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 programs; - for(unsigned i=0; i<12; ++i) - { - GL::Program::StandardFeatures feat; - feat.material = i/4>0; - feat.texture = i/4>1; - feat.lighting = i%4>0; - feat.normalmap = i%4>1; - feat.specular = i%4>2; - programs.push_back(new GL::Program(feat)); - if(feat.normalmap) - { - programs.back()->bind_attribute(4, "tangent"); - programs.back()->bind_attribute(5, "binormal"); - programs.back()->link(); - } - } - - GL::ProgramData progdata; - progdata.uniform("texture", 0); - progdata.uniform("normalmap", 1); - - GL::Lighting lighting; - GL::Light light; - light.set_position(GL::Vector4(0, 2, 3, 0)); - lighting.attach(0, light); - - GL::Bind bind_light(lighting); - - 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_material(&mat); - renderer.set_texturing(&texturing); - renderer.add_shader_data(progdata); - for(unsigned i=0; i<12; ++i) - { - GL::MatrixStack::Push push(renderer.matrix_stack()); - renderer.set_shader_program(programs[i]); - renderer.matrix_stack() *= GL::Matrix::translation(-3.3+(i%4)*2.2, 0, -3.5+(i/4)*3.0); - renderer.matrix_stack() *= 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; -}