Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

glfw3 support

  • Loading branch information...
commit 6b8bd1724df451f3b67f8eafd3d60338ef91752f 1 parent 8309433
@dividuum authored
Showing with 36 additions and 26 deletions.
  1. +1 −1  Makefile
  2. +35 −25 main.c
View
2  Makefile
@@ -31,7 +31,7 @@ endif
CFLAGS += -DVERSION='"$(VERSION)"'
CFLAGS += $(LUA_CFLAGS) -I/usr/include/freetype2/ -I/usr/include/ffmpeg -std=c99 -Wall
-LDFLAGS += $(LUA_LDFLAGS) -levent -lglfw -lGL -lGLU -lGLEW -lftgl -lIL -lILU -lavformat -lavcodec -lavutil -lswscale -lz
+LDFLAGS += $(LUA_LDFLAGS) -levent -lglfw3 -lGL -lGLU -lGLEW -lftgl -lIL -lILU -lavformat -lavcodec -lavutil -lswscale -lz -lm -lXi -lX11 -lXxf86vm -lXrandr -lpthread
prefix ?= /usr/local
exec_prefix ?= $(prefix)
View
60 main.c
@@ -23,7 +23,7 @@
#include <GL/glew.h>
#include <GL/gl.h>
#include <GL/glext.h>
-#include <GL/glfw.h>
+#include <GLFW/glfw3.h>
#include <IL/il.h>
#include <IL/ilu.h>
#include <libavformat/avformat.h>
@@ -1079,23 +1079,25 @@ static void check_inotify() {
/*============ GUI ===========*/
static int win_w, win_h;
+static GLFWwindow *window;
-static void GLFWCALL reshape(int width, int height) {
+static void reshape(GLFWwindow* window, int width, int height) {
win_w = width;
win_h = height;
fprintf(stderr, INFO("resized to %dx%d\n"), width, height);
}
-static void GLFWCALL keypressed(int key, int action) {
- if (action == GLFW_PRESS) {
- switch (key) {
- case GLFW_KEY_SPACE:
- node_profiler();
- break;
- case GLFW_KEY_ESC:
- running = 0;
- break;
- }
+static void keypressed(GLFWwindow* window, int key, int scancode, int action, int mods) {
+ if (action != GLFW_PRESS)
+ return;
+
+ switch (key) {
+ case GLFW_KEY_SPACE:
+ node_profiler();
+ break;
+ case GLFW_KEY_ESCAPE:
+ running = 0;
+ break;
}
}
@@ -1359,11 +1361,12 @@ static void tick() {
glClear(GL_COLOR_BUFFER_BIT);
node_render_self(&root, win_w, win_h);
- glfwSwapBuffers();
+ glfwSwapBuffers(window);
+ glfwPollEvents();
node_tree_gc(&root);
- if (!glfwGetWindowParam(GLFW_OPENED))
+ if (glfwWindowShouldClose(window))
running = 0;
}
@@ -1377,7 +1380,7 @@ static void init_default_texture() {
int main(int argc, char *argv[]) {
fprintf(stdout, VERSION_STRING " (" INFO_URL ")\n");
- fprintf(stdout, "Copyright (c) 2013, Florian Wesch <fw@dividuum.de>\n\n");
+ fprintf(stdout, "Copyright (c) 2014, Florian Wesch <fw@dividuum.de>\n\n");
if (argc != 2 || (argc == 2 && !strcmp(argv[1], "-h"))) {
fprintf(stderr,
@@ -1437,9 +1440,8 @@ int main(int argc, char *argv[]) {
open_tcp(&tcp_event);
glfwInit();
- glfwOpenWindowHint(GLFW_FSAA_SAMPLES, 4);
- int mode = getenv("INFOBEAMER_FULLSCREEN") ? GLFW_FULLSCREEN : GLFW_WINDOW;
+ int fullscreen = getenv("INFOBEAMER_FULLSCREEN") != NULL;
int width = 1024;
int height = 768;
@@ -1453,22 +1455,30 @@ int main(int argc, char *argv[]) {
fprintf(stderr, INFO("initial size is %dx%d\n"), width, height);
- if(!glfwOpenWindow(width, height, 8,8,8,8, 0,0, mode))
+ GLFWmonitor* monitor = glfwGetPrimaryMonitor();
+ if (!fullscreen)
+ monitor = NULL;
+
+ window = glfwCreateWindow(width, height, VERSION_STRING, monitor, NULL);
+ if (!window)
die("cannot open window");
+ glfwSetFramebufferSizeCallback(window, reshape);
+ glfwSetKeyCallback(window, keypressed);
+
+ glfwMakeContextCurrent(window);
+ glfwSwapInterval(1);
+
+ glfwGetFramebufferSize(window, &win_w, &win_h);
+
GLenum err = glewInit();
if (err != GLEW_OK)
die("cannot initialize glew");
if (!glewIsSupported("GL_VERSION_2_0"))
die("need opengl 2.0 support\n");
- glfwSetWindowTitle(VERSION_STRING);
- glfwSwapInterval(1);
- glfwSetWindowSizeCallback(reshape);
- glfwSetKeyCallback(keypressed);
-
- if (mode == GLFW_FULLSCREEN)
- glfwDisable(GLFW_MOUSE_CURSOR);
+ if (fullscreen)
+ glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_DISABLED);
ilInit();
iluInit();

1 comment on commit 6b8bd17

@xmw

You need to drop the #include from shader.c and font.c, too.
Maybe you can drop some other unneeded includes, too.

Please sign in to comment.
Something went wrong with that request. Please try again.