Fixed event polling loop which fixed laggy input

This commit is contained in:
Warwick 2025-08-18 15:30:53 +01:00
parent 966027815c
commit e383f8bf93

View file

@ -1,9 +1,11 @@
#include <SDL3/SDL.h>
#include <GL/glew.h> #include <GL/glew.h>
#include <SDL3/SDL.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <time.h> #include <time.h>
#include "SDL3/SDL_events.h"
#include "SDL3/SDL_keycode.h"
#include "camera.h" #include "camera.h"
#include "cglm/io.h" #include "cglm/io.h"
@ -145,16 +147,25 @@ int main(int argc, char *argv[]) {
// Initialise camera // Initialise camera
Camera camera = Camera_default; Camera camera = Camera_default;
// Lock and hide mouse to window // Lock and hide mouse
SDL_SetWindowRelativeMouseMode(window, true); SDL_SetWindowRelativeMouseMode(window, true);
SDL_GetRelativeMouseState(NULL, NULL); SDL_GetRelativeMouseState(NULL, NULL);
bool wants_running = true;
while (wants_running) {
while (1) { // handle input events
// handle input while (SDL_PollEvent(&event)) {
SDL_PollEvent(&event); switch (event.type) {
if (event.type == SDL_EVENT_QUIT) { case SDL_EVENT_QUIT:
wants_running = false;
break; break;
case SDL_EVENT_KEY_DOWN:
if (event.key.key == SDLK_ESCAPE) {
wants_running = false;
}
break;
}
} }
// Handle camera // Handle camera
@ -163,7 +174,7 @@ int main(int argc, char *argv[]) {
// TODO: make shader file // TODO: make shader file
mat4 mvp; mat4 mvp;
camera_calc_mvp(&mvp, &camera); camera_calc_mvp(&mvp, &camera);
//glm_mat4_print(mvp,stdout); // glm_mat4_print(mvp,stdout);
int mvp_uniform_location = glGetUniformLocation(shaderProgram, "MVP"); int mvp_uniform_location = glGetUniformLocation(shaderProgram, "MVP");
glUniformMatrix4fv(mvp_uniform_location, 1, GL_FALSE, &mvp[0][0]); glUniformMatrix4fv(mvp_uniform_location, 1, GL_FALSE, &mvp[0][0]);