annotate src/gtkglext-test.c @ 964:9fb37f10b037

test program for package gtkglext (by Martin Gerhardy)
author Volker Grabsch <vog@notjusthosting.com>
date Fri, 14 May 2010 00:21:49 +0200
parents
children a57c09f1b3f2
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
964
9fb37f10b037 test program for package gtkglext (by Martin Gerhardy)
Volker Grabsch <vog@notjusthosting.com>
parents:
diff changeset
1 /* This file is part of mingw-cross-env. */
9fb37f10b037 test program for package gtkglext (by Martin Gerhardy)
Volker Grabsch <vog@notjusthosting.com>
parents:
diff changeset
2 /* See doc/index.html for further information. */
9fb37f10b037 test program for package gtkglext (by Martin Gerhardy)
Volker Grabsch <vog@notjusthosting.com>
parents:
diff changeset
3
9fb37f10b037 test program for package gtkglext (by Martin Gerhardy)
Volker Grabsch <vog@notjusthosting.com>
parents:
diff changeset
4 #include <gtk/gtk.h>
9fb37f10b037 test program for package gtkglext (by Martin Gerhardy)
Volker Grabsch <vog@notjusthosting.com>
parents:
diff changeset
5 #include <gtk/gtkgl.h>
9fb37f10b037 test program for package gtkglext (by Martin Gerhardy)
Volker Grabsch <vog@notjusthosting.com>
parents:
diff changeset
6 #include <GL/gl.h>
9fb37f10b037 test program for package gtkglext (by Martin Gerhardy)
Volker Grabsch <vog@notjusthosting.com>
parents:
diff changeset
7
9fb37f10b037 test program for package gtkglext (by Martin Gerhardy)
Volker Grabsch <vog@notjusthosting.com>
parents:
diff changeset
8 static gboolean eventExpose(GtkWidget *gl, GdkEventExpose *e, gpointer userData)
9fb37f10b037 test program for package gtkglext (by Martin Gerhardy)
Volker Grabsch <vog@notjusthosting.com>
parents:
diff changeset
9 {
9fb37f10b037 test program for package gtkglext (by Martin Gerhardy)
Volker Grabsch <vog@notjusthosting.com>
parents:
diff changeset
10 GdkGLContext *ctx = gtk_widget_get_gl_context(gl);
9fb37f10b037 test program for package gtkglext (by Martin Gerhardy)
Volker Grabsch <vog@notjusthosting.com>
parents:
diff changeset
11 GdkGLDrawable *drawable = gtk_widget_get_gl_drawable(gl);
9fb37f10b037 test program for package gtkglext (by Martin Gerhardy)
Volker Grabsch <vog@notjusthosting.com>
parents:
diff changeset
12
9fb37f10b037 test program for package gtkglext (by Martin Gerhardy)
Volker Grabsch <vog@notjusthosting.com>
parents:
diff changeset
13 gdk_gl_drawable_gl_begin(drawable, ctx);
9fb37f10b037 test program for package gtkglext (by Martin Gerhardy)
Volker Grabsch <vog@notjusthosting.com>
parents:
diff changeset
14
9fb37f10b037 test program for package gtkglext (by Martin Gerhardy)
Volker Grabsch <vog@notjusthosting.com>
parents:
diff changeset
15 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
9fb37f10b037 test program for package gtkglext (by Martin Gerhardy)
Volker Grabsch <vog@notjusthosting.com>
parents:
diff changeset
16
9fb37f10b037 test program for package gtkglext (by Martin Gerhardy)
Volker Grabsch <vog@notjusthosting.com>
parents:
diff changeset
17 if (!gdk_gl_drawable_is_double_buffered(drawable))
9fb37f10b037 test program for package gtkglext (by Martin Gerhardy)
Volker Grabsch <vog@notjusthosting.com>
parents:
diff changeset
18 glFinish();
9fb37f10b037 test program for package gtkglext (by Martin Gerhardy)
Volker Grabsch <vog@notjusthosting.com>
parents:
diff changeset
19 else
9fb37f10b037 test program for package gtkglext (by Martin Gerhardy)
Volker Grabsch <vog@notjusthosting.com>
parents:
diff changeset
20 gdk_gl_drawable_swap_buffers(drawable);
9fb37f10b037 test program for package gtkglext (by Martin Gerhardy)
Volker Grabsch <vog@notjusthosting.com>
parents:
diff changeset
21
9fb37f10b037 test program for package gtkglext (by Martin Gerhardy)
Volker Grabsch <vog@notjusthosting.com>
parents:
diff changeset
22 gdk_gl_drawable_gl_end(drawable);
9fb37f10b037 test program for package gtkglext (by Martin Gerhardy)
Volker Grabsch <vog@notjusthosting.com>
parents:
diff changeset
23
9fb37f10b037 test program for package gtkglext (by Martin Gerhardy)
Volker Grabsch <vog@notjusthosting.com>
parents:
diff changeset
24 return TRUE;
9fb37f10b037 test program for package gtkglext (by Martin Gerhardy)
Volker Grabsch <vog@notjusthosting.com>
parents:
diff changeset
25 }
9fb37f10b037 test program for package gtkglext (by Martin Gerhardy)
Volker Grabsch <vog@notjusthosting.com>
parents:
diff changeset
26
9fb37f10b037 test program for package gtkglext (by Martin Gerhardy)
Volker Grabsch <vog@notjusthosting.com>
parents:
diff changeset
27 static gboolean eventConfigure(GtkWidget *gl, GdkEventConfigure *e, gpointer userData)
9fb37f10b037 test program for package gtkglext (by Martin Gerhardy)
Volker Grabsch <vog@notjusthosting.com>
parents:
diff changeset
28 {
9fb37f10b037 test program for package gtkglext (by Martin Gerhardy)
Volker Grabsch <vog@notjusthosting.com>
parents:
diff changeset
29 const guint width = gl->allocation.width;
9fb37f10b037 test program for package gtkglext (by Martin Gerhardy)
Volker Grabsch <vog@notjusthosting.com>
parents:
diff changeset
30 const guint height = gl->allocation.height;
9fb37f10b037 test program for package gtkglext (by Martin Gerhardy)
Volker Grabsch <vog@notjusthosting.com>
parents:
diff changeset
31
9fb37f10b037 test program for package gtkglext (by Martin Gerhardy)
Volker Grabsch <vog@notjusthosting.com>
parents:
diff changeset
32 glLoadIdentity();
9fb37f10b037 test program for package gtkglext (by Martin Gerhardy)
Volker Grabsch <vog@notjusthosting.com>
parents:
diff changeset
33 glViewport(0, 0, width, height);
9fb37f10b037 test program for package gtkglext (by Martin Gerhardy)
Volker Grabsch <vog@notjusthosting.com>
parents:
diff changeset
34 glOrtho(-3.5, 3.5, -3.5 * (GLfloat)height / (GLfloat)width,
9fb37f10b037 test program for package gtkglext (by Martin Gerhardy)
Volker Grabsch <vog@notjusthosting.com>
parents:
diff changeset
35 3.5 * (GLfloat)height / (GLfloat)width, -3.5, 3.5);
9fb37f10b037 test program for package gtkglext (by Martin Gerhardy)
Volker Grabsch <vog@notjusthosting.com>
parents:
diff changeset
36
9fb37f10b037 test program for package gtkglext (by Martin Gerhardy)
Volker Grabsch <vog@notjusthosting.com>
parents:
diff changeset
37 return TRUE;
9fb37f10b037 test program for package gtkglext (by Martin Gerhardy)
Volker Grabsch <vog@notjusthosting.com>
parents:
diff changeset
38 }
9fb37f10b037 test program for package gtkglext (by Martin Gerhardy)
Volker Grabsch <vog@notjusthosting.com>
parents:
diff changeset
39
9fb37f10b037 test program for package gtkglext (by Martin Gerhardy)
Volker Grabsch <vog@notjusthosting.com>
parents:
diff changeset
40 int main(int argc, char *argv[])
9fb37f10b037 test program for package gtkglext (by Martin Gerhardy)
Volker Grabsch <vog@notjusthosting.com>
parents:
diff changeset
41 {
9fb37f10b037 test program for package gtkglext (by Martin Gerhardy)
Volker Grabsch <vog@notjusthosting.com>
parents:
diff changeset
42 GtkWidget* window;
9fb37f10b037 test program for package gtkglext (by Martin Gerhardy)
Volker Grabsch <vog@notjusthosting.com>
parents:
diff changeset
43 GtkWidget* gl;
9fb37f10b037 test program for package gtkglext (by Martin Gerhardy)
Volker Grabsch <vog@notjusthosting.com>
parents:
diff changeset
44 GdkGLConfig* glConfig;
9fb37f10b037 test program for package gtkglext (by Martin Gerhardy)
Volker Grabsch <vog@notjusthosting.com>
parents:
diff changeset
45
9fb37f10b037 test program for package gtkglext (by Martin Gerhardy)
Volker Grabsch <vog@notjusthosting.com>
parents:
diff changeset
46 gtk_init(&argc, &argv);
9fb37f10b037 test program for package gtkglext (by Martin Gerhardy)
Volker Grabsch <vog@notjusthosting.com>
parents:
diff changeset
47 gtk_gl_init(&argc, &argv);
9fb37f10b037 test program for package gtkglext (by Martin Gerhardy)
Volker Grabsch <vog@notjusthosting.com>
parents:
diff changeset
48
9fb37f10b037 test program for package gtkglext (by Martin Gerhardy)
Volker Grabsch <vog@notjusthosting.com>
parents:
diff changeset
49 window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
9fb37f10b037 test program for package gtkglext (by Martin Gerhardy)
Volker Grabsch <vog@notjusthosting.com>
parents:
diff changeset
50 gl = gtk_drawing_area_new();
9fb37f10b037 test program for package gtkglext (by Martin Gerhardy)
Volker Grabsch <vog@notjusthosting.com>
parents:
diff changeset
51 gtk_container_add(GTK_CONTAINER(window), gl);
9fb37f10b037 test program for package gtkglext (by Martin Gerhardy)
Volker Grabsch <vog@notjusthosting.com>
parents:
diff changeset
52
9fb37f10b037 test program for package gtkglext (by Martin Gerhardy)
Volker Grabsch <vog@notjusthosting.com>
parents:
diff changeset
53 gtk_widget_set_events(gl, GDK_EXPOSURE_MASK);
9fb37f10b037 test program for package gtkglext (by Martin Gerhardy)
Volker Grabsch <vog@notjusthosting.com>
parents:
diff changeset
54
9fb37f10b037 test program for package gtkglext (by Martin Gerhardy)
Volker Grabsch <vog@notjusthosting.com>
parents:
diff changeset
55 glConfig = gdk_gl_config_new_by_mode(
9fb37f10b037 test program for package gtkglext (by Martin Gerhardy)
Volker Grabsch <vog@notjusthosting.com>
parents:
diff changeset
56 GDK_GL_MODE_RGB |
9fb37f10b037 test program for package gtkglext (by Martin Gerhardy)
Volker Grabsch <vog@notjusthosting.com>
parents:
diff changeset
57 GDK_GL_MODE_ALPHA |
9fb37f10b037 test program for package gtkglext (by Martin Gerhardy)
Volker Grabsch <vog@notjusthosting.com>
parents:
diff changeset
58 GDK_GL_MODE_DEPTH |
9fb37f10b037 test program for package gtkglext (by Martin Gerhardy)
Volker Grabsch <vog@notjusthosting.com>
parents:
diff changeset
59 GDK_GL_MODE_DOUBLE);
9fb37f10b037 test program for package gtkglext (by Martin Gerhardy)
Volker Grabsch <vog@notjusthosting.com>
parents:
diff changeset
60
9fb37f10b037 test program for package gtkglext (by Martin Gerhardy)
Volker Grabsch <vog@notjusthosting.com>
parents:
diff changeset
61 gtk_widget_set_gl_capability(gl, glConfig,
9fb37f10b037 test program for package gtkglext (by Martin Gerhardy)
Volker Grabsch <vog@notjusthosting.com>
parents:
diff changeset
62 NULL, TRUE, GDK_GL_RGBA_TYPE);
9fb37f10b037 test program for package gtkglext (by Martin Gerhardy)
Volker Grabsch <vog@notjusthosting.com>
parents:
diff changeset
63
9fb37f10b037 test program for package gtkglext (by Martin Gerhardy)
Volker Grabsch <vog@notjusthosting.com>
parents:
diff changeset
64 g_signal_connect_swapped(
9fb37f10b037 test program for package gtkglext (by Martin Gerhardy)
Volker Grabsch <vog@notjusthosting.com>
parents:
diff changeset
65 G_OBJECT(window), "destroy",
9fb37f10b037 test program for package gtkglext (by Martin Gerhardy)
Volker Grabsch <vog@notjusthosting.com>
parents:
diff changeset
66 G_CALLBACK(gtk_main_quit), G_OBJECT(window));
9fb37f10b037 test program for package gtkglext (by Martin Gerhardy)
Volker Grabsch <vog@notjusthosting.com>
parents:
diff changeset
67
9fb37f10b037 test program for package gtkglext (by Martin Gerhardy)
Volker Grabsch <vog@notjusthosting.com>
parents:
diff changeset
68 g_signal_connect(
9fb37f10b037 test program for package gtkglext (by Martin Gerhardy)
Volker Grabsch <vog@notjusthosting.com>
parents:
diff changeset
69 G_OBJECT(window), "destroy",
9fb37f10b037 test program for package gtkglext (by Martin Gerhardy)
Volker Grabsch <vog@notjusthosting.com>
parents:
diff changeset
70 G_CALLBACK(gtk_main_quit), NULL);
9fb37f10b037 test program for package gtkglext (by Martin Gerhardy)
Volker Grabsch <vog@notjusthosting.com>
parents:
diff changeset
71
9fb37f10b037 test program for package gtkglext (by Martin Gerhardy)
Volker Grabsch <vog@notjusthosting.com>
parents:
diff changeset
72 g_signal_connect(gl, "configure-event",
9fb37f10b037 test program for package gtkglext (by Martin Gerhardy)
Volker Grabsch <vog@notjusthosting.com>
parents:
diff changeset
73 G_CALLBACK(eventConfigure), NULL);
9fb37f10b037 test program for package gtkglext (by Martin Gerhardy)
Volker Grabsch <vog@notjusthosting.com>
parents:
diff changeset
74
9fb37f10b037 test program for package gtkglext (by Martin Gerhardy)
Volker Grabsch <vog@notjusthosting.com>
parents:
diff changeset
75 g_signal_connect(gl, "expose-event",
9fb37f10b037 test program for package gtkglext (by Martin Gerhardy)
Volker Grabsch <vog@notjusthosting.com>
parents:
diff changeset
76 G_CALLBACK(eventExpose), NULL);
9fb37f10b037 test program for package gtkglext (by Martin Gerhardy)
Volker Grabsch <vog@notjusthosting.com>
parents:
diff changeset
77
9fb37f10b037 test program for package gtkglext (by Martin Gerhardy)
Volker Grabsch <vog@notjusthosting.com>
parents:
diff changeset
78 gtk_widget_show_all(window);
9fb37f10b037 test program for package gtkglext (by Martin Gerhardy)
Volker Grabsch <vog@notjusthosting.com>
parents:
diff changeset
79
9fb37f10b037 test program for package gtkglext (by Martin Gerhardy)
Volker Grabsch <vog@notjusthosting.com>
parents:
diff changeset
80 gtk_main();
9fb37f10b037 test program for package gtkglext (by Martin Gerhardy)
Volker Grabsch <vog@notjusthosting.com>
parents:
diff changeset
81 return 0;
9fb37f10b037 test program for package gtkglext (by Martin Gerhardy)
Volker Grabsch <vog@notjusthosting.com>
parents:
diff changeset
82 }