From: Mikko Rasa Date: Mon, 13 Aug 2012 21:26:40 +0000 (+0300) Subject: Make the cubemap demo more interesting X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=e87e7a542c2b9fcde1676ba17387fcfb5180f196;p=libs%2Fgl.git Make the cubemap demo more interesting It now displays two different shapes, which have reflections through an environment map. The same environment map is used to render a skybox. Also uses the new direction lookup functions to create the contents for the cube map texture. --- diff --git a/demos/cubemap.cpp b/demos/cubemap.cpp index b3de5a12..4f663055 100644 --- a/demos/cubemap.cpp +++ b/demos/cubemap.cpp @@ -1,10 +1,14 @@ +#include #include +#include #include #include #include #include #include #include +#include +#include #include #include #include @@ -15,13 +19,23 @@ using namespace Msp; void create_face_texture(GL::TextureCube &texture, GL::TextureCubeFace face) { unsigned char *pixels = new unsigned char[128*128*3]; - for(unsigned y=0; y<128; ++y) - for(unsigned x=0; x<128; ++x) + for(int y=0; y<128; ++y) + for(int x=0; x<128; ++x) { unsigned i = (x+y*128)*3; - pixels[i] = (face==GL::NEGATIVE_X ? 0 : face==GL::POSITIVE_X ? 255 : face==GL::NEGATIVE_Z ? 255-x*2 : x*2); - pixels[i+1] = (face==GL::NEGATIVE_Y ? 0 : face==GL::POSITIVE_Y ? 255 : 255-y*2); - pixels[i+2] = (face==GL::NEGATIVE_Z ? 0 : face==GL::POSITIVE_Z ? 255 : face==GL::POSITIVE_X ? 255-x*2 : face==GL::NEGATIVE_X ? x*2 : face==GL::NEGATIVE_Y ? 255-y*2 : y*2); + 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; @@ -29,29 +43,30 @@ void create_face_texture(GL::TextureCube &texture, GL::TextureCubeFace face) int main() { - Graphics::SimpleGLWindow window(400, 400); + 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); - create_face_texture(texture, GL::NEGATIVE_Z); - create_face_texture(texture, GL::POSITIVE_Z); - create_face_texture(texture, GL::NEGATIVE_Y); - create_face_texture(texture, GL::POSITIVE_Y); - create_face_texture(texture, GL::NEGATIVE_X); - create_face_texture(texture, GL::POSITIVE_X); + for(unsigned i=0; i<6; ++i) + create_face_texture(texture, texture.enumerate_faces(i)); - GL::Mesh box((GL::VERTEX3, GL::TEXCOORD3, GL::NORMAL3)); - GL::MeshBuilder builder(box); - GL::BoxBuilder(2, 2, 2).build(builder); - for(unsigned i=0; i