Re: [GtkGLExt] Fwd: Re: GtkGlExt & GTK3



In the end of the day, what we need is (counted from your version for GTK 3):

The core functions:
a function to create an OpenGL context (8 lines of C code)
a function to remove an OpenGL context (6 lines of C code)
a function to set the current OpenGL context (5 lines of C code)
a function to swap front and back buffers (5 lines of C code)

The auxiliary functions:
a function to query if OpenGL is supported (4 lines of C code)
a function to fflush OpenGL events before proceding (1 line of C code)
a function to fflush X events before proceding (1 line of C code)

The grand total ( just pure code, excluding variable declarations, function headers, function brackets) is 30 lines of C code... (and some of these 30 lines are repeated!)

This is specifically for X11 using GLX. We need to find what are the equivalent 30 lines based on GLW that do the same job for Windows. But surely they should be very similar...

The more I know about this issue the more I convince myself that we don't need a library to bridge GTK and OpenGL. In my view, a simple and elegant set of functions like the one I proposed and you ported to GTK 3 is the better approach...

Porting 30 lines of C code to Wayland, Windows, to GTK 4, 5, 6, whatever, cannot be difficult...

I have fond memories of GTKGLArea, I used it for many years, but I am not totally excited about the code they propose (the functions are essentially the same as in 2000). For example:

1) we don't need three functions to create a new GL_context, one is perfectly enough:

GdkGLContext *gdk_gl_context_new(GdkVisual *visual);
GdkGLContext *gdk_gl_context_share_new(GdkVisual *visual, GdkGLContext *sharelist, gint direct); GdkGLContext *gdk_gl_context_attrlist_share_new(int *attrlist, GdkGLContext *sharelist, gint direct);

If this is the first GL context or if you don't want to share contexts, just set context to NULL, otherwise pre-compiled lists, etc. will be shared between the entered context and the new one:

GLXContext gtk_opengl_create (GtkWidget *area, int *attributes, GLXContext context);

The direct rendering attribute could be added (currently I am setting it always to TRUE in glXCreateContext, but it could be left as a 4th argument):
http://www.opengl.org/sdk/docs/man2/xhtml/glXCreateContext.xml

2) we don't need a special function for fonts:
void gdk_gl_use_gdk_font(GdkFont *font, int first, int count, int list_base);

(I know this, I have stroked and extruded fonts rendered with OpenGL on my app):
http://www.gamgi.org/screenshots/screenshot10_2.html
http://www.gamgi.org/screenshots/screenshot10_3.html

3) I am not conviced it is a good ideia to have these (unneeded) macros, enumerations, but without knowing GLW I cannot form a final opinion...

Regards,
Carlos
On 26 February 2014 22:21, Carlos Pereira
<jose carlos pereira ist utl pt>  wrote:
Hi Javier,
thank you very much for your work!
You are welcome! :)

I think this is really good news, it is the first time I see confirmation
that GTK 3 and OpenGL work well. These two examples don't test everything,
but I would be really surprised if something was not working properly, after
this.

The beauty of this approach is that the layer between GTK and OpenGL is so
small, that the maintenance work needed when GTK (or OpenGL) changes is
minimal and the chances of breaking something are also minimal.
I was taking a around, and correct me if Im wrong, but seems that your
api do more or less what the gtkglarea project do: [1]
So maybe it would be a good idea improve this code and eventually
migrate it to GTK+3. Indeed I found that someone already did this job:
[2] What do you think?

Perhaps it is time to start porting my package to GTK 3...
Please do it!

Regards

[1] https://git.gnome.org/browse/gtkglarea/tree/gtkgl/gdkgl.h#n82
[2] https://bugzilla.gnome.org/show_bug.cgi?id=707723




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