Skip to content

Commit

Permalink
gl: Remove GLFW and reinstate FreeGLUT.
Browse files Browse the repository at this point in the history
GLFW doesn't build on Visual Studio 2005 anymore, and I don't have time to keep
up with the changes.

So, we're switching back to FreeGLUT, which is more stable.

I've added the two missing features that made us switch to GLFW in the first
place: input methods and system clipboard support.

If MuPDF is compiled with our version of FreeGLUT, we now use these functions:

	* glutKeyboardExtFunc
	* glutSetClipboard
	* glutGetClipboard
  • Loading branch information
ccxvii committed Nov 8, 2017
1 parent 94a5846 commit 896830e
Show file tree
Hide file tree
Showing 12 changed files with 479 additions and 351 deletions.
12 changes: 6 additions & 6 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@
[submodule "thirdparty/jpeg"]
path = thirdparty/libjpeg
url = ../thirdparty-libjpeg.git
[submodule "thirdparty/lcms2"]
path = thirdparty/lcms2
url = ../thirdparty-lcms2.git
[submodule "thirdparty/openjpeg"]
path = thirdparty/openjpeg
url = ../thirdparty-openjpeg.git
[submodule "thirdparty/zlib"]
path = thirdparty/zlib
url = ../thirdparty-zlib.git
[submodule "thirdparty/glfw"]
path = thirdparty/glfw
url = ../thirdparty-glfw.git
[submodule "thirdparty/curl"]
path = thirdparty/curl
url = ../thirdparty-curl.git
[submodule "thirdparty/lcms2"]
path = thirdparty/lcms2
url = ../thirdparty-lcms2.git
[submodule "thirdparty/freeglut"]
path = thirdparty/freeglut
url = ../thirdparty-freeglut.git
18 changes: 9 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ $(OUT)/platform/x11/curl/%.o : platform/x11/%.c | $(ALL_DIR)
$(CC_CMD) $(X11_CFLAGS) $(CURL_CFLAGS) -DHAVE_CURL

$(OUT)/platform/gl/%.o : platform/gl/%.c | $(ALL_DIR)
$(CC_CMD) $(GLFW_CFLAGS)
$(CC_CMD) $(GLUT_CFLAGS)

$(OUT)/%.o : %.c | $(ALL_DIR)
$(CC_CMD)
Expand Down Expand Up @@ -392,12 +392,12 @@ $(MUVIEW_X11_CURL_EXE) : $(MUVIEW_X11_CURL_OBJ) $(MUPDF_LIB) $(THIRD_LIB) $(CURL
endif
endif

ifeq "$(HAVE_GLFW)" "yes"
MUVIEW_GLFW_EXE := $(OUT)/mupdf-gl
MUVIEW_GLFW_OBJ := $(addprefix $(OUT)/platform/gl/, gl-font.o gl-input.o gl-main.o)
$(MUVIEW_GLFW_OBJ) : $(FITZ_HDR) $(PDF_HDR) platform/gl/gl-app.h
$(MUVIEW_GLFW_EXE) : $(MUVIEW_GLFW_OBJ) $(MUPDF_LIB) $(THIRD_LIB) $(GLFW_LIB)
$(LINK_CMD) $(GLFW_LIBS)
ifeq "$(HAVE_GLUT)" "yes"
MUVIEW_GLUT_EXE := $(OUT)/mupdf-gl
MUVIEW_GLUT_OBJ := $(addprefix $(OUT)/platform/gl/, gl-font.o gl-input.o gl-main.o)
$(MUVIEW_GLUT_OBJ) : $(FITZ_HDR) $(PDF_HDR) platform/gl/gl-app.h
$(MUVIEW_GLUT_EXE) : $(MUVIEW_GLUT_OBJ) $(MUPDF_LIB) $(THIRD_LIB) $(GLUT_LIB)
$(LINK_CMD) $(GLUT_LIB) $(GLUT_LIBS)
endif

ifeq "$(HAVE_WIN32)" "yes"
Expand All @@ -408,7 +408,7 @@ $(MUVIEW_WIN32_EXE) : $(MUVIEW_WIN32_OBJ) $(MUPDF_LIB) $(THIRD_LIB)
$(LINK_CMD) $(WIN32_LIBS)
endif

MUVIEW_EXE := $(MUVIEW_X11_EXE) $(MUVIEW_WIN32_EXE) $(MUVIEW_GLFW_EXE)
MUVIEW_EXE := $(MUVIEW_X11_EXE) $(MUVIEW_WIN32_EXE) $(MUVIEW_GLUT_EXE)
MUVIEW_CURL_EXE := $(MUVIEW_X11_CURL_EXE) $(MUVIEW_WIN32_CURL_EXE)

INSTALL_APPS := $(MUTOOL_EXE) $(MUVIEW_EXE)
Expand Down Expand Up @@ -453,7 +453,7 @@ mandir ?= $(prefix)/share/man
docdir ?= $(prefix)/share/doc/mupdf

third: $(THIRD_LIB)
extra: $(CURL_LIB) $(GLFW_LIB)
extra: $(CURL_LIB) $(GLUT_LIB)
libs: $(INSTALL_LIBS)
apps: $(INSTALL_APPS)

Expand Down
6 changes: 5 additions & 1 deletion Makerules
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ HAVE_PTHREAD := yes
SYS_PTHREAD_CFLAGS :=
SYS_PTHREAD_LIBS := -lpthread

HAVE_GLUT := yes
SYS_GLUT_CFLAGS :=
SYS_GLUT_LIBS := -lglut -lGL

ifeq "$(shell pkg-config --exists 'libcrypto <= 1.0.1t' && echo yes)" "yes"
HAVE_LIBCRYPTO := yes
SYS_LIBCRYPTO_CFLAGS := -DHAVE_LIBCRYPTO $(shell pkg-config --cflags libcrypto)
Expand Down Expand Up @@ -280,5 +284,5 @@ endif
# TODO: If crosscompiling, why not just call "make libs" instead of this exception?
ifeq "$(CROSSCOMPILE)" "yes"
HAVE_X11 ?= no
HAVE_GLFW ?= no
HAVE_GLUT ?= no
endif
157 changes: 71 additions & 86 deletions Makethird
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ OPENJPEG_DIR := thirdparty/openjpeg/src/lib/openjp2
ZLIB_DIR := thirdparty/zlib

CURL_DIR := thirdparty/curl
GLFW_DIR := thirdparty/glfw
GLUT_DIR := thirdparty/freeglut

# --- MuJS ---

Expand Down Expand Up @@ -659,92 +659,77 @@ CURL_CFLAGS := $(SYS_CURL_CFLAGS)
CURL_LIBS := $(SYS_CURL_LIBS)
endif

# --- GLFW ---

ifneq "$(wildcard $(GLFW_DIR)/README.md)" ""

GLFW_LIB := $(OUT)/libglfw.a
GLFW_OUT := $(OUT)/thirdparty/glfw

ifeq "$(OS)" "MACOS"

GLFW_SRC := \
cocoa_init.m \
cocoa_joystick.m \
cocoa_monitor.m \
cocoa_time.c \
cocoa_window.m \
context.c \
init.c \
input.c \
monitor.c \
nsgl_context.m \
posix_tls.c \
vulkan.c \
window.c

$(GLFW_OUT)/%.o: $(GLFW_DIR)/src/%.m | $(GLFW_OUT)
$(CC_CMD) -D_GLFW_COCOA -D_GLFW_USE_MENUBAR -D_GLFW_USE_RETINA -Wno-deprecated-declarations
$(GLFW_OUT)/%.o: $(GLFW_DIR)/src/%.c | $(GLFW_OUT)
$(CC_CMD) -D_GLFW_COCOA -D_GLFW_USE_MENUBAR -D_GLFW_USE_RETINA

GLFW_OBJ := $(addprefix $(GLFW_OUT)/, $(GLFW_SRC))
GLFW_OBJ := $(GLFW_OBJ:%.c=%.o)
GLFW_OBJ := $(GLFW_OBJ:%.m=%.o)

$(GLFW_LIB): $(GLFW_OBJ)
GLFW_LIBS := -framework OpenGL -framework IOKit -framework CoreVideo -framework Cocoa

else

GLFW_SRC := \
context.c \
egl_context.c \
glx_context.c \
init.c \
input.c \
linux_joystick.c \
monitor.c \
posix_time.c \
posix_tls.c \
vulkan.c \
window.c \
x11_init.c \
x11_monitor.c \
x11_window.c \
xkb_unicode.c

$(GLFW_OUT)/%.o: $(GLFW_DIR)/src/%.c | $(GLFW_OUT)
$(CC_CMD) -D_GLFW_X11
$(GLFW_LIB): $(addprefix $(GLFW_OUT)/, $(GLFW_SRC:%.c=%.o))
GLFW_LIBS := -lGL -ldl -lX11 -lXcursor -lXrandr -lXinerama -lpthread

endif

GLFW_CFLAGS := -I$(GLFW_DIR)/include
$(GLFW_OUT):
# --- FreeGLUT ---

ifneq "$(wildcard $(GLUT_DIR)/README)" ""

HAVE_GLUT := yes

GLUT_LIB := $(OUT)/libfreeglut.a
GLUT_OUT := $(OUT)/freeglut
GLUT_SRC := \
fg_callbacks.c \
fg_cursor.c \
fg_display.c \
fg_ext.c \
fg_font.c \
fg_font_data.c \
fg_gamemode.c \
fg_geometry.c \
fg_gl2.c \
fg_init.c \
fg_input_devices.c \
fg_joystick.c \
fg_main.c \
fg_menu.c \
fg_misc.c \
fg_overlay.c \
fg_spaceball.c \
fg_state.c \
fg_stroke_mono_roman.c \
fg_stroke_roman.c \
fg_structure.c \
fg_teapot.c \
fg_videoresize.c \
fg_window.c

GLUT_X11_SRC := \
fg_cursor_x11.c \
fg_display_x11_glx.c \
fg_ext_x11.c \
fg_gamemode_x11.c \
fg_glutfont_definitions_x11.c \
fg_init_x11.c \
fg_input_devices_x11.c \
fg_joystick_x11.c \
fg_main_x11.c \
fg_menu_x11.c \
fg_spaceball_x11.c \
fg_state_x11.c \
fg_state_x11_glx.c \
fg_structure_x11.c \
fg_window_x11.c \
fg_window_x11_glx.c \
fg_xinput_x11.c

GLUT_OBJ := $(addprefix $(GLUT_OUT)/, $(GLUT_SRC:%.c=%.o))
GLUT_OBJ += $(addprefix $(GLUT_OUT)/, $(GLUT_X11_SRC:%.c=%.o))

$(GLUT_LIB): $(GLUT_OBJ)
$(GLUT_OUT):
$(MKDIR_CMD)

GLFW_SRC_UNUSED := \
mir_init.c \
mir_monitor.c \
mir_window.c \
wgl_context.c \
win32_init.c \
win32_joystick.c \
win32_monitor.c \
win32_time.c \
win32_tls.c \
win32_window.c \
wl_init.c \
wl_monitor.c \
wl_window.c \

HAVE_GLFW := yes

else ifeq "$(HAVE_GLFW)" "yes"
GLFW_CFLAGS := $(SYS_GLFW_CFLAGS)
GLFW_LIBS := $(SYS_GLFW_LIBS)
$(GLUT_OUT)/%.o: $(GLUT_DIR)/src/%.c | $(GLUT_OUT)
$(CC_CMD) -I$(GLUT_DIR)/include -I$(GLUT_DIR)/src -Wno-unused-const-variable \
-DHAVE_UNISTD_H -DHAVE_STDINT_H -DHAVE_X11_EXTENSIONS_XRANDR_H
$(GLUT_OUT)/%.o: $(GLUT_DIR)/src/x11/%.c | $(GLUT_OUT)
$(CC_CMD) -I$(GLUT_DIR)/include -I$(GLUT_DIR)/src \
-DHAVE_UNISTD_H -DHAVE_STDINT_H -DHAVE_X11_EXTENSIONS_XRANDR_H

GLUT_CFLAGS := -I$(GLUT_DIR)/include
GLUT_LIBS := -lGL -lX11 -lXrandr
else
GLUT_CFLAGS := $(SYS_GLUT_CFLAGS)
GLUT_LIBS := $(SYS_GLUT_LIBS)
endif

# --- X11 ---
Expand Down
8 changes: 5 additions & 3 deletions platform/gl/gl-app.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@ int win_open_file(char *buf, int len);
#include "mupdf/fitz.h"
#include "mupdf/ucdn.h"

#include <GLFW/glfw3.h>
#include <GL/freeglut.h>

extern fz_context *ctx;
extern GLFWwindow *window;

enum
{
Expand Down Expand Up @@ -57,7 +56,7 @@ struct ui
int x, y;
int down, middle, right;
int scroll_x, scroll_y;
int key, mod;
int key, mod, plain;

void *hot, *active, *focus;

Expand All @@ -68,6 +67,9 @@ struct ui

extern struct ui ui;

void ui_set_clipboard(const char *buf);
const char *ui_get_clipboard(void);

void ui_init_fonts(fz_context *ctx, float pixelsize);
void ui_finish_fonts(fz_context *ctx);
float ui_measure_character(fz_context *ctx, int ucs);
Expand Down
30 changes: 15 additions & 15 deletions platform/gl/gl-input.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,18 +112,18 @@ static int ui_input_key(struct input *input)
switch (ui.key)
{
case KEY_LEFT:
if (ui.mod == GLFW_MOD_CONTROL + GLFW_MOD_SHIFT)
if (ui.mod == GLUT_ACTIVE_CTRL + GLUT_ACTIVE_SHIFT)
{
input->q = prev_word(input->q, input->text);
}
else if (ui.mod == GLFW_MOD_CONTROL)
else if (ui.mod == GLUT_ACTIVE_CTRL)
{
if (input->p != input->q)
input->p = input->q = input->p < input->q ? input->p : input->q;
else
input->p = input->q = prev_word(input->q, input->text);
}
else if (ui.mod == GLFW_MOD_SHIFT)
else if (ui.mod == GLUT_ACTIVE_SHIFT)
{
if (input->q > input->text)
input->q = prev_char(input->q, input->text);
Expand All @@ -137,18 +137,18 @@ static int ui_input_key(struct input *input)
}
break;
case KEY_RIGHT:
if (ui.mod == GLFW_MOD_CONTROL + GLFW_MOD_SHIFT)
if (ui.mod == GLUT_ACTIVE_CTRL + GLUT_ACTIVE_SHIFT)
{
input->q = next_word(input->q, input->end);
}
else if (ui.mod == GLFW_MOD_CONTROL)
else if (ui.mod == GLUT_ACTIVE_CTRL)
{
if (input->p != input->q)
input->p = input->q = input->p > input->q ? input->p : input->q;
else
input->p = input->q = next_word(input->q, input->end);
}
else if (ui.mod == GLFW_MOD_SHIFT)
else if (ui.mod == GLUT_ACTIVE_SHIFT)
{
if (input->q < input->end)
input->q = next_char(input->q);
Expand All @@ -163,15 +163,15 @@ static int ui_input_key(struct input *input)
break;
case KEY_UP:
case KEY_HOME:
if (ui.mod == GLFW_MOD_CONTROL + GLFW_MOD_SHIFT)
if (ui.mod == GLUT_ACTIVE_CTRL + GLUT_ACTIVE_SHIFT)
{
input->q = input->text;
}
else if (ui.mod == GLFW_MOD_CONTROL)
else if (ui.mod == GLUT_ACTIVE_CTRL)
{
input->p = input->q = input->text;
}
else if (ui.mod == GLFW_MOD_SHIFT)
else if (ui.mod == GLUT_ACTIVE_SHIFT)
{
input->q = input->text;
}
Expand All @@ -182,15 +182,15 @@ static int ui_input_key(struct input *input)
break;
case KEY_DOWN:
case KEY_END:
if (ui.mod == GLFW_MOD_CONTROL + GLFW_MOD_SHIFT)
if (ui.mod == GLUT_ACTIVE_CTRL + GLUT_ACTIVE_SHIFT)
{
input->q = input->end;
}
else if (ui.mod == GLFW_MOD_CONTROL)
else if (ui.mod == GLUT_ACTIVE_CTRL)
{
input->p = input->q = input->end;
}
else if (ui.mod == GLFW_MOD_SHIFT)
else if (ui.mod == GLUT_ACTIVE_SHIFT)
{
input->q = input->end;
}
Expand Down Expand Up @@ -254,20 +254,20 @@ static int ui_input_key(struct input *input)
char *q = input->p > input->q ? input->p : input->q;
memmove(buf, p, q - p);
buf[q-p] = 0;
glfwSetClipboardString(window, buf);
ui_set_clipboard(buf);
if (ui.key == KEY_CTL_X)
ui_input_delete_selection(input);
}
break;
case KEY_CTL_V:
{
const char *buf = glfwGetClipboardString(window);
const char *buf = ui_get_clipboard();
if (buf)
ui_input_paste(input, buf, (int)strlen(buf));
}
break;
default:
if (ui.key >= 32)
if (ui.key >= 32 && ui.plain)
{
int cat = ucdn_get_general_category(ui.key);
if (ui.key == ' ' || (cat >= UCDN_GENERAL_CATEGORY_LL && cat < UCDN_GENERAL_CATEGORY_ZL))
Expand Down
Loading

0 comments on commit 896830e

Please sign in to comment.