From 763319ec1e787a12733ae138dee295aabd327882 Mon Sep 17 00:00:00 2001 From: Benjamin Franzke Date: Thu, 15 Mar 2012 08:28:53 +0100 Subject: wimmel_gl: Use EGL instead of GLUT by default That way we can create a context and make it current without creating a window. --- Makefile | 2 +- wimmel_gl.c | 81 ++++++++++++++++++++++++++++++++++++++++--------------------- 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 #include #include #define GL_GLEXT_PROTOTYPES +#if 0 #include +#else +#include +#endif + #include #include #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; } -- cgit