summaryrefslogtreecommitdiff
path: root/platform/gl
diff options
context:
space:
mode:
authorTor Andersson <tor.andersson@artifex.com>2017-11-13 12:45:50 +0100
committerTor Andersson <tor.andersson@artifex.com>2017-11-13 17:05:16 +0100
commit65be3177c793bb132c36f3e6bb87c3a6947be4e0 (patch)
tree70bc8256fd4de46b912e432932d5dc807c5b4dc8 /platform/gl
parentaf95ed2a3402ecf65ff744b45c3053bc811d4ada (diff)
downloadmupdf-65be3177c793bb132c36f3e6bb87c3a6947be4e0.tar.xz
gl: Fix GLUT build on MacOS X.
Diffstat (limited to 'platform/gl')
-rw-r--r--platform/gl/gl-app.h4
-rw-r--r--platform/gl/gl-main.c62
2 files changed, 46 insertions, 20 deletions
diff --git a/platform/gl/gl-app.h b/platform/gl/gl-app.h
index 59252b94..2aea2aed 100644
--- a/platform/gl/gl-app.h
+++ b/platform/gl/gl-app.h
@@ -7,7 +7,11 @@ int win_open_file(char *buf, int len);
#include "mupdf/fitz.h"
#include "mupdf/ucdn.h"
+#ifndef __APPLE__
#include <GL/freeglut.h>
+#else
+#include <GLUT/glut.h>
+#endif
extern fz_context *ctx;
diff --git a/platform/gl/gl-main.c b/platform/gl/gl-main.c
index 38c7c937..6475b501 100644
--- a/platform/gl/gl-main.c
+++ b/platform/gl/gl-main.c
@@ -10,6 +10,14 @@
#include <unistd.h> /* for fork and exec */
#endif
+#ifndef FREEGLUT
+/* freeglut extension no-ops */
+void glutExit(void) {}
+void glutMouseWheelFunc(void *fn) {}
+void glutInitErrorFunc(void *fn) {}
+void glutInitWarningFunc(void *fn) {}
+#endif
+
enum
{
/* Screen furniture: aggregate size of unusable space from title bars, task bars, window borders, etc */
@@ -1347,6 +1355,9 @@ static void run_main_loop(void)
if (doquit)
{
glutDestroyWindow(window);
+#ifdef __APPLE__
+ exit(1); /* GLUT on MacOS keeps running even with no windows */
+#endif
return;
}
@@ -1406,8 +1417,19 @@ static void run_main_loop(void)
ogl_assert(ctx, "swap buffers");
}
-static void on_keyboard_ext(int key, int x, int y)
+#if defined(FREEGLUT) && (GLUT_API_VERSION >= 6)
+static void on_keyboard(int key, int x, int y)
+#else
+static void on_keyboard(unsigned char key, int x, int y)
+#endif
{
+#ifdef __APPLE__
+ /* Apple's GLUT has swapped DELETE and BACKSPACE */
+ if (key == 8)
+ key = 127;
+ else if (key == 127)
+ key = 8;
+#endif
ui.key = key;
ui.mod = glutGetModifiers();
ui.plain = !(ui.mod & ~GLUT_ACTIVE_SHIFT);
@@ -1415,13 +1437,6 @@ static void on_keyboard_ext(int key, int x, int y)
ui.key = ui.mod = ui.plain = 0;
}
-#if GLUT_API_VERSION < 5
-static void on_keyboard(unsigned char key, int x, int y)
-{
- on_keyboard_ext(key, x, y);
-}
-#endif
-
static void on_special(int key, int x, int y)
{
ui.key = 0;
@@ -1429,7 +1444,9 @@ static void on_special(int key, int x, int y)
switch (key)
{
case GLUT_KEY_INSERT: ui.key = KEY_INSERT; break;
+#ifdef GLUT_KEY_DELETE
case GLUT_KEY_DELETE: ui.key = KEY_DELETE; break;
+#endif
case GLUT_KEY_RIGHT: ui.key = KEY_RIGHT; break;
case GLUT_KEY_LEFT: ui.key = KEY_LEFT; break;
case GLUT_KEY_DOWN: ui.key = KEY_DOWN; break;
@@ -1522,30 +1539,35 @@ static void on_warning(const char *fmt, va_list ap)
fprintf(stderr, "\n");
}
-#if GLUT_API_VERSION < 5
-static char *clipboard_buffer = NULL;
-#endif
+#if defined(FREEGLUT) && (GLUT_API_VERSION >= 6)
void ui_set_clipboard(const char *buf)
{
-#if GLUT_API_VERSION >= 5
glutSetClipboard(GLUT_CLIPBOARD, buf);
+}
+
+const char *ui_get_clipboard(void)
+{
+ return glutGetClipboard(GLUT_CLIPBOARD);
+}
+
#else
+
+static char *clipboard_buffer = NULL;
+
+void ui_set_clipboard(const char *buf)
+{
fz_free(ctx, clipboard_buffer);
clipboard_buffer = fz_strdup(ctx, buf);
-#endif
}
const char *ui_get_clipboard(void)
{
-#if GLUT_API_VERSION >= 5
- return glutGetClipboard(GLUT_CLIPBOARD);
-#else
return clipboard_buffer;
- return NULL;
-#endif
}
+#endif
+
static void usage(const char *argv0)
{
fprintf(stderr, "mupdf-gl version %s\n", FZ_VERSION);
@@ -1647,8 +1669,8 @@ int main(int argc, char **argv)
glutReshapeFunc(on_reshape);
glutDisplayFunc(on_display);
-#if GLUT_API_VERSION >= 5
- glutKeyboardExtFunc(on_keyboard_ext);
+#if defined(FREEGLUT) && (GLUT_API_VERSION >= 6)
+ glutKeyboardExtFunc(on_keyboard);
#else
glutKeyboardFunc(on_keyboard);
#endif