Example #1
0
File: ttf.go Project: henkman/Go2D
func (f *Font) RenderText_Blended(_text string, color Color) *Surface {
	ccolor := (*C.SDL_Color)(cast(&color))
	ctext := C.CString(_text)
	defer C.free(unsafe.Pointer(ctext))
	sf := C.TTF_RenderText_Blended(f.Get(), ctext, *ccolor)
	return (*Surface)(cast(sf))
}
Example #2
0
func (f *Font) RenderText_Blended(text string, color sdl.Color) *sdl.Surface {
	_text := C.CString(text)
	defer C.free(unsafe.Pointer(_text))
	_c := C.SDL_Color{C.Uint8(color.R), C.Uint8(color.G), C.Uint8(color.B), C.Uint8(color.A)}
	surface := (*sdl.Surface)(unsafe.Pointer(C.TTF_RenderText_Blended(f.f, _text, _c)))
	return surface
}
Example #3
0
// Renders Latin-1 text in the specified color and returns an SDL surface.
// Blended rendering is the slowest of the three methods, although it produces
// the best results, especially when blitted over another image.
func RenderText_Blended(font *Font, text string, color sdl.Color) *sdl.Surface {
	ctext := C.CString(text)
	ccol := C.SDL_Color{C.Uint8(color.R), C.Uint8(color.G), C.Uint8(color.B), C.Uint8(color.Unused)}
	surface := C.TTF_RenderText_Blended(font.cfont, ctext, ccol)
	C.free(unsafe.Pointer(ctext))
	return (*sdl.Surface)(unsafe.Pointer(surface))
}
Example #4
0
func (me *Font) WriteTo(text string, t *Image, c Color) bool {
	sur := C.TTF_RenderText_Blended(me.font, C.CString(text), c.toSDL_Color())

	runMainOp(func() {
		t.surface = C.SDL_CreateTextureFromSurface(renderer, sur)
	})

	var w, h C.int
	C.SDL_QueryTexture(t.surface, nil, nil, &w, &h)
	t.Width = int(w)
	t.Height = int(h)
	return t.surface != nil
}
Example #5
0
File: ttf.go Project: Zwobot/Go-SDL
// Renders Latin-1 text in the specified color and returns an SDL surface.
// Blended rendering is the slowest of the three methods, although it produces
// the best results, especially when blitted over another image.
func RenderText_Blended(font *Font, text string, color sdl.Color) *sdl.Surface {
	sdl.GlobalMutex.Lock() // Because 'C.TTF_Render*' uses 'C.SDL_CreateRGBSurface'
	font.mutex.Lock()      // Use a write lock, because 'C.TTF_Render*' may update font's internal caches

	ctext := C.CString(text)
	ccol := C.SDL_Color{C.Uint8(color.R), C.Uint8(color.G), C.Uint8(color.B), C.Uint8(color.Unused)}
	surface := C.TTF_RenderText_Blended(font.cfont, ctext, ccol)
	C.free(unsafe.Pointer(ctext))

	font.mutex.Unlock()
	sdl.GlobalMutex.Unlock()

	return wrap(surface)
}
Example #6
0
//Loads text into the Text object passed in.
//Returns true if successful, false otherwise.
func (me *Font) Write(text string, t *Text) bool {
	t.color = me.color
	t.text = C.TTF_RenderText_Blended(me.font, C.CString(text), me.color.toSDL_Color())
	return t.text != nil
}