Пример #1
0
func toSDL_Rect(b util.Bounds) C.SDL_Rect {
	var r C.SDL_Rect
	r.x = C.Sint16(b.X)
	r.y = C.Sint16(b.Y)
	r.w = C.Uint16(b.Width)
	r.h = C.Uint16(b.Height)
	return r
}
Пример #2
0
func sdl_Rect(x, y, width, height int) C.SDL_Rect {
	var r C.SDL_Rect
	r.x = C.Sint16(x)
	r.y = C.Sint16(y)
	r.w = C.Uint16(width)
	r.h = C.Uint16(height)
	return r
}
Пример #3
0
func OpenAudio(desired, obtained_orNil *AudioSpec) int {
	if alreadyOpened {
		panic("more than 1 audio stream currently not supported")
	}

	// copy handle to user-defined callback function, if defined
	// it is perfectly supported to not specify the callback function
	// in that case you will use default SendAudio semantics
	// note that if you specify a callback and use SendAudio, a hangup will instead happen
	// when calling SendAudio

	if nil != desired.UserDefinedCallback {
		userDefinedCallback = desired.UserDefinedCallback
	} else {
		// default playback (16-bit signed)
		userDefinedCallback = DownstreamPlaybackS16
		PlayLoop = make(chan AudioEvent)
	}

	var C_desired, C_obtained *C.SDL_AudioSpec

	C_desired = new(C.SDL_AudioSpec)
	C_desired.freq = C.int(desired.Freq)
	C_desired.format = C.Uint16(desired.Format)
	C_desired.channels = C.Uint8(desired.Channels)
	C_desired.samples = C.Uint16(desired.Samples)
	// there is an unique C callback acting as proxy to the different Go callbacks
	// see streamContext()
	C_desired.callback = C.callback_getCallback()

	if obtained_orNil != nil {
		if desired != obtained_orNil {
			C_obtained = new(C.SDL_AudioSpec)
		} else {
			C_obtained = C_desired
		}
	}

	status := C.SDL_OpenAudio(C_desired, C_obtained)

	if status == 0 {
		alreadyOpened = true
	}

	if obtained_orNil != nil {
		obtained := obtained_orNil

		obtained.Freq = int(C_obtained.freq)
		obtained.Format = uint16(C_obtained.format)
		obtained.Channels = uint8(C_obtained.channels)
		obtained.Samples = uint16(C_obtained.samples)
		obtained.Out_Silence = uint8(C_obtained.silence)
		obtained.Out_Size = uint32(C_obtained.size)
	}

	return int(status)
}
Пример #4
0
func convertRect(rect image.Rectangle) C.SDL_Rect {
	rect = rect.Canon()
	return C.SDL_Rect{
		C.Sint16(rect.Min.X),
		C.Sint16(rect.Min.Y),
		C.Uint16(rect.Max.X - rect.Min.X),
		C.Uint16(rect.Max.Y - rect.Min.Y),
	}
}
Пример #5
0
// Open the mixer with a certain audio format 
func OpenMixer(frequency int, format uint16, channels int, chunksize int) (bool) {     
  res := (int(C.Mix_OpenAudio(C.int(frequency), 
             C.Uint16(format), C.int( channels), C.int(chunksize))))
  ok  := (res == 0)
  MixerOpened  = ok 	     
  return ok
}
Пример #6
0
func (d *Display) routine() {
	rect := C.SDL_Rect{x: 0, y: 0, w: C.Uint16(d.width), h: C.Uint16(d.height)}
	for d.rendering {
		frame := <-d.frame
		C.SDL_LockYUVOverlay(d.overlay)
		pixels := (*[1 << 30]*C.Uint8)(unsafe.Pointer(d.overlay.pixels))
		pitches := (*[1 << 30]C.Uint8)(unsafe.Pointer(d.overlay.pitches))
		pixels[0] = (*C.Uint8)(frame.data[0])
		pixels[1] = (*C.Uint8)(frame.data[1])
		pixels[2] = (*C.Uint8)(frame.data[2])
		pitches[0] = (C.Uint8)(frame.linesize[0])
		pitches[1] = (C.Uint8)(frame.linesize[1])
		pitches[2] = (C.Uint8)(frame.linesize[2])
		C.SDL_UnlockYUVOverlay(d.overlay)
		C.SDL_DisplayYUVOverlay(d.overlay, &rect)
	}
}
Пример #7
0
// Returns the metrics (dimensions) of a glyph.
//
// Return values are:
//   minx, maxx, miny, maxy, advance, err
//
// The last return value (err) is 0 for success, -1 for any error (for example
// if the glyph is not available in this font).
//
// For more information on glyph metrics, visit
// http://freetype.sourceforge.net/freetype2/docs/tutorial/step2.html
func (f *Font) GlyphMetrics(ch uint16) (int, int, int, int, int, int) {
	minx := C.int(0)
	maxx := C.int(0)
	miny := C.int(0)
	maxy := C.int(0)
	advance := C.int(0)
	err := C.TTF_GlyphMetrics(f.cfont, C.Uint16(ch), &minx, &maxx, &miny, &maxy, &advance)
	return int(minx), int(maxx), int(miny), int(maxy), int(advance), int(err)
}
Пример #8
0
// Get the metrics (dimensions) of a glyph
// To understand what these metrics mean, here is a useful link:
// http://freetype.sourceforge.net/freetype2/docs/tutorial/step2.html
// retuns minx, maxx, miny, maxy, advance
func TTFGlyphMetrics(font *C.TTF_Font, ch uint16) (int, int, int, int, int) {
	var minx, maxx, miny, maxy, advance int
	pminx := cintptr(&minx)
	pmaxx := cintptr(&maxx)
	pminy := cintptr(&miny)
	pmaxy := cintptr(&maxy)
	padv := cintptr(&advance)
	C.TTF_GlyphMetrics(font, C.Uint16(ch), pminx, pmaxx, pminy, pmaxy, padv)
	return minx, maxx, miny, maxy, advance
}
Пример #9
0
func cAudioInfo(info *AudioInfo) *C.Sound_AudioInfo {
	if info == nil {
		return nil
	}
	cinfo := new(C.Sound_AudioInfo)
	cinfo.format = C.Uint16(info.Format)
	cinfo.channels = C.Uint8(info.Channels)
	cinfo.rate = C.Uint32(info.Rate)
	return cinfo
}
Пример #10
0
// Returns the metrics (dimensions) of a glyph.
//
// Return values are:
//   minx, maxx, miny, maxy, advance, err
//
// For more information on glyph metrics, visit
// http://freetype.sourceforge.net/freetype2/docs/tutorial/step2.html
func (f *Font) GlyphMetrics(ch uint16) (int, int, int, int, int, error) {
	minx := C.int(0)
	maxx := C.int(0)
	miny := C.int(0)
	maxy := C.int(0)
	advance := C.int(0)
	err := C.TTF_GlyphMetrics(f.cfont, C.Uint16(ch), &minx, &maxx, &miny, &maxy, &advance)
	if int(err) != 0 {
		return int(minx), int(maxx), int(miny), int(maxy), int(advance), sdl.NewSDLError()
	}
	return int(minx), int(maxx), int(miny), int(maxy), int(advance), nil
}
Пример #11
0
func OpenAudio(desired, obtained_orNil *AudioSpec) int {
	var C_desired, C_obtained *C.SDL_AudioSpec

	C_desired = new(C.SDL_AudioSpec)
	C_desired.freq = C.int(desired.Freq)
	C_desired.format = C.Uint16(desired.Format)
	C_desired.channels = C.Uint8(desired.Channels)
	C_desired.samples = C.Uint16(desired.Samples)
	C_desired.callback = C.callback_getCallback()

	if obtained_orNil != nil {
		if desired != obtained_orNil {
			C_obtained = new(C.SDL_AudioSpec)
		} else {
			C_obtained = C_desired
		}
	}

	status := C.SDL_OpenAudio(C_desired, C_obtained)

	if status == 0 {
		mutex.Lock()
		opened++
		mutex.Unlock()
	}

	if obtained_orNil != nil {
		obtained := obtained_orNil

		obtained.Freq = int(C_obtained.freq)
		obtained.Format = uint16(C_obtained.format)
		obtained.Channels = uint8(C_obtained.channels)
		obtained.Samples = uint16(C_obtained.samples)
		obtained.Out_Silence = uint8(C_obtained.silence)
		obtained.Out_Size = uint32(C_obtained.size)
	}

	return int(status)
}
Пример #12
0
func (f *Font) GlyphMetrics(ch uint16) (int, int, int, int, int, error) {
	minx := C.int(0)
	maxx := C.int(0)
	miny := C.int(0)
	maxy := C.int(0)
	advance := C.int(0)
	res := C.TTF_GlyphMetrics(f.c, C.Uint16(ch), &minx, &maxx, &miny, &maxy, &advance)
	var err error
	if res != 0 {
		err = getError()
	}
	return int(minx), int(maxx), int(miny), int(maxy), int(advance), err
}
Пример #13
0
// Returns the metrics (dimensions) of a glyph.
//
// Return values are:
//   minx, maxx, miny, maxy, advance, err
//
// The last return value (err) is 0 for success, -1 for any error (for example
// if the glyph is not available in this font).
//
// For more information on glyph metrics, visit
// http://freetype.sourceforge.net/freetype2/docs/tutorial/step2.html
func (f *Font) GlyphMetrics(ch uint16) (int, int, int, int, int, int) {
	sdl.GlobalMutex.Lock() // Because the underlying C code is fairly complex
	f.mutex.Lock()         // Use a write lock, because 'C.TTF_GlyphMetrics' may update font's internal caches

	minx := C.int(0)
	maxx := C.int(0)
	miny := C.int(0)
	maxy := C.int(0)
	advance := C.int(0)
	err := C.TTF_GlyphMetrics(f.cfont, C.Uint16(ch), &minx, &maxx, &miny, &maxy, &advance)

	sdl.GlobalMutex.Unlock()
	f.mutex.Unlock()

	return int(minx), int(maxx), int(miny), int(maxy), int(advance), int(err)
}
Пример #14
0
func OpenAudio(desired, obtained *AudioSpec, callback func(*byte, int)) bool {
	var cdesired C.SDL_AudioSpec
	var cobtained C.SDL_AudioSpec
	cdesired.freq = C.int(desired.Freq)
	cdesired.format = C.SDL_AudioFormat(int(desired.Format))
	cdesired.channels = C.Uint8(desired.Channels)
	cdesired.samples = C.Uint16(desired.Samples)
	cdesired.size = C.Uint32(0)
	cdesired.callback = C.go_sdl2_get_callback()
	cdesired.userdata = unsafe.Pointer(&callback)
	ret := C.SDL_OpenAudio(&cdesired, &cobtained)
	if obtained != nil {
		obtained.Freq = int32(cobtained.freq)
		obtained.Format = AudioFormat(int(cobtained.format))
		obtained.Channels = uint8(cobtained.channels)
		obtained.Silence = uint8(cobtained.silence)
		obtained.Samples = uint16(cobtained.samples)
		obtained.Size = uint32(cobtained.size)
	}
	return int(ret) == 0
}
Пример #15
0
func Init(initSDL, stereo bool, rate, nchannels, nbuffers int) {
	if initSDL {
		GSDLWasInitHere = true
		if C.SDL_Init(C.SDL_INIT_AUDIO) != 0 {
			panic(fmt.Sprintf("Unable to initialize SDL: %v\n", util.GetSdlError()))

		}
	}

	//initFlags := C.MIX_INIT_FLAC | C.MIX_INIT_MP3 | C.MIX_INIT_OGG
	//C.Mix_Init(initFlags)

	audio_format := C.AUDIO_S16SYS
	nstereo := 1
	if stereo {
		nstereo = 2
	}
	if C.Mix_OpenAudio(C.int(rate), C.Uint16(audio_format),
		C.int(nstereo), C.int(nbuffers)) != 0 {
		panic(fmt.Sprintf("Unable to initialize audio: %v\n", util.GetMixError()))
	}
	channel.Allocate(nchannels)
}
Пример #16
0
func OpenAudioDevice(device string, iscapture bool, desired, obtained *AudioSpec, allowed_changes bool, callback func(*byte, int)) bool {
	var cdesired C.SDL_AudioSpec
	var cobtained C.SDL_AudioSpec
	cdevice := C.CString(device)
	defer C.free(unsafe.Pointer(cdevice))
	cdesired.freq = C.int(desired.Freq)
	cdesired.format = C.SDL_AudioFormat(int(desired.Format))
	cdesired.channels = C.Uint8(desired.Channels)
	cdesired.samples = C.Uint16(desired.Samples)
	cdesired.size = C.Uint32(0)
	cdesired.callback = C.go_sdl2_get_callback()
	cdesired.userdata = unsafe.Pointer(&callback)
	ret := C.SDL_OpenAudioDevice(cdevice, C.int(bool2int(iscapture)), &cdesired, &cobtained, C.int(bool2int(allowed_changes)))
	if obtained != nil {
		obtained.Freq = int32(cobtained.freq)
		obtained.Format = AudioFormat(int(cobtained.format))
		obtained.Channels = uint8(cobtained.channels)
		obtained.Silence = uint8(cobtained.silence)
		obtained.Samples = uint16(cobtained.samples)
		obtained.Size = uint32(cobtained.size)
	}
	return int(ret) == 0
}
Пример #17
0
func (f *Font) GetMetrics(_ch uint16) (int, int, int, int, int) {
	var minx, maxx, miny, maxy, advance C.int
	C.TTF_GlyphMetrics(f.Get(), C.Uint16(_ch), (*C.int)(cast(&minx)), (*C.int)(cast(&maxx)), (*C.int)(cast(&miny)), (*C.int)(cast(&maxy)), (*C.int)(cast(&advance)))
	return int(minx), int(maxx), int(miny), int(maxy), int(advance)
}
Пример #18
0
// Initializes SDL_mixer.  Return 0 if successful and -1 if there were
// initialization errors.
func OpenAudio(frequency int, format uint16, channels, chunksize int) int {
	return int(C.Mix_OpenAudio(C.int(frequency), C.Uint16(format),
		C.int(channels), C.int(chunksize)))
}
Пример #19
0
// Warp mousej
func WarpMouse(x, y int) {
	C.SDL_WarpMouse(C.Uint16(x), C.Uint16(y))
}
Пример #20
0
// Create a 32-bit ARGB surface and render the given glyph at high quality,
// using alpha blending to dither the font with the given color.
// The glyph is rendered without any padding or centering in the X
// direction, and aligned normally in the Y direction.
// This function returns the new surface, or NULL if there was an error.
func TTFRenderGlyphBlended(font *C.TTF_Font, ch uint16,
	color C.SDL_Color) *C.SDL_Surface {
	return C.TTF_RenderGlyph_Blended(font, C.Uint16(ch), color)
}
Пример #21
0
// Create an 8-bit palettized surface and render the given glyph at
// high quality with the given font and colors.  The 0 pixel is background,
// while other pixels have varying degrees of the foreground color.
// The glyph is rendered without any padding or centering in the X
// direction, and aligned normally in the Y direction.
// This function returns the new surface, or NULL if there was an error.
func TTFRenderGlyphShaded(font *C.TTF_Font, ch uint16,
	fg, bg C.SDL_Color) *C.SDL_Surface {
	return C.TTF_RenderGlyph_Shaded(font, C.Uint16(ch), fg, bg)
}
Пример #22
0
// This function performs a fast fill of the given rectangle
// with the given coordinates and width and height with 'color'
func (dst *Surface) FillRectCoord(x, y, w, h int, color uint32) int {
	sdlrect := C.SDL_Rect{C.Sint16(x), C.Sint16(y), C.Uint16(w), C.Uint16(h)}
	return fillRect(dst.surface, &sdlrect, color)
}
Пример #23
0
func (f *Font) GlyphIsProvided(ch uint16) int {
	return int(C.TTF_GlyphIsProvided(f.c, C.Uint16(ch)))
}
Пример #24
0
func (dst *RWops) WriteBE16(value uint16) uint {
	if dst == nil {
		return 0
	}
	return uint(C.SDL_WriteBE16(dst.cptr(), C.Uint16(value)))
}