more documentation; renamed W/H to Width/Height on Image type
This commit is contained in:
parent
a9aa15d1d6
commit
37767fa86f
4 changed files with 34 additions and 3 deletions
|
@ -157,7 +157,8 @@ var (
|
||||||
|
|
||||||
// LoadGL needs to be called once per GL context to load the GL assets
|
// LoadGL needs to be called once per GL context to load the GL assets
|
||||||
// that canvas needs. The parameter is an implementation of the GL interface
|
// that canvas needs. The parameter is an implementation of the GL interface
|
||||||
// in this package that should make this package neutral to GL implementations
|
// in this package that should make this package neutral to GL implementations.
|
||||||
|
// The goglimpl subpackage contains an implementation based on Go-GL v3.2
|
||||||
func LoadGL(glimpl GL) (err error) {
|
func LoadGL(glimpl GL) (err error) {
|
||||||
gli = glimpl
|
gli = glimpl
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,8 @@ import (
|
||||||
var imageBufTex uint32
|
var imageBufTex uint32
|
||||||
var imageBuf []byte
|
var imageBuf []byte
|
||||||
|
|
||||||
|
// GetImageData returns an RGBA image of the currently displayed image. The
|
||||||
|
// alpha channel is always opaque
|
||||||
func (cv *Canvas) GetImageData(x, y, w, h int) *image.RGBA {
|
func (cv *Canvas) GetImageData(x, y, w, h int) *image.RGBA {
|
||||||
cv.activate()
|
cv.activate()
|
||||||
|
|
||||||
|
@ -42,6 +44,7 @@ func (cv *Canvas) GetImageData(x, y, w, h int) *image.RGBA {
|
||||||
return rgba
|
return rgba
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// PutImageData puts the given image at the given x/y coordinates
|
||||||
func (cv *Canvas) PutImageData(img *image.RGBA, x, y int) {
|
func (cv *Canvas) PutImageData(img *image.RGBA, x, y int) {
|
||||||
cv.activate()
|
cv.activate()
|
||||||
|
|
||||||
|
|
28
images.go
28
images.go
|
@ -9,6 +9,7 @@ import (
|
||||||
"unsafe"
|
"unsafe"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Image represents a loaded image that can be used in various drawing functions
|
||||||
type Image struct {
|
type Image struct {
|
||||||
w, h int
|
w, h int
|
||||||
tex uint32
|
tex uint32
|
||||||
|
@ -17,6 +18,11 @@ type Image struct {
|
||||||
|
|
||||||
var images = make(map[string]*Image)
|
var images = make(map[string]*Image)
|
||||||
|
|
||||||
|
// LoadImage loads an image. The src parameter can be either an image from the
|
||||||
|
// standard image package, a byte slice that will be loaded, or a file name
|
||||||
|
// string. If you want the canvas package to load the image, make sure you
|
||||||
|
// import the required format packages. Name is an optional name that can also
|
||||||
|
// be used in draw functions
|
||||||
func LoadImage(src interface{}, name string) (*Image, error) {
|
func LoadImage(src interface{}, name string) (*Image, error) {
|
||||||
var img *Image
|
var img *Image
|
||||||
var err error
|
var err error
|
||||||
|
@ -163,15 +169,33 @@ func loadImageConverted(src image.Image) (*Image, error) {
|
||||||
return img, nil
|
return img, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (img *Image) W() int { return img.w }
|
// Width returns the width of the image
|
||||||
func (img *Image) H() int { return img.h }
|
func (img *Image) Width() int { return img.w }
|
||||||
|
|
||||||
|
// Height returns the height of the image
|
||||||
|
func (img *Image) Height() int { return img.h }
|
||||||
|
|
||||||
|
// Size returns the width and height of the image
|
||||||
func (img *Image) Size() (int, int) { return img.w, img.h }
|
func (img *Image) Size() (int, int) { return img.w, img.h }
|
||||||
|
|
||||||
|
// Delete deletes the image from memory. Any draw calls with a deleted image
|
||||||
|
// will not do anything
|
||||||
func (img *Image) Delete() {
|
func (img *Image) Delete() {
|
||||||
gli.DeleteTextures(1, &img.tex)
|
gli.DeleteTextures(1, &img.tex)
|
||||||
img.deleted = true
|
img.deleted = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Draw image draws the given image to the given coordinates. The image
|
||||||
|
// parameter can be an Image loaded by LoadImage, a file name string that will
|
||||||
|
// be loaded and cached, or a name string that corresponds to a previously
|
||||||
|
// loaded image with the same name parameter.
|
||||||
|
//
|
||||||
|
// The coordinates must be one of the following:
|
||||||
|
// DrawImage("image", dx, dy)
|
||||||
|
// DrawImage("image", dx, dy, dw, dh)
|
||||||
|
// DrawImage("image", sx, sy, sw, sh, dx, dy, dw, dh)
|
||||||
|
// Where dx/dy/dw/dh are the destination coordinates and sx/sy/sw/sh are the
|
||||||
|
// source coordinates
|
||||||
func (cv *Canvas) DrawImage(image interface{}, coords ...float64) {
|
func (cv *Canvas) DrawImage(image interface{}, coords ...float64) {
|
||||||
var img *Image
|
var img *Image
|
||||||
switch v := image.(type) {
|
switch v := image.(type) {
|
||||||
|
|
|
@ -789,6 +789,9 @@ const (
|
||||||
gl_ZERO = 0
|
gl_ZERO = 0
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// The GL interface is used to make this package independent of any particular
|
||||||
|
// OpenGL implementation. The goglimpl subpackage conatins an implementation of
|
||||||
|
// this interface based on Go-GL v3.2
|
||||||
type GL interface {
|
type GL interface {
|
||||||
Ptr(data interface{}) unsafe.Pointer
|
Ptr(data interface{}) unsafe.Pointer
|
||||||
PtrOffset(offset int) unsafe.Pointer
|
PtrOffset(offset int) unsafe.Pointer
|
||||||
|
|
Loading…
Reference in a new issue