func NewSpriteFromSprite(sprite *Sprite) (*Sprite, error) {
	shape, err := NewShapeFromShape(sprite.shape)
	if err != nil {
		return nil, err
	}
	newSprite := &Sprite{texcoordBuffer: sprite.texcoordBuffer, texture: sprite.texture,
		shape: shape}
	return newSprite, checkForErrors()
}
NewSpriteFromSprite creates a new Sprite object that uses the same image
data as the supplied Sprite object. This can serve to save a lot of GPU
memory when dealing with Sprite objects that use image data.
package paunch
import (
	gl "github.com/chsc/gogl/gl21"
	"image"
	"image/png"
	"os"
)
type Sprite struct {
	texcoordBuffer gl.Uint
	texture        []gl.Uint
	shape          *Shape
}
func imageToBytes(img image.Image) (int, int, []byte) {
	width := img.Bounds().Max.X - img.Bounds().Min.X
	height := img.Bounds().Max.Y - img.Bounds().Min.Y
	var bytes []byte
	for i := 0; i < width*height; i++ {
		r, g, b, a := img.At(i%width, i/width).RGBA()
		bytes = append(bytes, byte(r))
		bytes = append(bytes, byte(g))
		bytes = append(bytes, byte(b))
		bytes = append(bytes, byte(a))
	}
	flippedBytes := make([]byte, width*height*4)
	for i := 0; i < height*width*4; i += width * 4 {
		pixrow := bytes[i : i+width*4]
		for j, val := range pixrow {
			flippedBytes[((width*(height-1)*4)-i)+j] = val
		}
	}
	return img.Bounds().Max.X, img.Bounds().Max.Y, flippedBytes
}
func NewSprite(x, y, width, height float64, data []byte, clip int) (*Sprite, error) {
	verticies := []float64{
		x, y,
		x + width, y,
		x, y + height,
		x + width, y + height,
		x + width, y,
		x, y + height}
	shape, err := NewShape(gl.TRIANGLES, verticies)
	if err != nil {
		return nil, err
	}
	sprite := &Sprite{texcoordBuffer: 0, texture: nil, shape: shape}
	texCoords := []float32{
		0, 0,
		1, 0,
		0, 1,
		1, 1,
		1, 0,
		0, 1}
	gl.GenBuffers(1, &sprite.texcoordBuffer)
	gl.BindBuffer(gl.ARRAY_BUFFER, gl.Uint(sprite.texcoordBuffer))
	gl.BufferData(gl.ARRAY_BUFFER, gl.Sizeiptr(len(texCoords)*4), gl.Pointer(&texCoords[0]), gl.STREAM_DRAW)
	gl.BindBuffer(gl.ARRAY_BUFFER, 0)
	sprite.texture = make([]gl.Uint, clip)
	gl.GenTextures(gl.Sizei(clip), &sprite.texture[0])
	clips := make([][]byte, clip)
	for i := range clips {
		clips[i] = data[i*(len(data)/len(clips)) : (i+1)*(len(data)/len(clips))]
		gl.BindTexture(gl.TEXTURE_2D, sprite.texture[len(clips)-1-i])
		gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR)
		gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST)
		gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.REPEAT)
		gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.REPEAT)
		gl.TexImage2D(gl.TEXTURE_2D, 0, gl.RGBA,
			gl.Sizei(width), gl.Sizei(height),
			0, gl.RGBA, gl.UNSIGNED_BYTE,
			gl.Pointer(&clips[i][0]))
	}
	gl.BindTexture(gl.TEXTURE_2D, 0)
	return sprite, checkForErrors()
}
func NewSpriteFromImage(x, y float64, filename string, clip int) (*Sprite, error) {
	var sprite *Sprite
	file, err := os.Open(filename)
	if err != nil {
		return sprite, err
	}
	defer file.Close()
	data, err := png.Decode(file)
	if err != nil {
		return sprite, err
	}
	width, height, byteData := imageToBytes(data)
	sprite, err = NewSprite(x, y, float64(width), float64(height/clip), byteData, clip)
	if err != nil {
		return sprite, err
	}
	return sprite, nil
}