English 中文(简体)
How to create a cairo-gl surface under Gtk
原标题:
  • 时间:2011-05-24 05:13:06
  •  标签:
  • cairo
  • gtk3

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?)





相关问题
Plotting by Using gnuplot and Glade

I am a new programmer. It is not my job but i want to learn python. I am a Windows 10 user and I am using the folllowing programs: Python 3.8 Gtk+ Glade Gnuplot Pycharm. I have installed the first 4 ...

How to use CssStyleProvider in Gtkmm3

I m programming in c++ with gtkmm3. I want to change some fonts in my program. I read all the things about CssStyleProvider, StyleContext in gtkmm documentation and also in gtk+ documentaion but i ...

pydev on aptana3 unable to import gi.repository

the following code should work import gi import gi.repository this works in a python shell. And it also works if I save the file as a script then launch it in a terminal. but in aptana3 i get this: ...

How to set bg image of a window in a GTK3 application

I found this way: GdkPixmap *backPixMap = gdk_pixmap_create_from_xpm ( window , NULL , NULL , fileName ); gdk_window_set_back_pixmap( GTK_WIDGET( window )->window , backPixMap , FALSE ); but it ...

How to create a cairo-gl surface under Gtk

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 ...

Setting Cursor-Color in GTK+ 3

I m looking to set a GtkTextView cursor-color. I know I can do it through the gtk_rc_parse command or something similar, but the documentation says that those commands are depreciated, and I don t ...

Learning GUI programming with GTK+2 or GTK+3?

I am new to GUI programming, and I haven t found yet what library is best for my purpose (i want to make desktop environment applications, eg. docks, panels, desklets etc.) I have started learning ...

热门标签