Ejemplo n.º 1
0
func LoadTexture(texture gl.Texture, filename string) error {
	file, err := os.Open(filename)
	if err != nil {
		return err
	}
	defer file.Close()
	img, _, err := image.Decode(file)
	if err != nil {
		return err
	}
	width, height, format, channelType, pixels := ImageData(img)
	gl.BindTexture(gl.TEXTURE_2D, texture)
	gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR)
	gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR)
	gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE)
	gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE)
	gl.TexImage2D(
		gl.TEXTURE_2D, 0, /* target, level of detail */
		gl.RGB8,          /* internal format */
		width, height, 0, /* width, height, border */
		format, channelType, /* external format, type */
		pixels, /* pixels */
	)
	return nil
}
Ejemplo n.º 2
0
func AttachTexture(location gl.UniformLocation, textureEnum gl.Enum, target gl.Enum, texture gl.Texture) {
	gl.ActiveTexture(textureEnum)
	gl.BindTexture(target, texture)
	gl.Uniform1i(location, gl.Int(textureEnum-gl.TEXTURE0))
}