c - Compilation errors when using GTK2+ with OpenGL? -
i writing c program makes use of fixed pipeline opengl , freeglut. however, use complete toolkit gtk+ instead of freeglut. cannot use gtk3+ not compatible old opengl code, use gtk2+.
i found this link example program called simple.c:
#include <math.h> #include <gtk/gtk.h> #include <gl/gl.h> #include <gtkgl/gtkglarea.h> int init (gtkwidget *widget) { if (gtk_gl_area_make_current (gtk_gl_area(widget))) { glviewport(0,0, widget->allocation.width, widget->allocation.height); glmatrixmode(gl_projection); glloadidentity(); glortho(0,100, 100,0, -1,1); glmatrixmode(gl_modelview); glloadidentity(); } return true; } int draw (gtkwidget *widget, gdkeventexpose *event) { if (event->count > 0) return true; if (gtk_gl_area_make_current (gtk_gl_area(widget))) { glclearcolor(0,0,0,1); glclear(gl_color_buffer_bit); glcolor3f(1,1,1); glbegin(gl_triangles); glvertex2f(10,10); glvertex2f(10,90); glvertex2f(90,90); glend(); gtk_gl_area_swap_buffers (gtk_gl_area(widget)); } return true; } int reshape (gtkwidget *widget, gdkeventconfigure *event) { if (gtk_gl_area_make_current (gtk_gl_area(widget))) glviewport(0,0, widget->allocation.width, widget->allocation.height); return true; } int main (int argc, char **argv) { gtkwidget *window, *glarea; int attrlist[] = { gdk_gl_rgba, gdk_gl_red_size,1, gdk_gl_green_size,1, gdk_gl_blue_size,1, gdk_gl_doublebuffer, gdk_gl_none }; gtk_init (&argc, &argv); if (gdk_gl_query () == false) return 0; window = gtk_window_new (gtk_window_toplevel); gtk_window_set_title (gtk_window(window), "simple"); gtk_container_set_border_width (gtk_container(window), 10); g_signal_connect (window, "delete_event", g_callback (gtk_main_quit), null); /* should delete gtk_gl_area widgets before exit or else glx contexts left undeleted, may cause problems (=core dump) in systems. destroy method of objects not automatically called on exit. need manually enable feature. gtk_quit_add_destroy() top level windows unless destroy signal other means. */ gtk_quit_add_destroy (1, gtk_object(window)); glarea = gtk_widget(gtk_gl_area_new (attrlist)); gtk_widget_set_size_request (gtk_widget(glarea), 100, 100); gtk_widget_set_events (gtk_widget(glarea), gdk_exposure_mask | gdk_button_press_mask); g_signal_connect (glarea, "expose_event", g_callback(draw), null); g_signal_connect (glarea, "configure_event", g_callback(reshape), null); g_signal_connect (glarea, "realize", g_callback(init), null); gtk_container_add (gtk_container(window), gtk_widget(glarea)); gtk_widget_show (gtk_widget(glarea)); gtk_widget_show (gtk_widget(window)); gtk_main (); return 0; }
but unfortunately requeries file don't know get, gtk_opengl.h
i unsuccessfully tried compile simple.c code
gcc simple.c -o helloworld `pkg-config --libs gtk+-2.0`
and, of course, got following error:
fatal error: gtk_opengl.h: no such file or directory
any ideas on how make simple.c compile? or on how combine opengl gtk2+?
on debian stable box had install libgtkgl2.0-dev
, add --cflags
& gtkgl-2.0
pkg-config
invocation:
gcc simple.c -o helloworld `pkg-config --cflags --libs gtk+-2.0 gtkgl-2.0`
Comments
Post a Comment