如何在Gtk下创建cairo-gl曲面
我想在linux(fedora 12)下使用GTK 3创建一个窗口,并使用cairo-gl后端在其上绘制一个简单的矩形,为此我想创建一个cairo-gl表面。我该如何做到这一点,任何人都可以帮助我提供示例代码。
提前致谢。
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,首先你需要确保你的 cairo 版本有 gl 支持。我不确定 Fedora 12 中的版本是否有它。您可能必须编译自己的 cairo。
然后你需要查看 cairo-gl.h:
http://cgit.freedesktop.org/cairo/tree/src/cairo-gl.h< /a>
该文件有一个很好的注释,解释说首先您需要使用 gl 上下文创建一个 cairo_device,然后将其传递给 cairo_gl_surface_create()。
cairo 测试套件中的此文件包含一个 gl 曲面的示例:
http://cgit.freedesktop.org/cairo/tree/test/gl-surface- source.c
请注意,它是一个 .c 文件,其中包含另一个 .c 文件:
http://cgit.freedesktop.org/cairo/tree/test/set-source.c< /a>
测试套件充满了 cairo 编程示例。使用它! :)
我不确定你如何使用 GTK3 进行 GL,但在最坏的情况下,你可以使用 GDK 获取 X11 的显示和窗口 ID,然后使用标准的 glx 调用:
http://developer.gnome.org/gdk3/stable/gdk3-X- Window-System-Interaction.html
要将 cairo 与 GTK3 一起使用,您需要查看以下内容:
http://developer.gnome.org/gdk3/stable/gdk3-Cairo-Interaction.html< /a>
还有这个:
我
给了你一堆乐高积木。现在你需要组装它们。 (或者也许有更多时间的人会这样做并在这里写出更好的答案?)
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?)