Пример #1
0
func (dev *openGLGraphicsDevice) SetTexture2D(texture Texture2D, unit uint) {
	gltexture := texture.(*openGLTexture2D)
	gl.ActiveTexture(gl.TEXTURE0 + gl.GLenum(unit))
	if gltexture != nil {
		gltexture.tex.Bind(gl.TEXTURE_2D)
	} else {
		gl.Texture(0).Bind(gl.TEXTURE_2D)
	}
}
Пример #2
0
func loadSurface(img image.Image) gl.Texture {
	w := img.Bounds().Dx()
	h := img.Bounds().Dy()
	rgba := image.NewRGBA(w, h)
	for x := 0; x < w; x++ {
		for y := 0; y < h; y++ {
			rgba.Set(x, y, img.At(x, y))
		}
	}
	gl.ActiveTexture(gl.TEXTURE0)
	texture := gl.GenTexture()
	texture.Bind(gl.TEXTURE_2D)

	gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR)

	gl.TexImage2D(gl.TEXTURE_2D, 0, gl.RGBA, rgba.Rect.Dx(), rgba.Rect.Dy(), 0, gl.RGBA, gl.UNSIGNED_BYTE, rgba.Pix)

	texture.Unbind(gl.TEXTURE_2D)
	return texture
}