diff --git a/Skeleton.cpp b/Skeleton.cpp index 1e496a6a13909a5c137d437fe8a38ddfb8ff7ad9..63829ab53814234644cafb5c68b086db1623c35b 100644 --- a/Skeleton.cpp +++ b/Skeleton.cpp @@ -234,8 +234,8 @@ public: bool shadowIntersect(Ray ray) { // for directional lights for (Intersectable * object : objects) { Hit hit = object->intersect(ray); - if (hit.t > 0) - if(hit.t < length(hit.position - ray.start)) + if (hit.t < 0) + if(hit.t > length(hit.position - ray.start)) return true; } return false; @@ -296,10 +296,15 @@ const char *fragmentSource = R"( class FullScreenTexturedQuad { unsigned int vao = 0; // vertex array object id and texture id + int wW, wH; Texture texture; public: + void loadImage(const std::vector<vec4>& image) { + texture.create(wW, wH, image); + } + FullScreenTexturedQuad(int windowWidth, int windowHeight, std::vector<vec4>& image) - : texture(windowWidth, windowHeight, image) + : wW(windowWidth), wH(windowHeight), texture(windowWidth, windowHeight, image) { glGenVertexArrays(1, &vao); // create 1 vertex array object glBindVertexArray(vao); // make it active @@ -328,22 +333,32 @@ FullScreenTexturedQuad * fullScreenTexturedQuad; void onInitialization() { glViewport(0, 0, windowWidth, windowHeight); scene.build(); - - std::vector<vec4> image(windowWidth * windowHeight); - long timeStart = glutGet(GLUT_ELAPSED_TIME); - scene.render(image); - long timeEnd = glutGet(GLUT_ELAPSED_TIME); - printf("Rendering time: %d milliseconds\n", (timeEnd - timeStart)); - - // copy image to GPU as a texture - fullScreenTexturedQuad = new FullScreenTexturedQuad(windowWidth, windowHeight, image); - + + std::vector<vec4> image(windowWidth * windowHeight); + + long timeStart = glutGet(GLUT_ELAPSED_TIME); + scene.render(image); + long timeEnd = glutGet(GLUT_ELAPSED_TIME); + printf("Rendering time: %d milliseconds\n", (timeEnd - timeStart)); + + // copy image to GPU as a texture + fullScreenTexturedQuad = new FullScreenTexturedQuad(windowWidth, windowHeight, image); + // create program for the GPU gpuProgram.create(vertexSource, fragmentSource, "fragmentColor"); } // Window has become invalid: Redraw void onDisplay() { + std::vector<vec4> image(windowWidth * windowHeight); + + long timeStart = glutGet(GLUT_ELAPSED_TIME); + scene.render(image); + long timeEnd = glutGet(GLUT_ELAPSED_TIME); + printf("Rendering time: %d milliseconds\n", (timeEnd - timeStart)); + + fullScreenTexturedQuad->loadImage(image); + fullScreenTexturedQuad->Draw(); glutSwapBuffers(); // exchange the two buffers } @@ -367,4 +382,6 @@ void onMouseMotion(int pX, int pY) { // Idle event indicating that some time elapsed: do animation here void onIdle() { + scene.Animate(.1f); + glutPostRedisplay(); }