added checks that LoadGL is called before anything else is done
This commit is contained in:
parent
caaba150e8
commit
34c01f47d4
4 changed files with 16 additions and 1 deletions
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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) {
|
||||
|
|
3
text.go
3
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:
|
||||
|
|
Loading…
Reference in a new issue