示例#1
0
func NewPaletteSurface(w, h int) (s *Surface) {
	mutex.Lock()
	defer mutex.Unlock()

	ptr := C.SDL_CreateRGBSurface(0, C.int(w), C.int(h), 8, 0, 0, 0, 0)
	s = &Surface{ptr}
	runtime.SetFinalizer(s, func(s *Surface) { C.SDL_FreeSurface(s.ptr) })
	return
}
示例#2
0
文件: sdl.go 项目: kearsley/Go-SDL
// Creates an empty Surface.
func CreateRGBSurface(flags uint32, width int, height int, bpp int, Rmask uint32, Gmask uint32, Bmask uint32, Amask uint32) *Surface {
	GlobalMutex.Lock()

	p := C.SDL_CreateRGBSurface(C.Uint32(flags), C.int(width), C.int(height), C.int(bpp),
		C.Uint32(Rmask), C.Uint32(Gmask), C.Uint32(Bmask), C.Uint32(Amask))

	GlobalMutex.Unlock()

	return wrap(p)
}
示例#3
0
func CreateRGBSurface(flags uint32, width, height, depth int32, Rmask, Gmask, Bmask, Amask uint32) *Surface {
	return (*Surface)(unsafe.Pointer(C.SDL_CreateRGBSurface(C.Uint32(flags),
		C.int(width),
		C.int(height),
		C.int(depth),
		C.Uint32(Rmask),
		C.Uint32(Gmask),
		C.Uint32(Bmask),
		C.Uint32(Amask))))
}
示例#4
0
func CreateRGBSurface(flags uint32, width, height, depth int32,
	Rmask, Gmask, Bmask, Amask uint32) *Surface {
	_flags := (C.Uint32)(flags)
	_width := (C.int)(width)
	_height := (C.int)(height)
	_depth := (C.int)(depth)
	_Rmask := (C.Uint32)(Rmask)
	_Gmask := (C.Uint32)(Gmask)
	_Bmask := (C.Uint32)(Bmask)
	_Amask := (C.Uint32)(Amask)
	return (*Surface)(unsafe.Pointer(C.SDL_CreateRGBSurface(_flags, _width, _height,
		_depth, _Rmask, _Gmask, _Bmask, _Amask)))
}
示例#5
0
func NewSurface(w, h int) (s *Surface) {
	mutex.Lock()
	defer mutex.Unlock()

	video := C.SDL_GetVideoSurface()
	ptr := C.SDL_CreateRGBSurface(
		0, C.int(w), C.int(h), C.int(video.format.BitsPerPixel),
		video.format.Rmask,
		video.format.Gmask,
		video.format.Bmask,
		video.format.Amask)
	s = &Surface{ptr}
	runtime.SetFinalizer(s, func(s *Surface) { C.SDL_FreeSurface(s.ptr) })
	return
}
示例#6
0
文件: surface.go 项目: emlai/go-sdl2
// CreateRGBSurface (https://wiki.libsdl.org/SDL_CreateRGBSurface)
func CreateRGBSurface(flags uint32, width, height, depth int32, Rmask, Gmask, Bmask, Amask uint32) (*Surface, error) {
	surface := (*Surface)(unsafe.Pointer(C.SDL_CreateRGBSurface(
		C.Uint32(flags),
		C.int(width),
		C.int(height),
		C.int(depth),
		C.Uint32(Rmask),
		C.Uint32(Gmask),
		C.Uint32(Bmask),
		C.Uint32(Amask))))
	if surface == nil {
		return nil, GetError()
	}
	return surface, nil
}
示例#7
0
文件: surface.go 项目: willemvds/sdl
func CreateRGBSurface(w, h, d int, rm, gm, bm, am uint32) (*Surface, error) {
	s := C.SDL_CreateRGBSurface(0,
		C.int(w),
		C.int(h),
		C.int(d),
		C.Uint32(rm),
		C.Uint32(gm),
		C.Uint32(bm),
		C.Uint32(am),
	)
	if s == nil {
		return nil, getError()
	}

	return (*Surface)(unsafe.Pointer(s)), nil
}
示例#8
0
文件: sdl.go 项目: 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
}
示例#9
0
文件: surface.go 项目: salihdb/sdl
// CreateSurface returns a newly allocated surface.
//
// Note: Free must be called when finished using the surface.
func CreateSurface(w, h int) (surface *Surface, err error) {
	surface = new(Surface)
	// SDL_PIXELFORMAT_RGBA8888
	rMask := C.Uint32(0xFF000000)
	gMask := C.Uint32(0x00FF0000)
	bMask := C.Uint32(0x0000FF00)
	aMask := C.Uint32(0x000000FF)
	if nativeEndian == binary.BigEndian {
		// SDL_PIXELFORMAT_ABGR8888
		rMask = 0x000000FF
		gMask = 0x0000FF00
		bMask = 0x00FF0000
		aMask = 0xFF000000
	}
	surface.cSurface = C.SDL_CreateRGBSurface(0, C.int(w), C.int(h), 32, rMask, gMask, bMask, aMask)
	if surface.cSurface == nil {
		return nil, getError()
	}
	return surface, nil
}
示例#10
0
文件: sdl.go 项目: gnanderson/Go-SDL
// Creates an empty Surface.
func CreateRGBSurface(flags uint32, width int, height int, bpp int, Rmask uint32, Gmask uint32, Bmask uint32, Amask uint32) *Surface {
	p := C.SDL_CreateRGBSurface(C.Uint32(flags), C.int(width), C.int(height), C.int(bpp),
		C.Uint32(Rmask), C.Uint32(Gmask), C.Uint32(Bmask), C.Uint32(Amask))
	return (*Surface)(cast(p))
}
示例#11
0
文件: video.go 项目: beoran/fungo
// Allocate and free an RGB surface (must be called after SDL_SetVideoMode)
// If the depth is 4 or 8 bits, an empty palette is allocated for the surface.
// If the depth is greater than 8 bits, the pixel format is set using the
// flags '[RGB]mask'.
// If the function runs out of memory, it will return NULL.
//
// The 'flags' tell what kind of surface to create.
// SDL_SWSURFACE means that the surface should be created in system memory.
// SDL_HWSURFACE means that the surface should be created in video memory,
// with the same format as the display surface.  This is useful for surfaces
// that will not change much, to take advantage of hardware acceleration
// when being blitted to the display surface.
// SDL_ASYNCBLIT means that SDL will try to perform asynchronous blits with
// this surface, but you must always lock it before accessing the pixels.
// SDL will wait for current blits to finish before returning from the lock.
// SDL_SRCCOLORKEY indicates that the surface will be used for colorkey blits.
// If the hardware supports acceleration of colorkey blits between
// two surfaces in video memory, SDL will try to place the surface in
// video memory. If this isn't possible or if there is no hardware
// acceleration available, the surface will be placed in system memory.
// SDL_SRCALPHA means that the surface will be used for alpha blits and
// if the hardware supports hardware acceleration of alpha blits between
// two surfaces in video memory, to place the surface in video memory
// if possible, otherwise it will be placed in system memory.
// If the surface is created in video memory, blits will be _much_ faster,
// but the surface format must be identical to the video surface format,
// and the only way to access the pixels member of the surface is to use
// the SDL_LockSurface() and SDL_UnlockSurface() calls.
// If the requested surface actually resides in video memory, SDL_HWSURFACE
// will be set in the flags member of the returned surface.  If for some
// reason the surface could not be placed in video memory, it will not have
// the SDL_HWSURFACE flag set, and will be created in system memory instead.
func createRGBSurface(flags uint32, width, height, depth int,
	rmask, gmask, bmask, amask uint32) *C.SDL_Surface {
	return C.SDL_CreateRGBSurface(C.Uint32(flags), C.int(width), C.int(height),
		C.int(depth), C.Uint32(rmask), C.Uint32(gmask),
		C.Uint32(bmask), C.Uint32(amask))
}