Example #1
0
func NewTextureBuffer(data interface{}) *TextureBuffer {
	texbuf := new(TextureBuffer)
	texbuf.Texture = new(Texture)
	gl33.GenTextures(1, &texbuf.Texture.Id)
	texbuf.Texture.Type = gl33.TEXTURE_BUFFER
	texbuf.Buffer = NewBuffer(gl33.TEXTURE_BUFFER, gl33.DYNAMIC_DRAW, data)
	texbuf.Width = texbuf.Buffer.Value.Len()
	var format gl33.Enum
	switch data.(type) {
	case []byte:
		format = gl33.R8
	case []uint16:
		format = gl33.R16
	case [][2]byte:
		format = gl33.RG8
	case [][2]uint16:
		format = gl33.RG16
	case [][4]byte:
		format = gl33.RGBA8
	case [][4]uint16:
		format = gl33.RGBA16
	}
	texbuf.Bind(0)
	gl33.TexBuffer(gl33.TEXTURE_BUFFER, format, texbuf.Buffer.Id)
	return texbuf
}
Example #2
0
// LoadTexture buffers an image.Image into the graphic cards memory.
func LoadTexture(img image.Image) (*Texture, error) {
	w := img.Bounds().Dx()
	h := img.Bounds().Dy()
	rgba := image.NewRGBA(image.Rect(0, 0, w, h))
	for x := 0; x < w; x++ {
		for y := 0; y < h; y++ {
			rgba.Set(x, y, img.At(x, y))
		}
	}
	var textureId gl.Uint
	//gl.ActiveTexture(gl.TEXTURE0)
	gl.GenTextures(1, &textureId)
	gl.BindTexture(gl.TEXTURE_2D, textureId)
	//gl.TexParameterf(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR)
	gl.TexParameterf(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR)

	gl.TexImage2D(gl.TEXTURE_2D, 0, 4, gl.Sizei(rgba.Rect.Dx()), gl.Sizei(rgba.Rect.Dy()), 0, gl.RGBA, gl.UNSIGNED_BYTE, gl.Pointer(&rgba.Pix[0]))

	gl.BindTexture(gl.TEXTURE_2D, 0)
	return &Texture{id: textureId}, nil
}
Example #3
0
func NewTextureCubeMap() *Texture {
	tex := new(Texture)
	gl33.GenTextures(1, &tex.Id)
	tex.Type = gl33.TEXTURE_CUBE_MAP
	return tex
}
Example #4
0
func NewTextureArray() *Texture {
	tex := new(Texture)
	gl33.GenTextures(1, &tex.Id)
	tex.Type = gl33.TEXTURE_2D_ARRAY
	return tex
}
Example #5
0
func NewTexture2D() *Texture {
	tex := new(Texture)
	gl33.GenTextures(1, &tex.Id)
	tex.Type = gl33.TEXTURE_2D
	return tex
}