// Renders UTF-8 text in the specified color (and with the specified background // color) and returns an SDL surface. Shaded rendering is slower than solid // rendering and the text is in a solid box, but it's better looking. func RenderUTF8_Shaded(font *Font, text string, color, bgcolor 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)} cbgcol := C.SDL_Color{C.Uint8(bgcolor.R), C.Uint8(bgcolor.G), C.Uint8(bgcolor.B), C.Uint8(bgcolor.Unused)} surface := C.TTF_RenderUTF8_Shaded(font.cfont, ctext, ccol, cbgcol) C.free(unsafe.Pointer(ctext)) return (*sdl.Surface)(unsafe.Pointer(surface)) }
// RenderUTF8_Shaded (https://www.libsdl.org/projects/SDL_ttf/docs/SDL_ttf_48.html#SEC48) func (f *Font) RenderUTF8_Shaded(text string, fg, bg sdl.Color) (*sdl.Surface, error) { _text := C.CString(text) defer C.free(unsafe.Pointer(_text)) _fg := C.SDL_Color{C.Uint8(fg.R), C.Uint8(fg.G), C.Uint8(fg.B), C.Uint8(fg.A)} _bg := C.SDL_Color{C.Uint8(bg.R), C.Uint8(bg.G), C.Uint8(bg.B), C.Uint8(bg.A)} surface := (*sdl.Surface)(unsafe.Pointer(C.TTF_RenderUTF8_Shaded(f.f, _text, _fg, _bg))) if surface == nil { return nil, GetError() } return surface, nil }
func (this Font) RenderTextShaded(text string, fg, bg sdl.Color) (sdl.Surface, error) { c_font := (*C.TTF_Font)(this.Ptr) c_text := C.CString(text) defer C.free(unsafe.Pointer(c_text)) c_fg := *(*C.SDL_Color)(unsafe.Pointer(&fg)) c_bg := *(*C.SDL_Color)(unsafe.Pointer(&bg)) ret := C.TTF_RenderUTF8_Shaded(c_font, c_text, c_fg, c_bg) if ret == nil { return sdl.Surface{}, sdl.GetError() } return sdl.Surface{unsafe.Pointer(ret)}, nil }
// Renders UTF-8 text in the specified color (and with the specified background // color) and returns an SDL surface. Shaded rendering is slower than solid // rendering and the text is in a solid box, but it's better looking. func RenderUTF8_Shaded(font *Font, text string, color, bgcolor 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)} cbgcol := C.SDL_Color{C.Uint8(bgcolor.R), C.Uint8(bgcolor.G), C.Uint8(bgcolor.B), C.Uint8(bgcolor.Unused)} surface := C.TTF_RenderUTF8_Shaded(font.cfont, ctext, ccol, cbgcol) C.free(unsafe.Pointer(ctext)) font.mutex.Unlock() sdl.GlobalMutex.Unlock() return wrap(surface) }
// Create an 8-bit palettized surface and render the given text at // high quality with the given font and colors. The 0 pixel is background, // while other pixels have varying degrees of the foreground color. // This function returns the new surface, or NULL if there was an error. func TTFRenderShaded(font *C.TTF_Font, text string, fg, bg C.SDL_Color) *C.SDL_Surface { ctext := cstr(text) defer ctext.free() return C.TTF_RenderUTF8_Shaded(font, ctext, fg, bg) }