summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makerules4
-rw-r--r--Makethird7
-rw-r--r--platform/gl/gl-app.h4
-rw-r--r--platform/gl/gl-main.c62
m---------thirdparty/freeglut0
5 files changed, 57 insertions, 20 deletions
diff --git a/Makerules b/Makerules
index a7a41b45..fc1375d2 100644
--- a/Makerules
+++ b/Makerules
@@ -77,6 +77,10 @@ else ifeq "$(OS)" "MACOS"
HAVE_X11 ?= no
+HAVE_GLUT ?= yes
+SYS_GLUT_CFLAGS := -Wno-deprecated-declarations
+SYS_GLUT_LIBS := -framework GLUT -framework OpenGL
+
CC = xcrun cc
AR = xcrun ar
LD = xcrun ld
diff --git a/Makethird b/Makethird
index f83be6cc..38d6d7cf 100644
--- a/Makethird
+++ b/Makethird
@@ -663,6 +663,11 @@ endif
ifneq "$(wildcard $(GLUT_DIR)/README)" ""
+ifeq "$(OS)" "MACOS"
+GLUT_CFLAGS := $(SYS_GLUT_CFLAGS)
+GLUT_LIBS := $(SYS_GLUT_LIBS)
+else
+
HAVE_GLUT := yes
GLUT_LIB := $(OUT)/libfreeglut.a
@@ -727,6 +732,8 @@ $(GLUT_OUT)/%.o: $(GLUT_DIR)/src/x11/%.c | $(GLUT_OUT)
GLUT_CFLAGS := -I$(GLUT_DIR)/include
GLUT_LIBS := -lGL -lX11 -lXrandr
+
+endif
else
GLUT_CFLAGS := $(SYS_GLUT_CFLAGS)
GLUT_LIBS := $(SYS_GLUT_LIBS)
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
diff --git a/thirdparty/freeglut b/thirdparty/freeglut
-Subproject 850d2102eb302bdd03fd81af6b6becdb1f3ae2e
+Subproject 2ba99eb5264fcc0c3c817dc515aef4b630b419b