当前位置: 首页>>代码示例>>Golang>>正文


Golang C.TTF_OpenFont函数代码示例

本文整理汇总了Golang中C.TTF_OpenFont函数的典型用法代码示例。如果您正苦于以下问题:Golang TTF_OpenFont函数的具体用法?Golang TTF_OpenFont怎么用?Golang TTF_OpenFont使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了TTF_OpenFont函数的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: LoadFont

func LoadFont(_file string, _size int) (*Font, error) {
	cfile := C.CString(_file)
	defer C.free(unsafe.Pointer(cfile))
	font := C.TTF_OpenFont(cfile, C.int(_size))
	/*if len((*font)) == 0 {
		return nil, errors.New("Font load error: " + GetError())
	}*/
	return (*Font)(font), nil
}
开发者ID:genbattle,项目名称:Go2D,代码行数:9,代码来源:ttf.go

示例2: LoadFont

func LoadFont(_file string, _size int) *Font {
	cfile := C.CString(_file)
	defer C.free(unsafe.Pointer(cfile))
	font := C.TTF_OpenFont(cfile, C.int(_size))
	if font == nil {
		return nil
	}
	return (*Font)(cast(font))
}
开发者ID:gasperko,项目名称:pokemon-universe,代码行数:9,代码来源:ttf.go

示例3: OpenFont

func OpenFont(file string, ptsize int) (*Font, error) {
	cfile := C.CString(file)
	defer C.free(unsafe.Pointer(cfile))
	font := C.TTF_OpenFont(cfile, C.int(ptsize))
	if font == nil {
		return nil, getError()
	}
	return &Font{c: font}, nil
}
开发者ID:willemvds,项目名称:sdl,代码行数:9,代码来源:ttf.go

示例4: OpenFont

func OpenFont(file string, ptsize int) (Font, error) {
	c_file := C.CString(file)
	defer C.free(unsafe.Pointer(c_file))
	c_ptsize := C.int(ptsize)
	ret := C.TTF_OpenFont(c_file, c_ptsize)
	if ret == nil {
		return Font{}, sdl.GetError()
	}
	return Font{unsafe.Pointer(ret)}, nil
}
开发者ID:badgerodon,项目名称:go,代码行数:10,代码来源:ttf.go

示例5: OpenFont

func OpenFont(file string, size int) (*Font, error) {
	_file := (C.CString)(file)
	_size := (C.int)(size)
	f := (*C.TTF_Font)(C.TTF_OpenFont(_file, _size))
	C.free(unsafe.Pointer(_file))
	if f == nil {
		return nil, GetError()
	}
	return &Font{f}, nil
}
开发者ID:hybridgroup,项目名称:go-sdl2,代码行数:10,代码来源:sdl_ttf.go

示例6: OpenFont

// Loads a font from a file at the specified point size.
func OpenFont(file string, ptsize int) *Font {
	cfile := C.CString(file)
	cfont := C.TTF_OpenFont(cfile, C.int(ptsize))
	C.free(unsafe.Pointer(cfile))

	if cfont == nil {
		return nil
	}

	return &Font{cfont}
}
开发者ID:jgastal,项目名称:Go-SDL,代码行数:12,代码来源:ttf.go

示例7: OpenFont

// Loads a font from a file at the specified point size.
func OpenFont(file string, ptsize int) *Font {
	sdl.GlobalMutex.Lock()

	cfile := C.CString(file)
	cfont := C.TTF_OpenFont(cfile, C.int(ptsize))
	C.free(unsafe.Pointer(cfile))

	sdl.GlobalMutex.Unlock()

	if cfont == nil {
		return nil
	}

	return &Font{cfont: cfont}
}
开发者ID:Zwobot,项目名称:Go-SDL,代码行数:16,代码来源:ttf.go

示例8: OpenFont

// Loads a font from a file at the specified point size.
func OpenFont(file string, ptsize int) (*Font, error) {
	sdl.GlobalMutex.Lock()

	cfile := C.CString(file)
	cfont := C.TTF_OpenFont(cfile, C.int(ptsize))
	C.free(unsafe.Pointer(cfile))

	sdl.GlobalMutex.Unlock()

	if cfont == nil {
		return nil, errors.New("Unable to load font")
	}

	return &Font{cfont: cfont}, nil
}
开发者ID:jonhanks,项目名称:Go-SDL,代码行数:16,代码来源:ttf.go

示例9: LoadFont

func LoadFont(_file string, _size int) (*Font, error) {
	cfile := C.CString(_file)
	defer C.free(unsafe.Pointer(cfile))
	font := C.TTF_OpenFont(cfile, C.int(_size))
	return (*Font)(font), nil
}
开发者ID:henkman,项目名称:Go2D,代码行数:6,代码来源:ttf.go

示例10: main

func main() {
	runtime.GOMAXPROCS(32)

	// sdl
	C.SDL_Init(C.SDL_INIT_AUDIO | C.SDL_INIT_VIDEO | C.SDL_INIT_TIMER)
	defer C.SDL_Quit()
	runtime.LockOSThread()
	window := C.SDL_CreateWindow(C.CString("play"), 0, 0, 1680, 1050,
		C.SDL_WINDOW_BORDERLESS|C.SDL_WINDOW_RESIZABLE|C.SDL_WINDOW_MAXIMIZED|C.SDL_WINDOW_OPENGL)
	if window == nil {
		fatalSDLError()
	}
	defer C.SDL_DestroyWindow(window)
	C.SDL_DisableScreenSaver()
	renderer := C.SDL_CreateRenderer(window, -1, C.SDL_RENDERER_ACCELERATED)
	if renderer == nil {
		fatalSDLError()
	}
	defer C.SDL_DestroyRenderer(renderer)
	var width, height C.int
	C.SDL_GetWindowSize(window, &width, &height)
	texture := C.SDL_CreateTexture(renderer,
		C.SDL_PIXELFORMAT_YV12,
		C.SDL_TEXTUREACCESS_STREAMING,
		width, height)
	if texture == nil {
		fatalSDLError()
	}
	defer C.SDL_DestroyTexture(texture)

	// sdl ttf
	if C.TTF_Init() == C.int(-1) {
		log.Fatal("sdl ttf init failed")
	}
	defer C.TTF_Quit()
	font := C.TTF_OpenFont(C.CString("/home/reus/font.ttf"), 32)
	if font == nil {
		fatalTTFError()
	}
	defer C.TTF_CloseFont(font)

	// open decoder
	decoder, err := NewDecoder(os.Args[1])
	if err != nil {
		log.Fatal(err)
	}
	if len(decoder.AudioStreams) == 0 || len(decoder.VideoStreams) == 0 {
		log.Fatal("no video or audio")
	}
	defer decoder.Close()

	// audio
	aCodecCtx := decoder.AudioStreams[0].codec
	audioStream := setupAudioOutput(int(aCodecCtx.sample_rate), int(aCodecCtx.channels), decoder)

	// call closure in sdl thread
	callEventCode := C.SDL_RegisterEvents(1)
	callbacks := make(chan func(Env), 1024)
	call := func(f func(env Env)) {
		var event C.SDL_Event
		var userevent C.SDL_UserEvent
		userevent._type = C.SDL_USEREVENT
		userevent.code = C.Sint32(callEventCode)
		C.set_userevent(&event, userevent)
		callbacks <- f
		C.SDL_PushEvent(&event)
	}

	// show fps
	nFrames := 0
	var fpsTexture *C.SDL_Texture
	var fpsColor C.SDL_Color
	var fpsSrc, fpsDst C.SDL_Rect
	fpsColor.r = 255
	fpsColor.g = 255
	fpsColor.b = 255
	fpsColor.a = 0
	go func() {
		for _ = range time.NewTicker(time.Second * 1).C {
			call(func(env Env) {
				cText := C.CString(fmt.Sprintf("%d", nFrames))
				sur := C.TTF_RenderUTF8_Blended(font, cText, fpsColor)
				fpsSrc.w = sur.w
				fpsSrc.h = sur.h
				fpsDst.w = sur.w
				fpsDst.h = sur.h
				C.SDL_DestroyTexture(fpsTexture)
				fpsTexture = C.SDL_CreateTextureFromSurface(env.renderer, sur)
				C.SDL_FreeSurface(sur)
				C.free(unsafe.Pointer(cText))
				nFrames = 0
			})
		}
	}()

	// render
	go func() {
		for {
			frame := <-decoder.timedFrames
			nFrames++
//.........这里部分代码省略.........
开发者ID:reusee,项目名称:player,代码行数:101,代码来源:player.go

示例11: String

	"strconv"
)

type fontKey struct {
	path string
	size int
}

func (me *fontKey) String() string {
	return me.path + strconv.Itoa(me.size)
}

var fonts = newFlyweight(
	func(key key) interface{} {
		k := key.(*fontKey)
		font := C.TTF_OpenFont(C.CString(k.path), C.int(k.size))
		return font
	},
	func(path key, val interface{}) {
		C.TTF_CloseFont(val.(*C.TTF_Font))
	})

//A drawable representation of a string.
type Text struct {
	color Color
	text  *C.SDL_Surface
}

func (me *Text) Free() {
	C.SDL_FreeSurface(me.text)
}
开发者ID:griffy,项目名称:starfish,代码行数:31,代码来源:font.go

示例12: TTFOpenFont

// Open a font file and create a font of the specified point size.
// Some .fon fonts will have several sizes embedded in the file, so the
// point size becomes the index of choosing which size.  If the value
// is too high, the last indexed size will be the default.
func TTFOpenFont(file string, ptsize int) *C.TTF_Font {
	cfile := cstr(file)
	defer cfile.free()
	return C.TTF_OpenFont(cfile, C.int(ptsize))
}
开发者ID:beoran,项目名称:fungo,代码行数:9,代码来源:ttf.go

示例13: LoadFont

func LoadFont(path string, size int) *Font {
	font := new(Font)
	font.font = C.TTF_OpenFont(C.CString(path), C.int(size))
	return font
}
开发者ID:gtalent,项目名称:starfish,代码行数:5,代码来源:sdl.go


注:本文中的C.TTF_OpenFont函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。