func NewTexture(c *opengl.Context, width, height int, filter opengl.Filter) (*Texture, error) { w := NextPowerOf2Int(width) h := NextPowerOf2Int(height) if w < 4 { return nil, errors.New("width must be equal or more than 4.") } if h < 4 { return nil, errors.New("height must be equal or more than 4.") } native, err := c.NewTexture(w, h, nil, filter) if err != nil { return nil, err } return &Texture{native, width, height}, nil }
func NewTextureFromImage(c *opengl.Context, img image.Image, filter opengl.Filter) (*Texture, error) { origSize := img.Bounds().Size() if origSize.X < 4 { return nil, errors.New("width must be equal or more than 4.") } if origSize.Y < 4 { return nil, errors.New("height must be equal or more than 4.") } adjustedImage := adjustImageForTexture(img) size := adjustedImage.Bounds().Size() native, err := c.NewTexture(size.X, size.Y, adjustedImage.Pix, filter) if err != nil { return nil, err } return &Texture{native, origSize.X, origSize.Y}, nil }