Fixed event polling loop which fixed laggy input
This commit is contained in:
parent
966027815c
commit
e383f8bf93
1 changed files with 20 additions and 9 deletions
25
src/main.c
25
src/main.c
|
|
@ -1,9 +1,11 @@
|
|||
#include <SDL3/SDL.h>
|
||||
#include <GL/glew.h>
|
||||
#include <SDL3/SDL.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "SDL3/SDL_events.h"
|
||||
#include "SDL3/SDL_keycode.h"
|
||||
#include "camera.h"
|
||||
#include "cglm/io.h"
|
||||
|
||||
|
|
@ -145,16 +147,25 @@ int main(int argc, char *argv[]) {
|
|||
// Initialise camera
|
||||
Camera camera = Camera_default;
|
||||
|
||||
// Lock and hide mouse to window
|
||||
// Lock and hide mouse
|
||||
SDL_SetWindowRelativeMouseMode(window, true);
|
||||
SDL_GetRelativeMouseState(NULL, NULL);
|
||||
|
||||
bool wants_running = true;
|
||||
while (wants_running) {
|
||||
|
||||
while (1) {
|
||||
// handle input
|
||||
SDL_PollEvent(&event);
|
||||
if (event.type == SDL_EVENT_QUIT) {
|
||||
// handle input events
|
||||
while (SDL_PollEvent(&event)) {
|
||||
switch (event.type) {
|
||||
case SDL_EVENT_QUIT:
|
||||
wants_running = false;
|
||||
break;
|
||||
case SDL_EVENT_KEY_DOWN:
|
||||
if (event.key.key == SDLK_ESCAPE) {
|
||||
wants_running = false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Handle camera
|
||||
|
|
@ -163,7 +174,7 @@ int main(int argc, char *argv[]) {
|
|||
// TODO: make shader file
|
||||
mat4 mvp;
|
||||
camera_calc_mvp(&mvp, &camera);
|
||||
//glm_mat4_print(mvp,stdout);
|
||||
// glm_mat4_print(mvp,stdout);
|
||||
int mvp_uniform_location = glGetUniformLocation(shaderProgram, "MVP");
|
||||
glUniformMatrix4fv(mvp_uniform_location, 1, GL_FALSE, &mvp[0][0]);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue