mirror of
https://github.com/glfw/glfw.git
synced 2025-10-04 13:46:37 +00:00
add text input test/example
This commit is contained in:
parent
5595fa3ae6
commit
718dbcda7e
1
.gitignore
vendored
1
.gitignore
vendored
@ -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
|
||||||
|
@ -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
62
tests/text.c
Normal 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);
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user