+/*
+ * Copyright (C) 2009-2010 Andy Spencer <andy753421@gmail.com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
#define GL_GLEXT_PROTOTYPES
#include <gtk/gtk.h>
#include <gtk/gtkgl.h>
return tex;
}
+gchar *gl_program_log(guint program, int *_len)
+{
+ gchar *buf = NULL;
+ int len = 0;
+ glGetProgramiv(program, GL_INFO_LOG_LENGTH, &len);
+ if (len > 0) {
+ buf = g_malloc(len);
+ glGetProgramInfoLog(program, len, &len, buf);
+ }
+ if (_len)
+ *_len = len;
+ return buf;
+}
+
+static void load_shader(gchar *filename)
+{
+ gchar *source;
+ gboolean status = g_file_get_contents(filename, &source, NULL, NULL);
+ if (!status)
+ g_error("Failed to load shader");
+
+ guint program = glCreateProgram();
+ if (!program)
+ g_error("Error creating program");
+
+ guint shader = glCreateShader(GL_VERTEX_SHADER_ARB);
+ if (!shader)
+ g_error("Error creating shader");
+
+ glShaderSource(shader, 1, (const gchar**)&source, NULL);
+ if (glGetError())
+ g_error("Error setting shader source");
+
+ glCompileShader(shader);
+ if (glGetError())
+ g_error("Error compiling shader");
+
+ glAttachShader(program, shader);
+ if (glGetError())
+ g_error("Error attaching shader");
+
+ glLinkProgram(program);
+ if (glGetError())
+ g_error("Error linking program");
+
+ glUseProgram(program);
+ if (glGetError())
+ g_error("Error using program:\n%s", gl_program_log(program, NULL));
+}
+
int main(int argc, char **argv)
{
gtk_init(&argc, &argv);
/* Load texture */
tex = load_tex("flag.png");
+ /* Load shader */
+ load_shader("sort.glsl");
+
gtk_main();
gdk_gl_drawable_gl_end(gldrawable);