22#include <GL/freeglut.h>
24#ifdef GPUCA_BUILD_EVENT_DISPLAY_X11
39void GPUDisplayFrontendGlut::displayFunc()
43 me->waitForFPSLimit();
46void GPUDisplayFrontendGlut::glutLoopFunc()
48 me->HandleExternalGUISignals();
52int32_t GPUDisplayFrontendGlut::GetKey(int32_t
key)
54 if (
key == GLUT_KEY_UP) {
57 if (
key == GLUT_KEY_DOWN) {
60 if (
key == GLUT_KEY_LEFT) {
63 if (
key == GLUT_KEY_RIGHT) {
66 if (
key == GLUT_KEY_PAGE_UP) {
69 if (
key == GLUT_KEY_PAGE_DOWN) {
72 if (
key == GLUT_KEY_HOME) {
75 if (
key == GLUT_KEY_END) {
78 if (
key == GLUT_KEY_INSERT) {
81 if (
key == GLUT_KEY_F1) {
84 if (
key == GLUT_KEY_F2) {
87 if (
key == GLUT_KEY_F3) {
90 if (
key == GLUT_KEY_F4) {
93 if (
key == GLUT_KEY_F5) {
96 if (
key == GLUT_KEY_F6) {
99 if (
key == GLUT_KEY_F7) {
102 if (
key == GLUT_KEY_F8) {
105 if (
key == GLUT_KEY_F9) {
108 if (
key == GLUT_KEY_F10) {
111 if (
key == GLUT_KEY_F11) {
114 if (
key == GLUT_KEY_F12) {
117 if (
key == 112 ||
key == 113) {
133void GPUDisplayFrontendGlut::GetKey(int32_t
key, int32_t& keyOut, int32_t& keyPressOut,
bool special)
135 int32_t specialKey = special ? GetKey(
key) : 0;
139 keyOut = keyPressOut = specialKey;
141 keyOut = keyPressOut =
key;
142 if (keyPressOut >=
'a' && keyPressOut <=
'z') {
143 keyPressOut +=
'A' -
'a';
148void GPUDisplayFrontendGlut::keyboardDownFunc(uint8_t
key, int32_t
x, int32_t
y)
150 int32_t handleKey = 0, keyPress = 0;
152 me->mKeysShift[keyPress] = glutGetModifiers() & GLUT_ACTIVE_SHIFT;
153 me->mKeys[keyPress] =
true;
154 me->HandleKey(handleKey);
157void GPUDisplayFrontendGlut::keyboardUpFunc(uint8_t
key, int32_t
x, int32_t
y)
159 int32_t handleKey = 0, keyPress = 0;
161 me->mKeys[keyPress] =
false;
162 me->mKeysShift[keyPress] =
false;
165void GPUDisplayFrontendGlut::specialDownFunc(int32_t
key, int32_t
x, int32_t
y)
167 int32_t handleKey = 0, keyPress = 0;
169 me->mKeysShift[keyPress] = glutGetModifiers() & GLUT_ACTIVE_SHIFT;
170 me->mKeys[keyPress] =
true;
171 me->HandleKey(handleKey);
174void GPUDisplayFrontendGlut::specialUpFunc(int32_t
key, int32_t
x, int32_t
y)
176 int32_t handleKey = 0, keyPress = 0;
178 me->mKeys[keyPress] =
false;
179 me->mKeysShift[keyPress] =
false;
182void GPUDisplayFrontendGlut::ResizeSceneWrapper(int32_t
width, int32_t
height)
184 if (!
me->mFullScreen) {
191void GPUDisplayFrontendGlut::mouseFunc(int32_t button, int32_t state, int32_t
x, int32_t
y)
194 me->mMouseWheel += 100;
195 }
else if (button == 4) {
196 me->mMouseWheel -= 100;
197 }
else if (state == GLUT_DOWN) {
198 if (button == GLUT_LEFT_BUTTON) {
200 }
else if (button == GLUT_RIGHT_BUTTON) {
201 me->mMouseDnR =
true;
202 }
else if (button == GLUT_MIDDLE_BUTTON) {
203 me->mMouseDnM =
true;
207 }
else if (state == GLUT_UP) {
208 if (button == GLUT_LEFT_BUTTON) {
209 me->mMouseDn =
false;
210 }
else if (button == GLUT_RIGHT_BUTTON) {
211 me->mMouseDnR =
false;
212 }
else if (button == GLUT_MIDDLE_BUTTON) {
213 me->mMouseDnM =
false;
218void GPUDisplayFrontendGlut::mouseMoveFunc(int32_t
x, int32_t
y)
224void GPUDisplayFrontendGlut::mMouseWheelFunc(int32_t button, int32_t dir, int32_t
x, int32_t
y) {
me->mMouseWheel += dir; }
226int32_t GPUDisplayFrontendGlut::FrontendMain()
229 fprintf(stderr,
"Only OpenGL backend supported\n");
239 char opt1[] =
"progname";
240 char opt2[] =
"-direct";
241 char* opts[] = {opt1, opt2};
242 glutInit(&nopts, opts);
244 glutInitContextProfile(
mBackend->
CoreProfile() ? GLUT_CORE_PROFILE : GLUT_COMPATIBILITY_PROFILE);
245 glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
248 glutSetOption(GLUT_ACTION_ON_WINDOW_CLOSE, GLUT_ACTION_GLUTMAINLOOP_RETURNS);
251 fprintf(stderr,
"Error initializing GL extension wrapper\n");
255 fprintf(stderr,
"Error in OpenGL initialization\n");
259 glutDisplayFunc(displayFunc);
260 glutIdleFunc(glutLoopFunc);
261 glutReshapeFunc(ResizeSceneWrapper);
262 glutKeyboardFunc(keyboardDownFunc);
263 glutKeyboardUpFunc(keyboardUpFunc);
264 glutSpecialFunc(specialDownFunc);
265 glutSpecialUpFunc(specialUpFunc);
266 glutMouseFunc(mouseFunc);
267 glutMotionFunc(mouseMoveFunc);
268 glutPassiveMotionFunc(mouseMoveFunc);
269 glutMouseWheelFunc(mMouseWheelFunc);
295#ifndef GPUCA_DISPLAY_OPENGL_CORE
299 glColor4f(
r,
g,
b,
a);
301 glutBitmapString(GLUT_BITMAP_HELVETICA_12, (
const uint8_t*)s);
311 glutReshapeWindow(mWidth, mHeight);
318#ifdef GPUCA_BUILD_EVENT_DISPLAY_X11
320 ((PFNGLXSWAPINTERVALEXTPROC)glXGetProcAddressARB((
const GLubyte*)
"glXSwapIntervalEXT"))(glXGetCurrentDisplay(), glXGetCurrentDrawable(),
enable);
327#ifdef GPUCA_BUILD_EVENT_DISPLAY_X11
328 return glXGetProcAddressARB((
const GLubyte*)
"glXSwapIntervalEXT") && glXGetCurrentDisplay();
int32_t GetKey(int32_t key)
virtual bool CoreProfile()
virtual int32_t ExtInit()
void ToggleMaximized(bool set) override
void StopDisplayA() override
void OpenGLPrint(const char *s, float x, float y, float r, float g, float b, float a, bool fromBotton=true) override
bool canSetVSync() override
void SetVSync(bool enable) override
void SwitchFullscreen(bool set) override
int32_t & drawTextFontSize()
static constexpr int32_t KEY_F9
const char * mFrontendName
static constexpr int32_t KEY_F2
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
std::mutex mExitStateMutex
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)
bool vsyncEnabled() const
GPUDisplayBackend * backend()
static constexpr int32_t KEY_UP
static constexpr int32_t KEY_DOWN
static constexpr int32_t KEY_F8
void applyInitialWindowState()
static constexpr int32_t INIT_HEIGHT
static constexpr int32_t KEY_RIGHT
volatile bool mDisplayRunning
static constexpr int32_t KEY_RCTRL
GLint GLsizei GLsizei height
GLboolean GLboolean GLboolean b
GLboolean GLboolean GLboolean GLboolean a