示例#1
0
文件: texture.go 项目: hialin/hialin
func MakeRandomTexture(textureSlot int) (Texture, error) {
	texture := NewTexture()
	texture.Bind(textureSlot)

	// gl.Enable(gl.TEXTURE_2D) // for some ATI drivers, for mipmap gen
	gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR)
	Check()
	gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR_MIPMAP_LINEAR)
	Check()
	gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE)
	Check()
	gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE)
	Check()

	var anisotropy float32
	gl.GetFloatv(MaxTextureMaxAnisotropyExt, &anisotropy)
	Check()
	gl.TexParameterf(gl.TEXTURE_2D, TextureMaxAnisotropyExt, anisotropy)
	Check()

	gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_BASE_LEVEL, 0)
	Check()
	gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAX_LEVEL, 0)
	Check()

	var pix [3 * 700 * 700]byte
	for i := 0; i < 3*700*700; i++ {
		pix[i] = byte(128 + i/16)
	}

	gl.TexImage2D(
		gl.TEXTURE_2D,
		0,
		gl.RGB,
		700,
		700,
		0,
		gl.RGB,
		gl.UNSIGNED_BYTE,
		gl.Ptr(&pix[0]))
	Check()

	return texture, nil
}
示例#2
0
文件: texture.go 项目: hialin/hialin
func (texture Texture) Load(textureSlot int, rgba *image.RGBA) {
	texture.Bind(textureSlot)

	// gl.Enable(gl.TEXTURE_2D) // for some ATI drivers, for mipmap gen
	gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR)
	Check()
	gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR_MIPMAP_LINEAR)
	Check()
	gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE)
	Check()
	gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE)
	Check()

	var anisotropy float32
	gl.GetFloatv(MaxTextureMaxAnisotropyExt, &anisotropy)
	Check()
	gl.TexParameterf(gl.TEXTURE_2D, TextureMaxAnisotropyExt, anisotropy)
	Check()

	gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_BASE_LEVEL, 0)
	Check()
	gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAX_LEVEL, 0)
	Check()

	gl.TexImage2D(
		gl.TEXTURE_2D,
		0,
		gl.RGBA,
		int32(rgba.Rect.Size().X),
		int32(rgba.Rect.Size().Y),
		0,
		gl.RGBA,
		gl.UNSIGNED_BYTE,
		gl.Ptr(rgba.Pix))
	Check()
}