22#include <GL/freeglut.h>
35void GPUDisplayFrontendGlut::displayFunc()
41void GPUDisplayFrontendGlut::glutLoopFunc()
47int32_t GPUDisplayFrontendGlut::GetKey(int32_t
key)
49 if (
key == GLUT_KEY_UP) {
52 if (
key == GLUT_KEY_DOWN) {
55 if (
key == GLUT_KEY_LEFT) {
58 if (
key == GLUT_KEY_RIGHT) {
61 if (
key == GLUT_KEY_PAGE_UP) {
64 if (
key == GLUT_KEY_PAGE_DOWN) {
67 if (
key == GLUT_KEY_HOME) {
70 if (
key == GLUT_KEY_END) {
73 if (
key == GLUT_KEY_INSERT) {
76 if (
key == GLUT_KEY_F1) {
79 if (
key == GLUT_KEY_F2) {
82 if (
key == GLUT_KEY_F3) {
85 if (
key == GLUT_KEY_F4) {
88 if (
key == GLUT_KEY_F5) {
91 if (
key == GLUT_KEY_F6) {
94 if (
key == GLUT_KEY_F7) {
97 if (
key == GLUT_KEY_F8) {
100 if (
key == GLUT_KEY_F9) {
103 if (
key == GLUT_KEY_F10) {
106 if (
key == GLUT_KEY_F11) {
109 if (
key == GLUT_KEY_F12) {
112 if (
key == 112 ||
key == 113) {
128void GPUDisplayFrontendGlut::GetKey(int32_t
key, int32_t& keyOut, int32_t& keyPressOut,
bool special)
130 int32_t specialKey = special ? GetKey(
key) : 0;
134 keyOut = keyPressOut = specialKey;
136 keyOut = keyPressOut =
key;
137 if (keyPressOut >=
'a' && keyPressOut <=
'z') {
138 keyPressOut +=
'A' -
'a';
143void GPUDisplayFrontendGlut::keyboardDownFunc(uint8_t
key, int32_t
x, int32_t
y)
145 int32_t handleKey = 0, keyPress = 0;
147 me->mKeysShift[keyPress] = glutGetModifiers() & GLUT_ACTIVE_SHIFT;
148 me->mKeys[keyPress] =
true;
149 me->HandleKey(handleKey);
152void GPUDisplayFrontendGlut::keyboardUpFunc(uint8_t
key, int32_t
x, int32_t
y)
154 int32_t handleKey = 0, keyPress = 0;
156 me->mKeys[keyPress] =
false;
157 me->mKeysShift[keyPress] =
false;
160void GPUDisplayFrontendGlut::specialDownFunc(int32_t
key, int32_t
x, int32_t
y)
162 int32_t handleKey = 0, keyPress = 0;
164 me->mKeysShift[keyPress] = glutGetModifiers() & GLUT_ACTIVE_SHIFT;
165 me->mKeys[keyPress] =
true;
166 me->HandleKey(handleKey);
169void GPUDisplayFrontendGlut::specialUpFunc(int32_t
key, int32_t
x, int32_t
y)
171 int32_t handleKey = 0, keyPress = 0;
173 me->mKeys[keyPress] =
false;
174 me->mKeysShift[keyPress] =
false;
177void GPUDisplayFrontendGlut::ResizeSceneWrapper(int32_t
width, int32_t
height)
179 if (!
me->mFullScreen) {
186void GPUDisplayFrontendGlut::mouseFunc(int32_t button, int32_t state, int32_t
x, int32_t
y)
189 me->mMouseWheel += 100;
190 }
else if (button == 4) {
191 me->mMouseWheel -= 100;
192 }
else if (state == GLUT_DOWN) {
193 if (button == GLUT_LEFT_BUTTON) {
195 }
else if (button == GLUT_RIGHT_BUTTON) {
196 me->mMouseDnR =
true;
200 }
else if (state == GLUT_UP) {
201 if (button == GLUT_LEFT_BUTTON) {
202 me->mMouseDn =
false;
203 }
else if (button == GLUT_RIGHT_BUTTON) {
204 me->mMouseDnR =
false;
209void GPUDisplayFrontendGlut::mouseMoveFunc(int32_t
x, int32_t
y)
215void GPUDisplayFrontendGlut::mMouseWheelFunc(int32_t button, int32_t dir, int32_t
x, int32_t
y) {
me->mMouseWheel += dir; }
217int32_t GPUDisplayFrontendGlut::FrontendMain()
220 fprintf(stderr,
"Only OpenGL backend supported\n");
230 char opt1[] =
"progname";
231 char opt2[] =
"-direct";
232 char* opts[] = {opt1, opt2};
233 glutInit(&nopts, opts);
235 glutInitContextProfile(
mBackend->
CoreProfile() ? GLUT_CORE_PROFILE : GLUT_COMPATIBILITY_PROFILE);
236 glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
239 glutSetOption(GLUT_ACTION_ON_WINDOW_CLOSE, GLUT_ACTION_GLUTMAINLOOP_RETURNS);
242 fprintf(stderr,
"Error initializing GL extension wrapper\n");
246 fprintf(stderr,
"Error in OpenGL initialization\n");
250 glutDisplayFunc(displayFunc);
251 glutIdleFunc(glutLoopFunc);
252 glutReshapeFunc(ResizeSceneWrapper);
253 glutKeyboardFunc(keyboardDownFunc);
254 glutKeyboardUpFunc(keyboardUpFunc);
255 glutSpecialFunc(specialDownFunc);
256 glutSpecialUpFunc(specialUpFunc);
257 glutMouseFunc(mouseFunc);
258 glutMotionFunc(mouseMoveFunc);
259 glutPassiveMotionFunc(mouseMoveFunc);
260 glutMouseWheelFunc(mMouseWheelFunc);
263 pthread_mutex_lock(&mSemLockExit);
265 pthread_mutex_unlock(&mSemLockExit);
268 pthread_mutex_lock(&mSemLockExit);
269 mGlutRunning =
false;
270 pthread_mutex_unlock(&mSemLockExit);
278 pthread_mutex_lock(&mSemLockExit);
282 pthread_mutex_unlock(&mSemLockExit);
283 while (mGlutRunning) {
290#ifndef GPUCA_DISPLAY_OPENGL_CORE
294 glColor4f(
r,
g,
b,
a);
296 glutBitmapString(GLUT_BITMAP_HELVETICA_12, (
const uint8_t*)s);
306 glutReshapeWindow(mWidth, mHeight);
317 GPUError(
"Coult not Create GL Thread...");
int32_t GetKey(int32_t key)
virtual bool CoreProfile()
virtual int32_t ExtInit()
void ToggleMaximized(bool set) override
void DisplayExit() override
void OpenGLPrint(const char *s, float x, float y, float r, float g, float b, float a, bool fromBotton=true) override
void SetVSync(bool enable) override
void SwitchFullscreen(bool set) override
int32_t StartDisplay() override
int32_t & drawTextFontSize()
static constexpr int32_t KEY_F9
const char * mFrontendName
static constexpr int32_t KEY_F2
static void * FrontendThreadWrapper(void *)
static constexpr int32_t KEY_ALT
static constexpr int32_t KEY_F12
static constexpr int32_t KEY_F7
static constexpr int32_t KEY_END
static constexpr int32_t KEY_PAGEDOWN
volatile int32_t mDisplayControl
static constexpr int32_t KEY_F10
static constexpr int32_t KEY_F4
static constexpr int32_t KEY_LEFT
static constexpr int32_t KEY_F6
static constexpr int32_t KEY_CTRL
static constexpr int32_t KEY_F1
static constexpr const char * DISPLAY_WINDOW_NAME
static constexpr int32_t INIT_WIDTH
static constexpr int32_t GL_MIN_VERSION_MAJOR
frontendTypes mFrontendType
static constexpr int32_t KEY_SHIFT
static constexpr int32_t KEY_F3
static constexpr int32_t KEY_INSERT
static constexpr int32_t KEY_F11
static constexpr int32_t KEY_F5
static constexpr int32_t KEY_PAGEUP
static constexpr int32_t KEY_HOME
GPUDisplayBackend * mBackend
static constexpr int32_t GL_MIN_VERSION_MINOR
int32_t InitDisplay(bool initFailure=false)
GPUDisplayBackend * backend()
static constexpr int32_t KEY_UP
static constexpr int32_t KEY_DOWN
static constexpr int32_t KEY_F8
static constexpr int32_t INIT_HEIGHT
static constexpr int32_t KEY_RIGHT
static constexpr int32_t KEY_RCTRL
GLint GLsizei GLsizei height
GLboolean GLboolean GLboolean b
GLboolean GLboolean GLboolean GLboolean a