feat(input,window): Add glfw debug and fix nanosleep for windows
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
#include "main.h"
|
||||
#include <glad.h>
|
||||
#include <GLFW/glfw3.h>
|
||||
#include <cglm/quat.h>
|
||||
#include <stdio.h>
|
||||
@@ -21,6 +22,12 @@ vec3 axis[3] = {
|
||||
|
||||
extern struct projection projection;
|
||||
|
||||
void __error_callback_input(int x, const char * msg )
|
||||
{
|
||||
mlog("[GLFW] ");
|
||||
mlog(msg);
|
||||
mlog("\n");
|
||||
}
|
||||
void __key_callback_input(
|
||||
GLFWwindow *window, int key, int scancode, int action, int mods)
|
||||
{
|
||||
|
||||
11
src/window.c
11
src/window.c
@@ -8,6 +8,7 @@ void __mouse_callback_input(GLFWwindow *, int, int, int);
|
||||
void __scroll_callback_input(GLFWwindow *, double, double);
|
||||
void __key_callback_input(GLFWwindow *, int, int, int, int);
|
||||
void __drop_callback_input(GLFWwindow *, int, const char **);
|
||||
void __error_callback_input(int, const char *);
|
||||
|
||||
window_t init_window(unsigned int w, unsigned int h, const char *name);
|
||||
|
||||
@@ -33,8 +34,12 @@ static void __limit_fps_window(int max_fps)
|
||||
struct timespec sleep_time;
|
||||
sleep_time.tv_sec = 0;
|
||||
sleep_time.tv_nsec = (long)((frame_time - elapsed_time) * 1e9);
|
||||
nanosleep(&sleep_time, NULL);
|
||||
|
||||
#ifdef _WIN32
|
||||
usleep(sleep_time.tv_nsec/1000);
|
||||
#else
|
||||
nanosleep(&sleep_time, NULL);
|
||||
#endif
|
||||
current_time = glfwGetTime();
|
||||
}
|
||||
|
||||
@@ -44,6 +49,7 @@ static void __limit_fps_window(int max_fps)
|
||||
window_t init_window(unsigned int width, unsigned int height, const char *title)
|
||||
{
|
||||
window_t window;
|
||||
glfwSetErrorCallback(__error_callback_input);
|
||||
|
||||
if (!glfwInit())
|
||||
return NULL;
|
||||
@@ -51,6 +57,7 @@ window_t init_window(unsigned int width, unsigned int height, const char *title)
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
|
||||
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
|
||||
glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, 1);
|
||||
|
||||
window = (window_t)glfwCreateWindow(width, height, title, NULL, NULL);
|
||||
if (!(window))
|
||||
@@ -67,8 +74,6 @@ window_t init_window(unsigned int width, unsigned int height, const char *title)
|
||||
glfwSetKeyCallback((GLFWwindow *)window, __key_callback_input);
|
||||
glfwSetDropCallback((GLFWwindow *)window, __drop_callback_input);
|
||||
|
||||
__window_callback_input((GLFWwindow *)window, width, height);
|
||||
|
||||
return window;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user