From fe758567014de027d3578467587bbc4d1e6a3386 Mon Sep 17 00:00:00 2001 From: Epicalert Date: Sat, 13 Nov 2021 09:07:37 +0800 Subject: [PATCH] Add keyboard input and model info keybind Pressing 'i' will show a dialog box with the model info --- CMakeLists.txt | 1 + src/graphics.cpp | 13 +++++++++++++ src/graphics.hpp | 4 ++++ src/input.cpp | 12 ++++++++++++ src/input.hpp | 6 ++++++ 5 files changed, 36 insertions(+) create mode 100644 src/input.cpp create mode 100644 src/input.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index adeb44f..2fab185 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -70,6 +70,7 @@ add_executable( fc2d src/error.cpp src/eye.cpp src/configfile.cpp + src/input.cpp packaging/fc2d.rc ) target_link_libraries( fc2d ${OpenCV_LIBS} ${OPENGL_LIBRARIES} ${WEBP_LIBRARIES} diff --git a/src/graphics.cpp b/src/graphics.cpp index 5085aa6..cff172d 100644 --- a/src/graphics.cpp +++ b/src/graphics.cpp @@ -23,6 +23,12 @@ #include #include #include +#include + +#ifndef NO_GRAPHICAL_DIALOG +#include +#endif + GLuint shader; //standard shader program used for all elements GLuint transUniform; //location of the "transMatrix" transformation matrix uniform in the shader @@ -98,6 +104,9 @@ void initGraphics () { glutInitWindowSize(512, 512); glutCreateWindow(PROJECT_NAME); + // input callback + glutKeyboardFunc(keyInput); + glewExperimental = GL_TRUE; glewInit(); @@ -237,3 +246,7 @@ void updateModel(struct FaceData faceData) { //tell FreeGLUT to schedule a screen update glutPostRedisplay(); } + +void showModelInfo() { + boxer::show(model->getInfoString().c_str(), "Model info", boxer::Style::Info); +} diff --git a/src/graphics.hpp b/src/graphics.hpp index 875a95b..2806965 100644 --- a/src/graphics.hpp +++ b/src/graphics.hpp @@ -10,6 +10,8 @@ #include #include +#include +#include extern GLuint transUniform; extern float windowAspectRatio; @@ -28,4 +30,6 @@ void printShaderCompileLog(GLuint shader); void updateModel(struct FaceData faceData); +void showModelInfo(); + #endif diff --git a/src/input.cpp b/src/input.cpp new file mode 100644 index 0000000..7faa7f4 --- /dev/null +++ b/src/input.cpp @@ -0,0 +1,12 @@ +#include +#include + +void keyInput(unsigned char key, int x, int y) { + switch(key) { + case 'i': // model info + showModelInfo(); + break; + default: + break; + } +} diff --git a/src/input.hpp b/src/input.hpp new file mode 100644 index 0000000..4d2d6aa --- /dev/null +++ b/src/input.hpp @@ -0,0 +1,6 @@ +#ifndef INPUT_HPP +#define INPUT_HPP + +void keyInput(unsigned char key, int x, int y); + +#endif