mirror of
https://github.com/TheRedShip/RT_GPU.git
synced 2025-09-27 18:48:36 +02:00
+ | FPS ~ | Single triangle shader
This commit is contained in:
@ -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
|
@ -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);
|
||||
}
|
||||
}
|
14
srcs/RT.cpp
14
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();
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
Reference in New Issue
Block a user