使用go-cairo在屏幕上绘制

huangapple go评论89阅读模式
英文:

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&lt;br>
您必须使用go-cairo的分支 https://github.com/Joker/go-cairo&lt;br>
并且必须安装XCB

英文:

If you are using Linux<br>
here's an example https://github.com/Joker/go-cairo/blob/master/example/xcb_joy.go&lt;br>
you have to use a go-cairo fork https://github.com/Joker/go-cairo&lt;br>
and XCB must be installed

huangapple
  • 本文由 发表于 2013年3月10日 03:06:09
  • 转载请务必保留本文链接:https://go.coder-hub.com/15314714.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定