Golang C.TTF_CloseFont类(方法)实例源码

下面列出了Golang C.TTF_CloseFont 类(方法)源码代码实例,从而了解它的用法。

作者:Zwobo    项目:Go-SD   
// Frees the pointer to the font.
func (f *Font) Close() {
	sdl.GlobalMutex.Lock()
	f.mutex.Lock()

	C.TTF_CloseFont(f.cfont)

	f.mutex.Unlock()
	sdl.GlobalMutex.Unlock()
}

作者:veandc    项目:go-sdl   
// Close (https://www.libsdl.org/projects/SDL_ttf/docs/SDL_ttf_18.html#SEC18)
func (f *Font) Close() {
	C.TTF_CloseFont(f.f)
	f.f = nil
}

作者:henkma    项目:Go2   
func (f *Font) Release() {
	C.TTF_CloseFont(f.Get())
}

作者:reuse    项目:playe   
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++
//.........这里部分代码省略.........

作者:griff    项目:starfis   
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)
}

//Returns a Color object representing the color of the text.
func (me *Text) Color() Color {
	return me.color

作者:badgerodo    项目:g   
func (this Font) Close() {
	c_font := (*C.TTF_Font)(this.Ptr)
	C.TTF_CloseFont(c_font)
}

作者:beora    项目:fung   
// Close an opened font file
func TTFCloseFont(font *C.TTF_Font) {
	C.TTF_CloseFont(font)
}

作者:jgasta    项目:Go-SD   
// Frees the pointer to the font.
func (f *Font) Close() { C.TTF_CloseFont(f.cfont) }

作者:gtalen    项目:starfis   
func FreeFont(val *Font) {
	C.TTF_CloseFont(val.font)
}


问题


面经


文章

微信
公众号

扫码关注公众号