mirror of
https://github.com/glfw/glfw.git
synced 2025-10-04 13:46:37 +00:00
63 lines
1.2 KiB
C
63 lines
1.2 KiB
C
#include <glad/glad.h>
|
|
#include <GLFW/glfw3.h>
|
|
|
|
#include <locale.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
|
|
static void char_callback(GLFWwindow* window, unsigned int ch)
|
|
{
|
|
printf ("Char: \"%lc\"\n", (int) ch);
|
|
}
|
|
|
|
static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods)
|
|
{
|
|
if (action != GLFW_PRESS)
|
|
return;
|
|
|
|
switch (key)
|
|
{
|
|
case GLFW_KEY_ESCAPE:
|
|
glfwSetWindowShouldClose(window, GLFW_TRUE);
|
|
break;
|
|
}
|
|
}
|
|
|
|
int main(int argc, char** argv)
|
|
{
|
|
setlocale(LC_ALL, "");
|
|
|
|
GLFWwindow* window;
|
|
|
|
if (!glfwInit())
|
|
{
|
|
fprintf(stderr, "Failed to initialize GLFW\n");
|
|
exit(EXIT_FAILURE);
|
|
}
|
|
|
|
window = glfwCreateWindow(200, 200, "Window Icon", NULL, NULL);
|
|
if (!window)
|
|
{
|
|
glfwTerminate();
|
|
|
|
fprintf(stderr, "Failed to open GLFW window\n");
|
|
exit(EXIT_FAILURE);
|
|
}
|
|
|
|
glfwMakeContextCurrent(window);
|
|
|
|
glfwSetKeyCallback(window, key_callback);
|
|
glfwSetCharCallback(window, char_callback);
|
|
|
|
while (!glfwWindowShouldClose(window))
|
|
{
|
|
glClear(GL_COLOR_BUFFER_BIT);
|
|
glfwSwapBuffers(window);
|
|
glfwWaitEvents();
|
|
}
|
|
|
|
glfwDestroyWindow(window);
|
|
glfwTerminate();
|
|
exit(EXIT_SUCCESS);
|
|
}
|