Exemple #1
0
// Texture (https://wiki.libsdl.org/SDL_UpdateTexture)
func (texture *Texture) Update(rect *Rect, pixels unsafe.Pointer, pitch int) error {
	_pitch := C.int(pitch)
	_ret := C.SDL_UpdateTexture(texture.cptr(), rect.cptr(), pixels, _pitch)
	if _ret < 0 {
		return GetError()
	}
	return nil
}
Exemple #2
0
func texFromImage(rend *C.SDL_Renderer, img *image.NRGBA) *C.SDL_Texture {
	b := img.Bounds()
	w, h := b.Dx(), b.Dy()
	fmt := C.SDL_PIXELFORMAT_ABGR8888
	acc := C.SDL_TEXTUREACCESS_STATIC
	tex := C.SDL_CreateTexture(rend, C.Uint32(fmt), C.int(acc), C.int(w), C.int(h))
	if tex == nil {
		panic(sdlError())
	}
	if C.SDL_UpdateTexture(tex, nil, unsafe.Pointer(&img.Pix[0]), C.int(img.Stride)) < 0 {
		panic(sdlError())
	}
	if C.SDL_SetTextureBlendMode(tex, C.SDL_BLENDMODE_BLEND) < 0 {
		panic(sdlError())
	}
	return tex
}
Exemple #3
0
func (t *Texture) Update64(r *Rect, pix []uint64, pitch int) error {
	if r == nil {
		_, _, w, h, err := t.Query()
		if err != nil {
			return err
		}

		r = &Rect{
			W: int32(w),
			H: int32(h),
		}
	}

	if len(pix) < int(r.W)*int(r.H) {
		return errors.New("len(pix) < r.W * r.H")
	}

	if C.SDL_UpdateTexture(t.c, r.c(), unsafe.Pointer(&pix[0]), C.int(pitch)) != 0 {
		return getError()
	}

	return nil
}
Exemple #4
0
func (t *Texture) Update(rect *Rect, pixels interface{}, pitch int) {
	C.SDL_UpdateTexture(t.cTexture, (*C.SDL_Rect)(cast(rect)), ptr(pixels), C.int(pitch))
}
Exemple #5
0
func (texture *Texture) Update(rect *Rect, pixels unsafe.Pointer, pitch int) int {
	_texture := (*C.SDL_Texture)(unsafe.Pointer(texture))
	_rect := (*C.SDL_Rect)(unsafe.Pointer(rect))
	_pitch := (C.int)(pitch)
	return (int)(C.SDL_UpdateTexture(_texture, _rect, pixels, _pitch))
}
Exemple #6
0
func (texture *Texture) Update(rect *Rect, pixels unsafe.Pointer, pitch int) int {
	_pitch := C.int(pitch)
	return int(C.SDL_UpdateTexture(texture.cptr(), rect.cptr(), pixels, _pitch))
}
Exemple #7
0
func (t *Texture) Update(rect *Rect, pixels interface{}, pitch int) {
	GlobalMutex.Lock()
	defer GlobalMutex.Unlock()

	C.SDL_UpdateTexture(t.cTexture, (*C.SDL_Rect)(cast(rect)), ptr(pixels), C.int(pitch))
}