key + error callbacks
This commit is contained in:
parent
7629baef17
commit
7946041cba
1 changed files with 15 additions and 2 deletions
17
src/main.cpp
17
src/main.cpp
|
|
@ -1,6 +1,18 @@
|
||||||
#include <GLFW/glfw3.h>
|
#include <GLFW/glfw3.h>
|
||||||
#include <fmt/core.h>
|
#include <fmt/core.h>
|
||||||
|
|
||||||
|
void error_callback(int error_code, const char *description) {
|
||||||
|
fmt::print("[ERROR - {}] {}", error_code, *description);
|
||||||
|
}
|
||||||
|
|
||||||
|
void key_callback(GLFWwindow *window, int key, int scancode, int action,
|
||||||
|
int mods) {
|
||||||
|
const char *key_name = glfwGetKeyName(key, scancode);
|
||||||
|
if (key_name == NULL)
|
||||||
|
return;
|
||||||
|
fmt::print("Key pressed {}\n", key_name);
|
||||||
|
}
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
|
|
||||||
int supported = glfwPlatformSupported(GLFW_PLATFORM_WAYLAND);
|
int supported = glfwPlatformSupported(GLFW_PLATFORM_WAYLAND);
|
||||||
|
|
@ -12,8 +24,7 @@ int main() {
|
||||||
fmt::print("GLFW failed to init! {} - {}\n", code, description);
|
fmt::print("GLFW failed to init! {} - {}\n", code, description);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
GLFWwindow *window =
|
GLFWwindow *window = glfwCreateWindow(640, 480, "GLFW", NULL, NULL);
|
||||||
glfwCreateWindow(640, 480, "GLFW", glfwGetPrimaryMonitor(), NULL);
|
|
||||||
|
|
||||||
if (!window) {
|
if (!window) {
|
||||||
glfwTerminate();
|
glfwTerminate();
|
||||||
|
|
@ -21,6 +32,8 @@ int main() {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
glfwSetErrorCallback(error_callback);
|
||||||
|
glfwSetKeyCallback(window, key_callback);
|
||||||
glfwMakeContextCurrent(window);
|
glfwMakeContextCurrent(window);
|
||||||
glClearColor(0.4f, 0.3f, 0.4f, 0.0f);
|
glClearColor(0.4f, 0.3f, 0.4f, 0.0f);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue