示例#1
0
文件: sdl.go 项目: gtalent/starfish
func LoadImage(path string) *Image {
	var retval *Image
	var texture *C.SDL_Texture

	i := C.IMG_Load(C.CString(path))
	if i == nil {
		errlog.Println("Surface for", path, "loaded nil")
		return nil
	}

	if renderer == nil {
		errlog.Println("Cannot load image because renderer is nil")
		return nil
	}

	runMainOp(func() {
		texture = C.SDL_CreateTextureFromSurface(renderer, i)
	})

	if texture == nil {
		errlog.Println("Texture for", path, "loaded nil")
		return nil
	}
	retval = new(Image)
	retval.surface = texture
	C.SDL_FreeSurface(i)
	return retval
}
示例#2
0
func LoadPNG(path, name string) error {
	// Make sure this name isn't already in use
	if _, ok := Textures[name]; ok {
		return errors.New("Texture name already in use")
	}

	// Convert the path to a c-string
	cpath := C.CString(path)
	defer C.free(unsafe.Pointer(cpath))

	// Load the surface
	surface := C.IMG_Load(cpath)
	if surface == nil {
		return errors.New("SDL_LoadBMP")
	}
	defer C.SDL_FreeSurface(surface)

	// Create the texture
	tex := C.SDL_CreateTextureFromSurface(renderer, surface)
	if tex == nil {
		return errors.New("SDL_CreateTextureFromSurface")
	}

	Textures[name] = Texture{tex: tex}

	return nil
}
示例#3
0
func Load(file string) (*sdl.Surface, error) {
	_file := C.CString(file)
	defer C.free(unsafe.Pointer(_file))
	_surface := C.IMG_Load(_file)
	if _surface == nil {
		return nil, GetError()
	}
	return (*sdl.Surface)(unsafe.Pointer(_surface)), nil
}
示例#4
0
func LoadImage(_file string) *Surface {
	cfile := C.CString(_file)
	defer C.free(unsafe.Pointer(cfile))
	img := C.IMG_Load(cfile)
	if img == nil {
		fmt.Printf("Image load error: %v", C.GoString(C.IMG_GetError()))
	}
	return (*Surface)(cast(img))
}
示例#5
0
文件: image.go 项目: badgerodon/go
func Load(file string) (sdl.Surface, error) {
	c_file := C.CString(file)
	defer C.free(unsafe.Pointer(c_file))
	ret := C.IMG_Load(c_file)
	if ret == nil {
		return sdl.Surface{}, sdl.GetError()
	}
	return sdl.Surface{unsafe.Pointer(ret)}, nil
}
示例#6
0
文件: image.go 项目: genbattle/Go2D
func LoadImage(_file string) (*Surface, error) {
	cfile := C.CString(_file)
	defer C.free(unsafe.Pointer(cfile))
	img := C.IMG_Load(cfile)
	if img == nil {
		return nil, errors.New("Image load error: " + C.GoString(C.IMG_GetError()))
	}
	return (*Surface)(cast(img)), nil
}
示例#7
0
文件: image.go 项目: DeedleFake/sdl
func Load(name string) (*sdl.Surface, error) {
	cname := C.CString(name)
	defer C.free(unsafe.Pointer(cname))

	s := C.IMG_Load(cname)
	if s == nil {
		return nil, getError()
	}
	return (*sdl.Surface)(unsafe.Pointer(s)), nil
}
示例#8
0
文件: sdl.go 项目: kearsley/Go-SDL
// Loads Surface from file (using IMG_Load).
func Load(file string) *Surface {
	GlobalMutex.Lock()

	cfile := C.CString(file)
	var screen = C.IMG_Load(cfile)
	C.free(unsafe.Pointer(cfile))

	GlobalMutex.Unlock()

	return wrap(screen)
}
示例#9
0
func Load(file string) *sdl.Surface {
	_file := C.CString(file)
	defer C.free(unsafe.Pointer(_file))
	return (*sdl.Surface)(unsafe.Pointer(C.IMG_Load(_file)))
}
示例#10
0
文件: sdl.go 项目: gnanderson/Go-SDL
// Loads Surface from file (using IMG_Load).
func Load(file string) *Surface {
	cfile := C.CString(file)
	var screen = C.IMG_Load(cfile)
	C.free(unsafe.Pointer(cfile))
	return (*Surface)(cast(screen))
}
示例#11
0
文件: sdl.go 项目: beoran/fungo
// Bindings to SDL_Image
// Load an image from an SDL data source.
// The 'type' may be one of: "BMP", "GIF", "PNG", etc.
// If the image format supports a transparent pixel, SDL will set the
// colorkey for the surface.  You can enable RLE acceleration on the
// surface afterwards by calling:
// SDL_SetColorKey(image, SDL_RLEACCEL, image->format->colorkey);
func imgLoad(filename string) *C.SDL_Surface {
	cfile := cstr(filename)
	defer cfile.free()
	return C.IMG_Load(cfile)
}
示例#12
0
文件: image.go 项目: griffy/starfish
type imageKey struct {
	path   string
	width  int
	height int
}

func (me *imageKey) String() string {
	return me.path + strconv.Itoa(me.width) + strconv.Itoa(me.height)
}

//Resizes images from imageFiles and caches them.
var images = newFlyweight(
	func(path key) interface{} {
		key := path.(*imageKey)
		tmp := C.IMG_Load(C.CString(key.path))
		i := C.SDL_DisplayFormatAlpha(tmp)
		C.SDL_FreeSurface(tmp)
		if key.width != -1 && key.height != -1 {
			if (i != nil) && (int(i.w) != key.width || int(i.h) != key.height) {
				i = resize(i, key.width, key.height)
			}
		}
		return i
	},
	func(path key, img interface{}) {
		i := img.(*C.SDL_Surface)
		C.SDL_FreeSurface(i)
	})

type Image struct {
示例#13
0
func Load(file string) *sdl.Surface {
	return (*sdl.Surface)(unsafe.Pointer(C.IMG_Load(C.CString(file))))
}