Re: OpenGL support in GTK+

Hi, I'm a maintainer of GtkGLExt.

On 9/18/03 23:23, "Jeff Franks" <jcf tpg com au> wrote:

> Josh Beam wrote:
>> On Wed, Sep 17, 2003 at 04:38:37PM -0400, Havoc Pennington wrote:
>> GtkGLExt might be what you're thinking of. But, like Owen said in
>> Bug 119189, it doesn't really fit into the GTK+ model very well.
> This is untrue. GtkGLExt does fit in with the GTK+ 2.0 model. Having
> just written a C++ binding for GtkGLExt I'm familiar with it's
> structure. GtkGLExt is implemented as the interface class,
> GdkGLDrawable, that derives from GTypeInterface, and two classes that
> derive from GObject, GdkGLConfig and GdkGLContext. Then there are
> several functions that extend the GTK+ API. There are two Pango font
> functions, three GDK init functions, three GTK init functions, and there
> are numerous GdkPixmap, GL query, GDK drawing, GdkWindow and GtkWidget
> functions.  That's it. The only thing missing from GtkGLext is
> GtkGLDrawingArea. Currently this is left as a repeditive coding exercise
> for the programmer.
> It shouldn't be too hard to move GtkGLExt into GTK+. I think it would
> best to put it into a separate namespace, gdk-gl, like gdk-pixbuf.
> GdkGLDrawable, GdkGLConfig and GdkGLContext fit would right in with the
> existing GObject system. This leaves:
> 1. Dealing with the GDK and GTK init functions.
> 2. How best to incorporate the extension API for Pango fonts, GdkPixmap,
> GL query, GDK drawing, GdkWindow and GtkWidget  functions.
> 3. There also needs to be a GtkGLDrawingArea widget that derives
> GtkDrawingArea.
> The advantage of GtkGLExt over something like GtkGLArea is that GtkGLExt
> is primarily an interface that can be implemented by any widget, making
> it Open-GL capable. Though most of the time you would only need to use a
> widget like GtkGLDrawingArea, but the flexability is there.

About the "idiosynchratic scheme" Owen said (adding extra gtk_widget_*()
functions), this is why I decided to use such approach...

1. GtkDrawingArea can be used for OpenGL rendering, and no additional widget
   is needed (see low-level.c example in GtkGLExt source). GtkDrawingArea is
   "a widget for custom user interface elements".

2. For glade and libglade, new custom widget cannot be used until glade
   supports it.

3. I'm lazy ;-p

GtkGLExt package is conposed with two libraries, GdkGLExt and GtkGLExt. I
think that GdkGLExt is more important than GtkGLExt. GtkGLExt is just a
simple support library which enables developers to use OpenGL with
GtkDrawingArea. If GdkGLExt library is integrated into GDK, GtkDrawingArea
will be able to support OpenGL, and GtkGLExt library will go away.

 struct _GtkDrawingArea {
  GtkWidget *widget;
  GdkGLWindow *gl_window;
  gpointer draw_data;

 gtk_drawing_area_enable_gl (GtkDrawingArea *drawingarea,
                             GdkGLConfig *glconfig);

 gtk_drawing_area_share_gl_list (GtkDrawingArea *drawingarea,
                                 GdkGLContext *share_list);

 gtk_drawing_area_share_gl_list_with_darea (GtkDrawingArea *drawingarea,
                                            GtkDrawingArea *share_list);

 gtk_drawing_area_set_direct_gl (GtkDrawingArea *drawingarea,
                                 gboolean direct);

 GdkGLContext *
 gtk_drawing_area_create_gl_context (GtkDrawingArea *drawingarea,
                                     GdkGLContext *share_list,
                                     gboolean direct,
                                     int render_type);

 GdkGLContext *
 gtk_drawing_area_get_gl_context (GtkDrawingArea *drawingarea);

 void main (int argc, char **argv)
    GdkGLConfig *glconfig;
    GtkWidget *drawing_area;

    gtk_init (argc, argv);

    glconfig = gdk_gl_config_new_by_mode (GDK_GL_MODE_RGB |
                                          GDK_GL_MODE_DOUBLE |

    drawing_area = gtk_drawing_area_new ();
    gtk_drawing_area_enable_gl (drawing_area, glconfig);
    gtk_drawing_area_set_direct_gl (drawing_area, TRUE);


 static gboolean
 expose_event (GtkDrawingArea *darea,
               GdkEventExpose *event,
               gpointer user_data)
    GdkGLContext *glcontext = gtk_drawing_area_get_gl_context (darea);

    gdk_gl_drawable_begin_gl (darea->gl_window, glcontext);



    gdk_gl_drawable_wait_gl (darea->gl_window);

    gdk_draw_rectangle (darea->window,
                        TRUE, ....);

    gdk_gl_drawable_wait_gdk (darea->gl_window);

    glBegin (GL_QUAD);
    glEnd ();

    if (gdk_gl_drawable_is_double_buffered (darea->gl_window))
       gdk_gl_drawable_swap_buffers (darea->gl_window);
       glFlush ();

    gdk_gl_drawable_end_gl (darea->gl_window);

    return FALSE;

GtkDrawingArea can support both X11 and OpenGL rendering naturally.

Anyway, I don't mind adding new GtkGLDrawingArea or something if GTK+ people
likes it.

I'm just working for new GtkGLExt-2.0 API. If GdkGLExt can be integrated
into GDK, I can work on it instead of GtkGLExt-2.0.


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]