diff --git a/includes/Window.hpp b/includes/Window.hpp index 1f3d53a..f28efbe 100644 --- a/includes/Window.hpp +++ b/includes/Window.hpp @@ -26,7 +26,7 @@ class Window GLFWwindow *getWindow(void) const; RT::Vec2i getMousePos(void) const; - + float getFps(void) const; void display(); void pollEvents(); @@ -40,6 +40,8 @@ class Window GLFWwindow *_window; RT::Vec2i _mousePos; + float _fps; + }; #endif \ No newline at end of file diff --git a/shaders/frag.frag b/shaders/frag.frag index f451bd0..c09c17d 100644 --- a/shaders/frag.frag +++ b/shaders/frag.frag @@ -51,7 +51,8 @@ void main() vec2 uv; vec4 color; - uv = gl_FragCoord.xy / u_resolution.xy * 2.0 - 1.0; + uv = gl_FragCoord.xy / u_resolution.xy; + uv = uv * 2.0 - 1.0; uv.x *= u_resolution.x / u_resolution.y; vec3 rayOrigin = vec3(0.0, 0.0, 0.0); @@ -70,6 +71,6 @@ void main() vec3 color = computeLighting(hitPoint, normal, viewDir); FragColor = vec4(color, 1.0); } else { - FragColor = vec4(0.0, 0.0, 0.0, 1.0); + FragColor = vec4(0., 0.0, 0.0, 1.0); } } \ No newline at end of file diff --git a/srcs/RT.cpp b/srcs/RT.cpp index a991de2..7a02580 100644 --- a/srcs/RT.cpp +++ b/srcs/RT.cpp @@ -14,14 +14,17 @@ int main(void) { - Window window(WIDTH, HEIGHT, "RT_GPU", 1); + Window window(WIDTH, HEIGHT, "RT_GPU", 0); Shader shader("shaders/vertex.vert", "shaders/frag.frag"); shader.attach(); - RT::Vec2f vertices[6] = { - { -1.0f, -1.0f }, { 1.0f, -1.0f }, { -1.0f, 1.0f }, - { 1.0f, -1.0f }, { 1.0f, 1.0f }, { -1.0f, 1.0f } + // RT::Vec2f vertices[6] = { + // { -1.0f, -1.0f }, { 1.0f, -1.0f }, { -1.0f, 1.0f }, + // { 1.0f, -1.0f }, { 1.0f, 1.0f }, { -1.0f, 1.0f } + // }; + RT::Vec2f vertices[3] = { + {-1.0f, -1.0f}, {3.0f, -1.0f}, {-1.0f, 3.0f} }; size_t size = sizeof(vertices) / sizeof(RT::Vec2f) / 3; @@ -32,10 +35,11 @@ int main(void) glClear(GL_COLOR_BUFFER_BIT); shader.setVec2f("u_resolution", RT::Vec2f(WIDTH, HEIGHT)); - glUseProgram(shader.getProgram()); shader.drawTriangles(size); + std::cout << "\rFPS: " << int(window.getFps()) << " " << std::flush; + window.display(); window.pollEvents(); } diff --git a/srcs/Window.cpp b/srcs/Window.cpp index 1658b7c..e308bf0 100644 --- a/srcs/Window.cpp +++ b/srcs/Window.cpp @@ -85,9 +85,15 @@ void Window::mouseButtonCallback(GLFWwindow* window, int button, int action, int } } - void Window::display() { + static double lastTime = glfwGetTime(); + double currentTime = glfwGetTime(); + double delta = currentTime - lastTime; + + lastTime = currentTime; + _fps = 1.0f / delta; + glfwSwapBuffers(_window); } void Window::pollEvents() @@ -107,3 +113,8 @@ RT::Vec2i Window::getMousePos(void) const { return (_mousePos); } + +float Window::getFps(void) const +{ + return (_fps); +} \ No newline at end of file