How to mix OpenGL and non-OpenGL drawing commands in the same window?

View: New views
2 Messages — Rating Filter:   Alert me  

How to mix OpenGL and non-OpenGL drawing commands in the same window?

by BALLABIO GERARDO-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi all,
may I ask your help.

I'm trying to render an OpenGL scene on a GtkGLExt window (to be precise I'm using gtkglextmm) and then to draw over it with plain Gtk+ drawing commands (that is, Gdk or Cairo).

Specifically, I want to draw some text in the same font used by the other widgets in my gtkglmm application. From the example in the documentation (http://gtkglext.sourceforge.net/reference/gtkglextmm/font_8cc-example.html) I see that the recommended method for drawing text is to map every individual character onto an OpenGL display list. But that is suboptimal as the text is rendered without antialiasing, ligatures etc. When compared to the text in neighboring widgets, the difference is easily spotted; some fonts look really ugly. Furthermore, handling non-ascii text (for example non-Latin languages) is going to introduce extra complexity. It would be much better if I could draw text directly from a Pango layout.

So I tried adding some Cairo commands after the OpenGL commands in the expose handler. This works only partially: it is ok if the window is only redrawn occasionally, but if I refresh it at a given framerate, as I need to, the text "flashes" (try the attached example). I understand that GtkGLExt suppresses the normal Gtk+ double buffering, and relies on OpenGL's own double buffering; so when the OpenGL buffers are switched, the text drawn by Cairo gets erased on screen, and only after some delay it is redrawn. Thus the "flashing".

Is my diagnosis correct? If so, how can I work around this problem? Can I restore the Gtk+ double buffering, so that the window is actually redrawn after *both* the OpenGL scene *and* the Cairo text have been drawn? Or can I direct Cairo to draw on the OpenGL back buffer? Or is there another way?

Thanks for any help that you can give me.

Gerardo


_______________________________________________
gtkglext-list mailing list
gtkglext-list@...
http://mail.gnome.org/mailman/listinfo/gtkglext-list

test.cc (4K) Download Attachment

Re: How to mix OpenGL and non-OpenGL drawing commands in the same window?

by BALLABIO GERARDO-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

> I'm trying to render an OpenGL scene on a GtkGLExt window (to
> be precise I'm using gtkglextmm) and then to draw over it
> with plain Gtk+ drawing commands (that is, Gdk or Cairo).
>
> Specifically, I want to draw some text in the same font used
> by the other widgets in my gtkglmm application.
                             ^^^^^^^
                             (that should've been gtkmm)

Just to let you know that I found a way to do that. Example attached.

In short, I copy a region from the OpenGL back buffer to an off-screen pixmap, draw over it (in this example it's text but you can draw anything) using Cairo, and copy the modified image back. Then swap buffers and everything is displayed with no flashing.

Gerardo


_______________________________________________
gtkglext-list mailing list
gtkglext-list@...
http://mail.gnome.org/mailman/listinfo/gtkglext-list

text.cc (6K) Download Attachment