pixelisation try to stay between 60 and 90 fps

This commit is contained in:
2025-01-11 16:03:08 +01:00
parent ec30084d6f
commit e0b057a189
5 changed files with 22 additions and 9 deletions

BIN
RT

Binary file not shown.

View File

@ -6,7 +6,7 @@
/* By: ycontre <ycontre@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/13 16:15:41 by TheRed #+# #+# */
/* Updated: 2024/12/23 18:35:35 by ycontre ### ########.fr */
/* Updated: 2025/01/11 15:48:52 by tomoron ### ########.fr */
/* */
/* ************************************************************************** */
@ -45,6 +45,7 @@ class Window
float _fps;
float _delta;
int _frameCount;
int _pixelisation;
};

5
shell.nix Normal file
View File

@ -0,0 +1,5 @@
{ pkgs ? import <nixpkgs> {} }:
pkgs.mkShell {
nativeBuildInputs = with pkgs; [ libGL xorg.libX11 libGLU glfw];
}

View File

@ -6,7 +6,7 @@
/* By: ycontre <ycontre@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/09/27 14:51:49 by TheRed #+# #+# */
/* Updated: 2025/01/10 19:12:40 by ycontre ### ########.fr */
/* Updated: 2025/01/11 15:52:07 by tomoron ### ########.fr */
/* */
/* ************************************************************************** */
@ -72,7 +72,7 @@ int main(int argc, char **argv)
shader.set_int("u_frameCount", window.getFrameCount());
shader.set_int("u_objectsNum", object_data.size());
shader.set_int("u_pixelisation", window.getPixelisation() * 10 + 1);
shader.set_int("u_pixelisation", window.getPixelisation());
shader.set_float("u_time", (float)(glfwGetTime()));
shader.set_vec2("u_resolution", glm::vec2(WIDTH, HEIGHT));

View File

@ -6,7 +6,7 @@
/* By: ycontre <ycontre@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/13 16:16:24 by TheRed #+# #+# */
/* Updated: 2025/01/09 16:34:48 by tomoron ### ########.fr */
/* Updated: 2025/01/11 15:55:19 by tomoron ### ########.fr */
/* */
/* ************************************************************************** */
@ -16,6 +16,7 @@ Window::Window(Scene *scene, int width, int height, const char *title, int sleep
{
_scene = scene;
_frameCount = 0;
_pixelisation = 0;
if (!glfwInit())
{
@ -54,7 +55,6 @@ Window::~Window(void)
void Window::process_input()
{
bool forward = glfwGetKey(_window, GLFW_KEY_W) == GLFW_PRESS;
bool backward = glfwGetKey(_window, GLFW_KEY_S) == GLFW_PRESS;
bool left = glfwGetKey(_window, GLFW_KEY_A) == GLFW_PRESS;
@ -173,6 +173,13 @@ int Window::getPixelisation(void)
bool movement = _scene->getCamera()->getVelocity() > 0.0f;
if (mouse || movement)
return (1);
return (0);
{
if(_fps < 60 && _pixelisation < 16)
_pixelisation++;
if(_fps > 90 && _pixelisation > 0)
_pixelisation--;
}
else if(_pixelisation)
_pixelisation = 0;
return (_pixelisation + 1);
}