Пример #1
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)
}
Пример #2
0
func (tex Texture) Update(ctx gl.Context, lvl int, width int, height int, data []byte) {
	ctx.TexImage2D(gl.TEXTURE_2D, lvl, width, height, gl.RGBA, gl.UNSIGNED_BYTE, data)
	if lvl > 0 {
		ctx.GenerateMipmap(gl.TEXTURE_2D)
	}
}
Пример #3
0
func (tex Texture) Update(ctx gl.Context, width int, height int, data []byte) {
	ctx.TexImage2D(gl.TEXTURE_2D, 0, width, height, gl.RGBA, gl.UNSIGNED_BYTE, data)
}