Beispiel #1
0
func (t *Texture) SetColorMod(r, g, b uint8) error {
	if C.SDL_SetTextureColorMod(t.c, C.Uint8(r), C.Uint8(g), C.Uint8(b)) != 0 {
		return getError()
	}

	return nil
}
Beispiel #2
0
// Renders UTF-8 text in the specified color and returns an SDL surface.  Solid
// rendering is quick, although not as smooth as the other rendering types.
func RenderUTF8_Solid(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_RenderUTF8_Solid(font.cfont, ctext, ccol)
	C.free(unsafe.Pointer(ctext))
	return (*sdl.Surface)(unsafe.Pointer(surface))
}
Beispiel #3
0
func (f *Font) RenderText_Solid(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_Solid(f.f, _text, _c)))
	return surface
}
Beispiel #4
0
func (renderer *Renderer) SetDrawColor(r, g, b, a uint8) int {
	_r := C.Uint8(r)
	_g := C.Uint8(g)
	_b := C.Uint8(b)
	_a := C.Uint8(a)
	return int(C.SDL_SetRenderDrawColor(renderer.cptr(), _r, _g, _b, _a))
}
Beispiel #5
0
func (r *Renderer) SetDrawColor(c Color) {
	GlobalMutex.Lock()
	defer GlobalMutex.Unlock()

	C.SDL_SetRenderDrawColor(r.cRenderer, C.Uint8(c.R),
		C.Uint8(c.G), C.Uint8(c.B), C.Uint8(c.Alpha))
}
Beispiel #6
0
// Renders UTF-8 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 (font *Font) RenderUTF8_Blended(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.A)}
	surface := C.TTF_RenderUTF8_Blended(font.cfont, ctext, ccol)
	C.free(unsafe.Pointer(ctext))
	return wrap(surface)
}
Beispiel #7
0
func (s *Surface) SetColorMod(r, g, b uint8) error {
	if C.SDL_SetSurfaceColorMod(s.c(), C.Uint8(r), C.Uint8(g), C.Uint8(b)) != 0 {
		return getError()
	}

	return nil
}
Beispiel #8
0
func (r *Renderer) SetDrawColor(red, g, b, a uint8) error {
	if C.SDL_SetRenderDrawColor(r.c, C.Uint8(red), C.Uint8(g), C.Uint8(b), C.Uint8(a)) != 0 {
		return getError()
	}

	return nil
}
Beispiel #9
0
func MapRGB(pixelFormat PixelFormat, r, g, b uint8) uint32 {
	c_format := (*C.SDL_PixelFormat)(pixelFormat.Ptr)
	c_r := C.Uint8(r)
	c_g := C.Uint8(g)
	c_b := C.Uint8(b)
	ret := C.SDL_MapRGB(c_format, c_r, c_g, c_b)
	return uint32(ret)
}
Beispiel #10
0
func (p *PixelFormat) MapRGBA(r, g, b, a uint8) uint32 {
	return uint32(C.SDL_MapRGBA(
		p.c(),
		C.Uint8(r),
		C.Uint8(g),
		C.Uint8(b),
		C.Uint8(a),
	))
}
Beispiel #11
0
func FillRect(x, y, w, h int, c Color) {
	var rect C.SDL_Rect
	rect.x = C.int(x)
	rect.y = C.int(y)
	rect.w = C.int(w)
	rect.h = C.int(h)
	C.SDL_SetRenderDrawColor(renderer, C.Uint8(c.Red), C.Uint8(c.Green), C.Uint8(c.Blue), C.Uint8(c.Alpha))
	C.SDL_RenderFillRect(renderer, &rect)
}
Beispiel #12
0
func (f *Font) RenderUTF8Solid(text string, fg sdl.Color) (*sdl.Surface, error) {
	ctext := C.CString(text)
	ccolor := C.SDL_Color{C.Uint8(fg.R), C.Uint8(fg.G), C.Uint8(fg.B), C.Uint8(255)}
	s := C.TTF_RenderUTF8_Solid(f.c, ctext, ccolor)
	if s == nil {
		return nil, getError()
	}
	return (*sdl.Surface)(unsafe.Pointer(s)), nil
}
Beispiel #13
0
// returns (cvt, 0/1/-1) -- 0 means no conversion, 1 means filter is set up
func BuildAudioCVT(src_format AudioFormat, src_channels uint8, src_rate int,
	dst_format AudioFormat, dst_channels uint8, dst_rate int) (*AudioCVT, int) {
	var cvt C.SDL_AudioCVT
	ret := C.SDL_BuildAudioCVT(&cvt,
		C.SDL_AudioFormat(int(src_format)), C.Uint8(src_channels), C.int(src_rate),
		C.SDL_AudioFormat(int(dst_format)), C.Uint8(dst_channels), C.int(dst_rate))
	rcvt := &AudioCVT{&cvt, nil}
	return rcvt, int(ret)
}
Beispiel #14
0
func PixelRGBA(renderer *sdl.Renderer, x, y int, r, g, b, a uint8) bool {
	_x := C.Sint16(x)
	_y := C.Sint16(y)
	_r := C.Uint8(r)
	_g := C.Uint8(g)
	_b := C.Uint8(b)
	_a := C.Uint8(a)
	return C.pixelRGBA(renderer, _x, _y, _r, _g, _b, _a) == 0
}
Beispiel #15
0
// Texture (https://wiki.libsdl.org/SDL_SetTextureColorMod)
func (texture *Texture) SetColorMod(r uint8, g uint8, b uint8) error {
	_r := C.Uint8(r)
	_g := C.Uint8(g)
	_b := C.Uint8(b)
	_ret := C.SDL_SetTextureColorMod(texture.cptr(), _r, _g, _b)
	if _ret < 0 {
		return GetError()
	}
	return nil
}
Beispiel #16
0
func VlineRGBA(renderer *sdl.Renderer, x, y1, y2 int, r, g, b, a uint8) bool {
	_x := C.Sint16(x)
	_y1 := C.Sint16(y1)
	_y2 := C.Sint16(y2)
	_r := C.Uint8(r)
	_g := C.Uint8(g)
	_b := C.Uint8(b)
	_a := C.Uint8(a)
	return C.vlineRGBA(renderer, _x, _y1, _y2, _r, _g, _b, _a) == 0
}
Beispiel #17
0
func (f *Font) RenderUTF8_Blended_Wrapped(text string, fg sdl.Color, wrapLength int) (*sdl.Surface, error) {
	_text := C.CString(text)
	defer C.free(unsafe.Pointer(_text))
	_c := C.SDL_Color{C.Uint8(fg.R), C.Uint8(fg.G), C.Uint8(fg.B), C.Uint8(fg.A)}
	surface := (*sdl.Surface)(unsafe.Pointer(C.TTF_RenderUTF8_Blended_Wrapped(f.f, _text, _c, C.Uint32(wrapLength))))
	if surface == nil {
		return nil, GetError()
	}
	return surface, nil
}
Beispiel #18
0
// RenderUTF8_Blended (https://www.libsdl.org/projects/SDL_ttf/docs/SDL_ttf_52.html#SEC52)
func (f *Font) RenderUTF8_Blended(text string, color sdl.Color) (*sdl.Surface, error) {
	_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_RenderUTF8_Blended(f.f, _text, _c)))
	if surface == nil {
		return nil, GetError()
	}
	return surface, nil
}
Beispiel #19
0
func CharacterRGBA(renderer *sdl.Renderer, x, y int, c, r, g, b, a uint8) bool {
	_x := C.Sint16(x)
	_y := C.Sint16(y)
	_c := C.char(c)
	_r := C.Uint8(r)
	_g := C.Uint8(g)
	_b := C.Uint8(b)
	_a := C.Uint8(a)
	return C.characterRGBA(renderer, _x, _y, _c, _r, _g, _b, _a) == 0
}
Beispiel #20
0
func HlineRGBA(renderer *sdl.Renderer, x1, x2, y int, r, g, b, a uint8) bool {
	_x1 := C.Sint16(x1)
	_x2 := C.Sint16(x2)
	_y := C.Sint16(y)
	_r := C.Uint8(r)
	_g := C.Uint8(g)
	_b := C.Uint8(b)
	_a := C.Uint8(a)
	return C.hlineRGBA(renderer, _x1, _x2, _y, _r, _g, _b, _a) == 0
}
Beispiel #21
0
func StringRGBA(renderer *sdl.Renderer, x, y int, s string, r, g, b, a uint8) bool {
	_x := C.Sint16(x)
	_y := C.Sint16(y)
	_s := C.CString(s)
	_r := C.Uint8(r)
	_g := C.Uint8(g)
	_b := C.Uint8(b)
	_a := C.Uint8(a)
	return C.stringRGBA(renderer, _x, _y, _s, _r, _g, _b, _a) == 0
}
Beispiel #22
0
func FilledPolygonRGBA(renderer *sdl.Renderer, vx, vy []int16, r, g, b, a uint8) bool {
	_vx := (*C.Sint16)(unsafe.Pointer(&vx[0]))
	_vy := (*C.Sint16)(unsafe.Pointer(&vy[0]))
	_len := C.int(min(len(vx), len(vy)))
	_r := C.Uint8(r)
	_g := C.Uint8(g)
	_b := C.Uint8(b)
	_a := C.Uint8(a)
	return C.filledPolygonRGBA(renderer, _vx, _vy, _len, _r, _g, _b, _a) == 0
}
Beispiel #23
0
func FilledCircleRGBA(renderer *sdl.Renderer, x, y, rad int, r, g, b, a uint8) bool {
	_x := C.Sint16(x)
	_y := C.Sint16(y)
	_rad := C.Sint16(rad)
	_r := C.Uint8(r)
	_g := C.Uint8(g)
	_b := C.Uint8(b)
	_a := C.Uint8(a)
	return C.filledCircleRGBA(renderer, _x, _y, _rad, _r, _g, _b, _a) == 0
}
Beispiel #24
0
// SetColor sets the color used for drawing operations (DrawPoints, DrawLines, DrawRects, FillRects, and Clear).
func (c Canvas) SetColor(col color.Color) {
	r, g, b, a := col.RGBA()
	f := 255.0 / 0xFFFF
	r8 := C.Uint8(float64(r) * f)
	g8 := C.Uint8(float64(g) * f)
	b8 := C.Uint8(float64(b) * f)
	a8 := C.Uint8(float64(a) * f)
	if C.SDL_SetRenderDrawColor(c.win.rend, r8, g8, b8, a8) < 0 {
		panic(sdlError())
	}
}
Beispiel #25
0
func (r *Renderer) GetDrawColor() Color {
	cr := C.Uint8(0)
	cg := C.Uint8(0)
	cb := C.Uint8(0)
	ca := C.Uint8(0)
	ret := C.SDL_GetRenderDrawColor(r.cRenderer, &cr, &cg, &cb, &ca)
	if int(ret) == 0 {
		return Color{uint8(cr), uint8(cg), uint8(cb), uint8(ca)}
	}
	return Color{0, 0, 0, 0}
}
Beispiel #26
0
// Renderer (https://wiki.libsdl.org/SDL_SetRenderDrawColor)
func (renderer *Renderer) SetDrawColor(r, g, b, a uint8) error {
	_r := C.Uint8(r)
	_g := C.Uint8(g)
	_b := C.Uint8(b)
	_a := C.Uint8(a)
	_ret := C.SDL_SetRenderDrawColor(renderer.cptr(), _r, _g, _b, _a)
	if _ret < 0 {
		return GetError()
	}
	return nil
}
Beispiel #27
0
func AALineRGBA(renderer *sdl.Renderer, x1, y1, x2, y2 int, r, g, b, a uint8) bool {
	_x1 := C.Sint16(x1)
	_y1 := C.Sint16(y1)
	_x2 := C.Sint16(x2)
	_y2 := C.Sint16(y2)
	_r := C.Uint8(r)
	_g := C.Uint8(g)
	_b := C.Uint8(b)
	_a := C.Uint8(a)
	return C.aalineRGBA(renderer, _x1, _y1, _x2, _y2, _r, _g, _b, _a) == 0
}
Beispiel #28
0
func FilledEllipseRGBA(renderer *sdl.Renderer, x, y, rx, ry int, r, g, b, a uint8) bool {
	_x := C.Sint16(x)
	_y := C.Sint16(y)
	_rx := C.Sint16(rx)
	_ry := C.Sint16(ry)
	_r := C.Uint8(r)
	_g := C.Uint8(g)
	_b := C.Uint8(b)
	_a := C.Uint8(a)
	return C.filledEllipseRGBA(renderer, _x, _y, _rx, _ry, _r, _g, _b, _a) == 0
}
Beispiel #29
0
func FilledPieRGBA(renderer *sdl.Renderer, x, y, rad, start, end int, r, g, b, a uint8) bool {
	_x := C.Sint16(x)
	_y := C.Sint16(y)
	_rad := C.Sint16(rad)
	_start := C.Sint16(start)
	_end := C.Sint16(end)
	_r := C.Uint8(r)
	_g := C.Uint8(g)
	_b := C.Uint8(b)
	_a := C.Uint8(a)
	return C.filledPieRGBA(renderer, _x, _y, _rad, _start, _end, _r, _g, _b, _a) == 0
}
Beispiel #30
0
func ThickLineRGBA(renderer *sdl.Renderer, x1, y1, x2, y2, width int, r, g, b, a uint8) bool {
	_x1 := C.Sint16(x1)
	_y1 := C.Sint16(y1)
	_x2 := C.Sint16(x2)
	_y2 := C.Sint16(y2)
	_width := C.Uint8(width)
	_r := C.Uint8(r)
	_g := C.Uint8(g)
	_b := C.Uint8(b)
	_a := C.Uint8(a)
	return C.thickLineRGBA(renderer, _x1, _y1, _x2, _y2, _width, _r, _g, _b, _a) == 0
}