func (tex *Texture) Unbind() { bound := tex.bound() if *bound == tex { gl33.BindTexture(tex.Type, 0) *bound = nil } }
func (tex *Texture) Bind(textureUnit int) { if activeTexture != textureUnit { gl33.ActiveTexture(gl33.Enum(gl33.TEXTURE0 + textureUnit)) activeTexture = textureUnit } bound := tex.bound() if *bound != tex { gl33.BindTexture(tex.Type, tex.Id) *bound = tex } }
// LoadTexture buffers an image.Image into the graphic cards memory. func LoadTexture(img image.Image) (*Texture, error) { w := img.Bounds().Dx() h := img.Bounds().Dy() rgba := image.NewRGBA(image.Rect(0, 0, w, h)) for x := 0; x < w; x++ { for y := 0; y < h; y++ { rgba.Set(x, y, img.At(x, y)) } } var textureId gl.Uint //gl.ActiveTexture(gl.TEXTURE0) gl.GenTextures(1, &textureId) gl.BindTexture(gl.TEXTURE_2D, textureId) //gl.TexParameterf(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR) gl.TexParameterf(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR) gl.TexImage2D(gl.TEXTURE_2D, 0, 4, gl.Sizei(rgba.Rect.Dx()), gl.Sizei(rgba.Rect.Dy()), 0, gl.RGBA, gl.UNSIGNED_BYTE, gl.Pointer(&rgba.Pix[0])) gl.BindTexture(gl.TEXTURE_2D, 0) return &Texture{id: textureId}, nil }
func (t *Texture) Unbind() { gl.BindTexture(gl.TEXTURE_2D, 0) }
func (t *Texture) Bind() { gl.BindTexture(gl.TEXTURE_2D, t.id) }