summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Franzke <benjaminfranzke@googlemail.com>2012-03-15 08:28:53 +0100
committerBenjamin Franzke <benjaminfranzke@googlemail.com>2012-03-15 08:44:06 +0100
commit763319ec1e787a12733ae138dee295aabd327882 (patch)
tree3b1a04e97381d7e2c9c14a36029d4ed9d2e662a4
parent5be333052f97c9980a328af2b256ffbff6c6af9b (diff)
downloadcv-763319ec1e787a12733ae138dee295aabd327882.tar.gz
cv-763319ec1e787a12733ae138dee295aabd327882.tar.bz2
cv-763319ec1e787a12733ae138dee295aabd327882.zip
wimmel_gl: Use EGL instead of GLUT by default
That way we can create a context and make it current without creating a window.
-rw-r--r--Makefile2
-rw-r--r--wimmel_gl.c81
2 files changed, 55 insertions, 28 deletions
diff --git a/Makefile b/Makefile
index 310f1d9..a88cebe 100644
--- a/Makefile
+++ b/Makefile
@@ -23,7 +23,7 @@ wimmel_gl: wimmel_gl.o util.o
wimmel_gl:
- $(CC) -lglut `pkg-config --cflags --libs gtk+-2.0 glib-2.0` -o $@ $+
+ $(CC) `pkg-config --cflags --libs gtk+-2.0 glib-2.0 egl gl` -o $@ $+
diff --git a/wimmel_gl.c b/wimmel_gl.c
index 2a42109..dcf4c19 100644
--- a/wimmel_gl.c
+++ b/wimmel_gl.c
@@ -1,13 +1,20 @@
+#include <stdlib.h>
#include <glib.h>
#include <gdk-pixbuf/gdk-pixbuf.h>
#define GL_GLEXT_PROTOTYPES
+#if 0
#include <GL/glut.h>
+#else
+#include <EGL/egl.h>
+#endif
+
#include <GL/gl.h>
#include <GL/glext.h>
#include "util.h"
+EGLDisplay dpy;
GLuint vbo;
GLint proj_uniform, tex_uniform, pixelsize_uniform,
search_rect_uniform, barrier_uniform;
@@ -175,38 +182,31 @@ draw(void)
}
-int
-main(int argc, char **argv)
+static void
+init_gl(void)
{
GLuint fb, rb;
- gint stride;
- guchar *buffer;
-
- g_type_init();
-
+#if 0
glutInit(&argc, argv);
- if (argc <= 1)
- return 1;
-
glutInitDisplayMode(GLUT_RGBA /*| GLUT_DEPTH */ | GLUT_DOUBLE);
-
-
- pixbuf = gdk_pixbuf_new_from_file(argv[1], NULL);
- if (!pixbuf)
- return 1;
-
- width = gdk_pixbuf_get_width(pixbuf);
- height = gdk_pixbuf_get_height(pixbuf);
-
- x1 = atoi(argv[2]);
- y1 = atoi(argv[3]);
- mwidth = atoi(argv[4]);
- mheight = atoi(argv[5]);
-
glutInitWindowSize(1,1);
int window = glutCreateWindow("wimmel");
glutDestroyWindow(window);
+#else
+ dpy = eglGetDisplay(EGL_DEFAULT_DISPLAY);
+ eglInitialize(dpy, NULL, NULL);
+ eglBindAPI(EGL_OPENGL_API);
+ EGLContext ctx = eglCreateContext(dpy, NULL, EGL_NO_CONTEXT, NULL);
+ if (ctx == NULL) {
+ fprintf(stderr, "failed to create context\n");
+ exit(EXIT_FAILURE);
+ }
+ if (!eglMakeCurrent(dpy, EGL_NO_SURFACE, EGL_NO_SURFACE, ctx)) {
+ fprintf(stderr, "failed to make context current\n");
+ exit(EXIT_FAILURE);
+ }
+#endif
glGenFramebuffersEXT(1, &fb);
glGenRenderbuffersEXT(1, &rb);
@@ -223,14 +223,39 @@ main(int argc, char **argv)
if (glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT) !=
GL_FRAMEBUFFER_COMPLETE_EXT) {
- fprintf(stderr, "framebuffer not complete\n");
- return 1;
+ fprintf(stderr, "Framebuffer not complete\n");
+ exit(EXIT_FAILURE);
}
+}
+
+int
+main(int argc, char **argv)
+{
+ gint stride;
+ guchar *buffer;
+
+ g_type_init();
+
+ if (argc <= 5)
+ return 1;
+
+ pixbuf = gdk_pixbuf_new_from_file(argv[1], NULL);
+ if (!pixbuf)
+ return 1;
+
+ width = gdk_pixbuf_get_width(pixbuf);
+ height = gdk_pixbuf_get_height(pixbuf);
+
+ init_gl();
+
+ x1 = atoi(argv[2]);
+ y1 = atoi(argv[3]);
+ mwidth = atoi(argv[4]);
+ mheight = atoi(argv[5]);
init_shaders();
create_texture(pixbuf);
glViewport(0,0,width,height);
-
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
draw();
@@ -264,5 +289,7 @@ main(int argc, char **argv)
free(buffer);
g_object_unref(pixbuf);
+ eglTerminate(dpy);
+
return 0;
}