Skip to content
Snippets Groups Projects
Verified Commit 6a3cd6de authored by Tóth Miklós Tibor's avatar Tóth Miklós Tibor :shrug:
Browse files

forog

parent 097b4c2a
No related branches found
No related tags found
No related merge requests found
...@@ -234,8 +234,8 @@ public: ...@@ -234,8 +234,8 @@ public:
bool shadowIntersect(Ray ray) { // for directional lights bool shadowIntersect(Ray ray) { // for directional lights
for (Intersectable * object : objects) { for (Intersectable * object : objects) {
Hit hit = object->intersect(ray); Hit hit = object->intersect(ray);
if (hit.t > 0) if (hit.t < 0)
if(hit.t < length(hit.position - ray.start)) if(hit.t > length(hit.position - ray.start))
return true; return true;
} }
return false; return false;
...@@ -296,10 +296,15 @@ const char *fragmentSource = R"( ...@@ -296,10 +296,15 @@ const char *fragmentSource = R"(
class FullScreenTexturedQuad { class FullScreenTexturedQuad {
unsigned int vao = 0; // vertex array object id and texture id unsigned int vao = 0; // vertex array object id and texture id
int wW, wH;
Texture texture; Texture texture;
public: public:
void loadImage(const std::vector<vec4>& image) {
texture.create(wW, wH, image);
}
FullScreenTexturedQuad(int windowWidth, int windowHeight, std::vector<vec4>& 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 glGenVertexArrays(1, &vao); // create 1 vertex array object
glBindVertexArray(vao); // make it active glBindVertexArray(vao); // make it active
...@@ -330,6 +335,7 @@ void onInitialization() { ...@@ -330,6 +335,7 @@ void onInitialization() {
scene.build(); scene.build();
std::vector<vec4> image(windowWidth * windowHeight); std::vector<vec4> image(windowWidth * windowHeight);
long timeStart = glutGet(GLUT_ELAPSED_TIME); long timeStart = glutGet(GLUT_ELAPSED_TIME);
scene.render(image); scene.render(image);
long timeEnd = glutGet(GLUT_ELAPSED_TIME); long timeEnd = glutGet(GLUT_ELAPSED_TIME);
...@@ -344,6 +350,15 @@ void onInitialization() { ...@@ -344,6 +350,15 @@ void onInitialization() {
// Window has become invalid: Redraw // Window has become invalid: Redraw
void onDisplay() { 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(); fullScreenTexturedQuad->Draw();
glutSwapBuffers(); // exchange the two buffers glutSwapBuffers(); // exchange the two buffers
} }
...@@ -367,4 +382,6 @@ void onMouseMotion(int pX, int pY) { ...@@ -367,4 +382,6 @@ void onMouseMotion(int pX, int pY) {
// Idle event indicating that some time elapsed: do animation here // Idle event indicating that some time elapsed: do animation here
void onIdle() { void onIdle() {
scene.Animate(.1f);
glutPostRedisplay();
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment