add text input test/example

This commit is contained in:
Yair Chuchem 2018-11-01 17:38:49 +02:00
parent 5595fa3ae6
commit 718dbcda7e
3 changed files with 64 additions and 0 deletions

1
.gitignore vendored
View File

@ -76,6 +76,7 @@ tests/monitors
tests/msaa tests/msaa
tests/reopen tests/reopen
tests/tearing tests/tearing
tests/text
tests/threads tests/threads
tests/timeout tests/timeout
tests/title tests/title

View File

@ -26,6 +26,7 @@ add_executable(iconify iconify.c ${GETOPT} ${GLAD})
add_executable(monitors monitors.c ${GETOPT} ${GLAD}) add_executable(monitors monitors.c ${GETOPT} ${GLAD})
add_executable(reopen reopen.c ${GLAD}) add_executable(reopen reopen.c ${GLAD})
add_executable(cursor cursor.c ${GLAD}) add_executable(cursor cursor.c ${GLAD})
add_executable(text text.c ${GLAD})
add_executable(empty WIN32 MACOSX_BUNDLE empty.c ${TINYCTHREAD} ${GLAD}) add_executable(empty WIN32 MACOSX_BUNDLE empty.c ${TINYCTHREAD} ${GLAD})
add_executable(gamma WIN32 MACOSX_BUNDLE gamma.c ${GLAD}) add_executable(gamma WIN32 MACOSX_BUNDLE gamma.c ${GLAD})

62
tests/text.c Normal file
View File

@ -0,0 +1,62 @@
#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);
}