Reflection
[opengl.git] / main.cpp
index 613d67914eb7f943efa4fb50515f774fffbd9d32..4dd4e605963d7be0cc169e9fbeb92028baa2e30a 100644 (file)
--- a/main.cpp
+++ b/main.cpp
@@ -23,7 +23,7 @@ using namespace std;
 
 GLuint lightVao;
 
-Program *textureProg, *plainProg;
+Program *textureProg, *plainProg, *reflectProg;
 Skybox *skybox;
                          
 glm::vec3 camPos   = glm::vec3(0.0f, 0.0f,  0.0f);
@@ -31,8 +31,8 @@ glm::vec3 camFront = glm::vec3(0.0f, 0.0f, 1.0f);
 glm::vec3 camUp    = glm::vec3(0.0f, 1.0f,  0.0f);
 float yaw = 1.57, pitch = 0;
 bool doScale, doRotate, doTranslate;
-Model *chest;
-glm::vec3 lightPos(0);
+Model *chest, *mirrorCube;
+glm::vec3 lightPos(3);
 
 const int WIDTH = 800, HEIGHT = 600;
 const float ASPECT = (float)WIDTH / (float)HEIGHT;
@@ -88,8 +88,6 @@ void display() {
        glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
        float d = (float)glutGet(GLUT_ELAPSED_TIME) * 0.001f;
 
-       skybox->draw(projMat(), viewMat());
-
        glm::vec4 lightColor(1, 1, 1, 1);
 
        drawLight(d, lightPos, lightColor);
@@ -98,10 +96,10 @@ void display() {
        setProjectionAndViewUniforms(textureProg->progId);
        setLightColorAndPos(textureProg->progId, lightPos, lightColor);
 
-       Model::Node *top = chest->find("top");
-       top->model = glm::translate(glm::mat4(1), glm::vec3(0, 1, -1));
-       top->model = glm::rotate(top->model, sin(d / 2.5f) * 0.5f, glm::vec3(1, 0, 0));
-       top->model = glm::translate(top->model, glm::vec3(0, -1, 1));
+       /* Model::Node *top = chest->find("top"); */
+       /* top->model = glm::translate(glm::mat4(1), glm::vec3(0, 1, -1)); */
+       /* top->model = glm::rotate(top->model, sin(d / 2.5f) * 0.5f, glm::vec3(1, 0, 0)); */
+       /* top->model = glm::translate(top->model, glm::vec3(0, -1, 1)); */
        
        /* Model::Node *jewels = chest->find("jewels"); */
        /* jewels->model = glm::scale(glm::mat4(1), glm::vec3((sin(d) + 1.2f) / 2.f)); */
@@ -114,8 +112,11 @@ void display() {
        /* Model::Node *key = chest->find("key"); */
        /* key->model = glm::translate(glm::mat4(1), glm::vec3(0, 0, sin(d))); */
        
-       /* chest->getRoot()->model = glm::translate(glm::mat4(1), lightPos); */
-       chest->draw();
+       /* chest->draw(); */
+
+       mirrorCube->draw();
+
+       skybox->draw(projMat(), viewMat());
 
        glutSwapBuffers();
 }
@@ -136,29 +137,11 @@ void setupLightBuffers(GLuint progId) {
        glVertexAttribPointer(posLoc, 3, GL_FLOAT, GL_FALSE, 0, 0);
 }
 
-void validateProgram(GLuint progId) {
-       glValidateProgram(progId);
-       
-       GLint success;
-       glGetProgramiv(progId, GL_VALIDATE_STATUS, &success);
-       if (!success) {
-               GLchar log[1024];
-               glGetProgramInfoLog(progId, sizeof(log), NULL, log);
-               fprintf(stderr, "error: %s\n", log);
-               exit(1);
-       }
-}
-
 void init() {
        plainProg = new Program("plainvertex.glsl", "plainfrag.glsl");
        glUseProgram(plainProg->progId);
        setupLightBuffers(plainProg->progId);
-       validateProgram(plainProg->progId);
-
-       textureProg = new Program("texturevertex.glsl", "texturefrag.glsl");
-       glUseProgram(textureProg->progId);
-
-       chest = new Model("models/chest.dae", *textureProg);
+       plainProg->validate();
 
        std::vector<std::string> faces = {
                "models/skybox/right.jpg",
@@ -170,6 +153,11 @@ void init() {
        };
        skybox = new Skybox(faces);
 
+       textureProg = new Program("texturevertex.glsl", "texturefrag.glsl");
+       /* chest = new Model("models/chest.dae", *textureProg, *skybox); */
+
+       mirrorCube = new Model("models/mirrorCube.dae", *textureProg, *skybox);
+
        glEnable(GL_DEPTH_TEST); 
        glEnable(GL_CULL_FACE); 
 }