I want to create a window using GTK 3 under linux (fedora 12) and draw on it a simple rectangle using cairo-gl backend, for this I want to create a cairo-gl surface. How can I do this, can anybody help me with a sample code.
Thanks in advance.
RC7
I want to create a window using GTK 3 under linux (fedora 12) and draw on it a simple rectangle using cairo-gl backend, for this I want to create a cairo-gl surface. How can I do this, can anybody help me with a sample code.
Thanks in advance.
RC7
Well, first of all you need to make sure your cairo version has gl support. I'm not sure the version in Fedora 12 has it. You may have to compile your own cairo.
Then you need to look at cairo-gl.h: http://cgit.freedesktop.org/cairo/tree/src/cairo-gl.h
This file has a nice comment explaining that first you need to create a cairo_device using your gl context and then pass it to cairo_gl_surface_create().
This file from the cairo test suite contains an example of a gl surface: http://cgit.freedesktop.org/cairo/tree/test/gl-surface-source.c
Notice that it is a .c file that includes another .c file: http://cgit.freedesktop.org/cairo/tree/test/set-source.c
The test suite is full of cairo programming examples. Use it! :)
I'm not sure how you do GL using GTK3, but in the worst case, you can use GDK to get X11's Display and Window IDs, then you use standard glx calls: http://developer.gnome.org/gdk3/stable/gdk3-X-Window-System-Interaction.html
And to use cairo with GTK3, you need to look at this: http://developer.gnome.org/gdk3/stable/gdk3-Cairo-Interaction.html And this: http://zetcode.com/tutorials/cairographicstutorial/
I gave you a bunch of Lego bricks. Now you need to assemble them. (Or maybe someone with more time will do it and write a better answer here?)
© 2022 - 2024 — McMap. All rights reserved.