diff --git a/.gitignore b/.gitignore index f6103c222..9d622bb39 100644 --- a/.gitignore +++ b/.gitignore @@ -76,6 +76,7 @@ tests/monitors tests/msaa tests/reopen tests/tearing +tests/text tests/threads tests/timeout tests/title diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 7078b005d..dbf8a2d5a 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -26,6 +26,7 @@ add_executable(iconify iconify.c ${GETOPT} ${GLAD}) add_executable(monitors monitors.c ${GETOPT} ${GLAD}) add_executable(reopen reopen.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(gamma WIN32 MACOSX_BUNDLE gamma.c ${GLAD}) diff --git a/tests/text.c b/tests/text.c new file mode 100644 index 000000000..d2ac9740c --- /dev/null +++ b/tests/text.c @@ -0,0 +1,62 @@ +#include +#include + +#include +#include +#include + +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); +}