示例#1
0
文件: gl.go 项目: dskinner/material
func (tex Texture) Bind(ctx gl.Context, options ...func(gl.Context, Texture)) {
	ctx.ActiveTexture(gl.Enum(uint32(gl.TEXTURE0) + tex.Value - 1))
	ctx.BindTexture(gl.TEXTURE_2D, tex.Texture)
	for _, opt := range options {
		opt(ctx, tex)
	}
}
示例#2
0
func loadTexture(glctx gl.Context) {
	a, err := asset.Open("key.jpeg")
	if err != nil {
		log.Fatal(err)
	}
	defer a.Close()

	img, _, err := image.Decode(a)
	if err != nil {
		log.Fatal(err)
	}

	rect := img.Bounds()
	rgba := image.NewRGBA(rect)
	draw.Draw(rgba, rect, img, rect.Min, draw.Src)
	tex := glctx.CreateTexture()

	glctx.ActiveTexture(gl.TEXTURE0)
	glctx.BindTexture(gl.TEXTURE_2D, tex)

	glctx.TexImage2D(gl.TEXTURE_2D, 0, 859, 610, gl.RGBA, gl.UNSIGNED_BYTE, rgba.Pix)

	glctx.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR)
	glctx.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR)
	glctx.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE)
	glctx.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE)

	glctx.ActiveTexture(gl.TEXTURE0)
	glctx.BindTexture(gl.TEXTURE_2D, tex)
	glctx.TexImage2D(
		gl.TEXTURE_2D, 0,
		rect.Max.X-rect.Min.X, rect.Max.Y-rect.Min.Y,
		gl.RGBA, gl.UNSIGNED_BYTE, rgba.Pix)
}
示例#3
0
文件: gl.go 项目: dskinner/material
func (tex Texture) Unbind(ctx gl.Context) {
	ctx.BindTexture(gl.TEXTURE_2D, gl.Texture{0})
}