diff --git a/canvas.go b/canvas.go index 0250e7a..985fda2 100644 --- a/canvas.go +++ b/canvas.go @@ -102,6 +102,9 @@ const ( // the origin, since GL uses the bottom left coordinate, the // coordinates given here also use the bottom left as origin func New(x, y, w, h int) *Canvas { + if gli == nil { + panic("LoadGL must be called before a canvas can be created") + } cv := &Canvas{stateStack: make([]drawState, 0, 20)} cv.SetBounds(x, y, w, h) cv.state.lineWidth = 1 diff --git a/gradients.go b/gradients.go index c7a88c9..5d19b19 100644 --- a/gradients.go +++ b/gradients.go @@ -40,6 +40,9 @@ type gradientStop struct { // the coordinates from where to where the gradient // will apply on the canvas func NewLinearGradient(x0, y0, x1, y1 float64) *LinearGradient { + if gli == nil { + panic("LoadGL must be called before gradients can be created") + } lg := &LinearGradient{gradient: gradient{from: vec{x0, y0}, to: vec{x1, y1}, opaque: true}} gli.GenTextures(1, &lg.tex) gli.ActiveTexture(gl_TEXTURE0) @@ -61,6 +64,9 @@ func NewLinearGradient(x0, y0, x1, y1 float64) *LinearGradient { // gradient will apply from the first to the second // circle func NewRadialGradient(x0, y0, r0, x1, y1, r1 float64) *RadialGradient { + if gli == nil { + panic("LoadGL must be called before gradients can be created") + } rg := &RadialGradient{gradient: gradient{from: vec{x0, y0}, to: vec{x1, y1}, opaque: true}, radFrom: r0, radTo: r1} gli.GenTextures(1, &rg.tex) gli.ActiveTexture(gl_TEXTURE0) diff --git a/images.go b/images.go index e6459ff..d4a8aea 100644 --- a/images.go +++ b/images.go @@ -24,6 +24,9 @@ var images = make(map[string]*Image) // string. If you want the canvas package to load the image, make sure you // import the required format packages func LoadImage(src interface{}) (*Image, error) { + if gli == nil { + panic("LoadGL must be called before images can be loaded") + } var img *Image var err error switch v := src.(type) { diff --git a/text.go b/text.go index d5982d5..51474dd 100644 --- a/text.go +++ b/text.go @@ -30,6 +30,9 @@ var defaultFont *Font // LoadFont loads a font and returns the result. The font // can be a file name or a byte slice in TTF format func LoadFont(src interface{}) (*Font, error) { + if gli == nil { + panic("LoadGL must be called before fonts can be loaded") + } var f *Font switch v := src.(type) { case *truetype.Font: @@ -392,7 +395,7 @@ func (cv *Canvas) MeasureText(str string) TextMetrics { } return TextMetrics{ - Width: x, + Width: x, ActualBoundingBoxAscent: -minY, ActualBoundingBoxDescent: +maxY, }