Example #1
0
// AllocFormat creates a PixelFormat structure from a uint.
// AllocFormat (https://wiki.libsdl.org/SDL_AllocFormat)
func AllocFormat(format uint) (*PixelFormat, error) {
	r := (*PixelFormat)(unsafe.Pointer(C.SDL_AllocFormat(C.Uint32(format))))
	if r == nil {
		return nil, GetError()
	}
	return r, nil
}
Example #2
0
func AllocFormat(f uint32) (*PixelFormat, error) {
	p := C.SDL_AllocFormat(C.Uint32(f))
	if p == nil {
		return nil, getError()
	}

	return (*PixelFormat)(unsafe.Pointer(p)), nil
}
Example #3
0
File: sdl.go Project: rwcarlsen/sdl
func NewSurface(w, h int) (*Surface, error) {
	var curr C.SDL_DisplayMode
	if C.SDL_GetCurrentDisplayMode(0, &curr) != 0 {
		return nil, sdlerr()
	}
	pixfmt := C.SDL_AllocFormat(curr.format)

	s := C.SDL_CreateRGBSurface(0, C.int(w), C.int(h),
		C.int(pixfmt.BitsPerPixel),
		pixfmt.Rmask, pixfmt.Gmask,
		pixfmt.Bmask, pixfmt.Amask)
	if s == nil {
		return nil, sdlerr()
	}

	surf := &Surface{s, pixfmt}
	runtime.SetFinalizer(surf, freesurf)
	return surf, nil
}