added checks that LoadGL is called before anything else is done

This commit is contained in:
Thomas Friedel 2018-09-18 14:20:08 +02:00
parent caaba150e8
commit 34c01f47d4
4 changed files with 16 additions and 1 deletions

View file

@ -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

View file

@ -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)

View file

@ -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) {

View file

@ -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: