英文:
Paint to screen with go-cairo
问题
我正在使用http://github.com/ungerik/go-cairo作为cairo库来绘制屏幕。我对这个库和cairo一般都不熟悉;然而,我一直在查阅这个库和其他语言的cairo绑定的文档,希望能够理解如何绘制到屏幕(不幸的是,我没有找到很多关于绘制到屏幕的教程,只有保存图像为.PNG的教程)。
这是我目前的代码,但是没有产生任何效果(没有显示任何内容)。希望能得到帮助。
package main
import (
"github.com/ungerik/go-cairo"
"time"
)
func main() {
surface := cairo.NewSurface (cairo.FORMAT_ARGB32, 240, 80)
surface.SelectFontFace ("serif", cairo.FONT_SLANT_NORMAL,
cairo.FONT_WEIGHT_BOLD)
surface.SetFontSize(32.0)
surface.SetSourceRGB(0.0, 0.0, 1.0)
surface.MoveTo (10.0, 50.0)
surface.ShowText ("Hello World")
for {
surface.Paint ()
time.Sleep (1000)
}
//surface.Finish()
}
英文:
I'm using http://github.com/ungerik/go-cairo as a cairo library to paint to the screen. I'm completely unfamiliar with this library and cairo in general; however, I've been scouring over documentation for both this library and various cairo bindings for other languages hoping to understand how to paint to screen (unfortunately, I haven't been able to find many tutorials for painting to the screen--only for saving images as .PNGs).
This is what I have so far, and it's not producing any effect (nothing displays). Any help would be appreciated.
package main
import (
"github.com/ungerik/go-cairo"
"time"
)
func main() {
surface := cairo.NewSurface (cairo.FORMAT_ARGB32, 240, 80)
surface.SelectFontFace ("serif", cairo.FONT_SLANT_NORMAL,
cairo.FONT_WEIGHT_BOLD)
surface.SetFontSize(32.0)
surface.SetSourceRGB(0.0, 0.0, 1.0)
surface.MoveTo (10.0, 50.0)
surface.ShowText ("Hello World")
for {
surface.Paint ()
time.Sleep (1000)
}
//surface.Finish()
}
答案1
得分: 4
如果您正在使用Linux<br>
这是一个示例 https://github.com/Joker/go-cairo/blob/master/example/xcb_joy.go<br>
您必须使用go-cairo的分支 https://github.com/Joker/go-cairo<br>
并且必须安装XCB
英文:
If you are using Linux<br>
here's an example https://github.com/Joker/go-cairo/blob/master/example/xcb_joy.go<br>
you have to use a go-cairo fork https://github.com/Joker/go-cairo<br>
and XCB must be installed
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论