Created
July 22, 2016 17:41
-
-
Save abadams/7f0a2c0bc4811a9ca3191e42057a6a02 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/apps/opengl_demo/Makefile b/apps/opengl_demo/Makefile | |
index 8c75fa5..a9fc30f 100644 | |
--- a/apps/opengl_demo/Makefile | |
+++ b/apps/opengl_demo/Makefile | |
@@ -26,12 +26,14 @@ ifeq ($(UNAME),Darwin) | |
# These are for OS X: | |
DTX_FONT = /Library/Fonts/Arial.ttf | |
OPENGL_LIBS = -lglfw3 -framework OpenGL -framework GLUT | |
+ GENERATOR_LIBS = -lHalide -lz -lcurses | |
else | |
# These are for Ubuntu Linux | |
DTX_FONT = /usr/share/fonts/truetype/dejavu/DejaVuSans.ttf | |
- OPENGL_LIBS = -lglfw -lGL -lglut -lX11 -lpthread -ldl | |
+ OPENGL_LIBS = `pkg-config glfw3 --libs` -lGL -lglut -lX11 -lpthread -ldl -lXxf86vm -lXinerama -lXcursor -lXrandr | |
+ GENERATOR_LIBS = -lHalide -lz -lcurses -Wl,--rpath=$(HALIDE_LIB_PATH) | |
endif | |
@@ -45,7 +47,7 @@ CXXFLAGS = -std=c++11 -g -DDTX_FONT=\"$(DTX_FONT)\" $(HALIDE_INC_PATH) | |
.PHONY: run clean | |
default: run | |
- | |
+ | |
run: build/opengl_demo | |
build/opengl_demo image.png | |
diff --git a/apps/opengl_demo/glfw_helpers.cpp b/apps/opengl_demo/glfw_helpers.cpp | |
index 80484e9..e605e36 100644 | |
--- a/apps/opengl_demo/glfw_helpers.cpp | |
+++ b/apps/opengl_demo/glfw_helpers.cpp | |
@@ -1,7 +1,7 @@ | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <GLFW/glfw3.h> | |
- | |
+#include <unistd.h> | |
#include "glfw_helpers.h" | |
using namespace GlfwHelpers; | |
@@ -26,6 +26,12 @@ static void key_callback(GLFWwindow *window, int key, int scancode, int action, | |
glfwSetWindowShouldClose(window, GL_TRUE); | |
} | |
+static bool first_focus = false; | |
+static void focus_callback(GLFWwindow *window, int) | |
+{ | |
+ first_focus = true; | |
+} | |
+ | |
struct info GlfwHelpers::setup(int width, int height) | |
{ | |
struct info info; | |
@@ -36,8 +42,13 @@ struct info GlfwHelpers::setup(int width, int height) | |
window = glfwCreateWindow(width, height, "opengl_halide_test", NULL, NULL); | |
if (!window) die("couldn't create window!"); | |
glfwSetKeyCallback(window, key_callback); | |
+ glfwSetWindowFocusCallback(window, focus_callback); | |
glfwMakeContextCurrent(window); | |
+ while (!first_focus) { | |
+ glfwWaitEvents(); | |
+ } | |
+ | |
int framebuffer_width, framebuffer_height; | |
glfwGetFramebufferSize(window, &framebuffer_width, &framebuffer_height); | |
info.dpi_scale = float(framebuffer_width) / float(width); | |
diff --git a/apps/opengl_demo/opengl_helpers.cpp b/apps/opengl_demo/opengl_helpers.cpp | |
index a162000..8d9c577 100644 | |
--- a/apps/opengl_demo/opengl_helpers.cpp | |
+++ b/apps/opengl_demo/opengl_helpers.cpp | |
@@ -10,6 +10,7 @@ void OpenGLHelpers::setup(float dpi_scale) | |
{ | |
const int scaled_font_size = font_size * dpi_scale; | |
dtx_use_font(dtx_open_font(DTX_FONT, scaled_font_size), scaled_font_size); | |
+ glClear(GL_COLOR_BUFFER_BIT); | |
} | |
GLuint OpenGLHelpers::create_texture(int width, int height, const uint8_t *data) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Forget the unistd thing, forgot to delete that