OpenGL in GTK+ design



Here are my ideas on the design of OpenGL support for GTK+. For those
that haven't seen it yet, you might want to download what I've coded
thus far:

http://joshbeam.com/files/gdkgl.tar.gz

All that features right now is a GdkGL object that wraps Xlib/GLX.
The 'test' program features a viewport widget with the GL window
inside of it.

The basic goal is to have a GtkGL widget that can easily be created,
packed, and manipulated like any other GtkWidget. Something like this:

    GtkWidget *gl;

    gl = gtk_gl_new(GDK_GL_RGBA | GDK_GL_DOUBLEBUFFER);
    gtk_container_add(GTK_CONTAINER(container), gl);
    gtk_widget_show(gl);

which can then be used like this:

	gtk_gl_make_current(GTK_GL(gl)); /* not necessary if there's only one GtkGL being used */
    glClear(GL_DEPTH_BUFFER_BIT);

    ... more GL stuff...

    glFlush();
    gtk_gl_swap_buffers(GTK_GL(gl));

Of course there would also be functions for setting the depth size,
stencil size, and whatever else would be needed for OpenGL use.

At the lower level, there's a GdkGL object (early version is included
with the file I linked to above) that wraps calls to Xlib/GLX, or
Win32, or whatever library is used on a given platform that we want to
support. The gdk_gl_show() function is passed a GdkGL pointer and a
parent GdkWindow (which would usually be created by the GtkGL widget),
and then creates a GL window as a child of the parent GdkWindow.

That's basically it. The API would be pretty simple, as shown in the
example code above.

I've already started coding a GtkWidget, but it's not quite working
correctly yet; I'll include it with the next tarball of code I post.

Anyone have any comments?

-- 
Josh Beam <josh joshbeam com>
http://joshbeam.com/



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