Example #1
0
func (s *Surface) SaveBMP(_file string) {
	cfile := C.CString(_file)
	defer C.free(unsafe.Pointer(cfile))
	cparams := C.CString("wb")
	defer C.free(unsafe.Pointer(cparams))
	C.SDL_SaveBMP_RW(s.Get(), C.SDL_RWFromFile(cfile, cparams), C.int(1))
}
Example #2
0
func LoadBMP(_file string) *Surface {
	cfile := C.CString(_file)
	defer C.free(unsafe.Pointer(cfile))
	cparams := C.CString("rb")
	defer C.free(unsafe.Pointer(cparams))
	return (*Surface)(C.SDL_LoadBMP_RW(C.SDL_RWFromFile(cfile, cparams), C.int(1)))
}
Example #3
0
func LoadWAV(file string) *Chunk {
	_file := C.CString(file)
	defer C.free(unsafe.Pointer(_file))
	_rb := C.CString("rb")
	defer C.free(unsafe.Pointer(_rb))
	return (*Chunk)(unsafe.Pointer(C.Mix_LoadWAV_RW(C.SDL_RWFromFile(_file, _rb), 1)))
}
Example #4
0
func RWFromFile(file, mode string) *RWops {
	_file := C.CString(file)
	defer C.free(unsafe.Pointer(_file))
	_mode := C.CString(mode)
	defer C.free(unsafe.Pointer(_mode))
	return (*RWops)(unsafe.Pointer(C.SDL_RWFromFile(_file, _mode)))
}
Example #5
0
File: sdl.go Project: beoran/fungo
// Functions to create SDL_RWops structures from various data sources
// Creates an RWOPS from a file
func RWFromFile(file, mode string) *C.SDL_RWops {
	cfile := cstr(file)
	defer cfile.free()
	cmode := cstr(mode)
	defer cmode.free()
	rw := C.SDL_RWFromFile(cfile, cmode)
	return rw
}
Example #6
0
func LoadWAV(file string, spec *AudioSpec, audio_buf **uint8, audio_len *uint32) *AudioSpec {
	_file := (C.CString)(file)
	_spec := (*C.SDL_AudioSpec)(unsafe.Pointer(spec))
	_audio_buf := (**C.Uint8)(unsafe.Pointer(audio_buf))
	_audio_len := (*C.Uint32)(unsafe.Pointer(audio_len))
	return (*AudioSpec)(unsafe.Pointer(C.SDL_LoadWAV_RW(C.SDL_RWFromFile(_file, C.CString("rb")),
		1, _spec, _audio_buf, _audio_len)))
}
Example #7
0
// LoadWAV (https://wiki.libsdl.org/SDL_LoadWAV)
func LoadWAV(file string, spec *AudioSpec, audioBuf **uint8, audioLen *uint32) *AudioSpec {
	_file := C.CString(file)
	_rb := C.CString("rb")
	defer C.free(unsafe.Pointer(_file))
	defer C.free(unsafe.Pointer(_rb))
	_audioBuf := (**C.Uint8)(unsafe.Pointer(audioBuf))
	_audioLen := (*C.Uint32)(unsafe.Pointer(audioLen))
	return (*AudioSpec)(unsafe.Pointer(C.SDL_LoadWAV_RW(C.SDL_RWFromFile(_file, _rb), 1, spec.cptr(), _audioBuf, _audioLen)))
}
Example #8
0
func loadSound(name string) *C.Mix_Chunk {
	cfile, rb := C.CString(name), C.CString("rb")
	rwop := C.SDL_RWFromFile(cfile, rb)
	C.free(unsafe.Pointer(cfile))
	C.free(unsafe.Pointer(rb))
	chunk := C.Mix_LoadWAV_RW(rwop, 1)
	if chunk == nil {
		panic(fmt.Sprintf("Unable to load Sound file (%v): %v", name, util.GetMixError()))
	}
	return chunk
}
Example #9
0
func LoadWAV(file string) *Chunk {
	cfile := C.CString(file)
	cchunk := C.Mix_LoadWAV_RW(C.SDL_RWFromFile(cfile, C.CString("rb")), 1)
	C.free(unsafe.Pointer(cfile))

	if cchunk == nil {
		return nil
	}

	return &Chunk{cchunk}
}
Example #10
0
func LoadWAV(file string) (chunk *Chunk, err error) {
	_file := C.CString(file)
	defer C.free(unsafe.Pointer(_file))
	_rb := C.CString("rb")
	defer C.free(unsafe.Pointer(_rb))
	// why doesn't this call Mix_LoadWAV ?
	chunk = (*Chunk)(unsafe.Pointer(C.Mix_LoadWAV_RW(C.SDL_RWFromFile(_file, _rb), 1)))
	if chunk == nil {
		err = sdl.GetError()
	}
	return
}
Example #11
0
func RWFromFile(file string, mode int) *RWops {
	cfile := C.CString(file)
	defer C.free(unsafe.Pointer(cfile))

	cmode := modeFromFlags(mode)
	if cmode == nil {
		return nil
	}
	defer C.free(unsafe.Pointer(cmode))

	return (*RWops)(C.SDL_RWFromFile(cfile, cmode))
}
Example #12
0
func RWFromFile(file string, mode string) (*RWops, error) {
	cfile := C.CString(file)
	defer C.free(unsafe.Pointer(cfile))

	cmode := C.CString(mode)
	defer C.free(unsafe.Pointer(cmode))

	rw := C.SDL_RWFromFile(cfile, cmode)
	if rw == nil {
		return nil, getError()
	}

	return &RWops{rw}, nil
}
Example #13
0
// LoadWAV (https://wiki.libsdl.org/SDL_LoadWAV)
func LoadWAV(file string, spec *AudioSpec) ([]byte, *AudioSpec) {
	_file := C.CString(file)
	_rb := C.CString("rb")
	defer C.free(unsafe.Pointer(_file))
	defer C.free(unsafe.Pointer(_rb))

	var _audioBuf *C.Uint8
	var _audioLen C.Uint32
	audioSpec := (*AudioSpec)(unsafe.Pointer(C.SDL_LoadWAV_RW(C.SDL_RWFromFile(_file, _rb), 1, spec.cptr(), &_audioBuf, &_audioLen)))

	var b []byte
	sliceHeader := (*reflect.SliceHeader)(unsafe.Pointer(&b))
	sliceHeader.Len = (int)(_audioLen)
	sliceHeader.Cap = (int)(_audioLen)
	sliceHeader.Data = uintptr(unsafe.Pointer(_audioBuf))
	return b, audioSpec
}
Example #14
0
File: audio.go Project: velour/ui
func loadWAV(path string) (*audioData, error) {
	cpath := C.CString(path)
	defer C.free(unsafe.Pointer(cpath))

	var data *C.Uint8
	var len C.Uint32
	var s C.SDL_AudioSpec // Apparently just a buffer?  SDL just zeroes it, fills it, and returns it.
	spec := C.SDL_LoadWAV_RW(C.SDL_RWFromFile(cpath, rb), 1, &s, &data, &len)
	if spec == nil {
		return nil, sdlError()
	}

	var err error
	data, len, err = convert(spec, data, len)
	if err != nil {
		return nil, err
	}

	return &audioData{
		path: path,
		data: unsafe.Pointer(data),
		len:  uintptr(len),
	}, nil
}
Example #15
0
func LoadWAV(file string) *Chunk {
	_file := (C.CString)(file)
	return (*Chunk)(unsafe.Pointer(C.Mix_LoadWAV_RW(C.SDL_RWFromFile(_file,
		C.CString("rb")), 1)))
}
Example #16
0
func RWFromFile(file, mode string) *RWops {
	_file := (C.CString)(file)
	_mode := (C.CString)(mode)
	return (*RWops)(unsafe.Pointer(C.SDL_RWFromFile(_file, _mode)))
}
Example #17
0
func RWFromFile(file string, mode string) *RWops {
	cfile, cmode := C.CString(file), C.CString(mode)
	defer C.free(unsafe.Pointer(cfile))
	defer C.free(unsafe.Pointer(cmode))
	return wrapRWops(C.SDL_RWFromFile(cfile, cmode))
}