Exemplo n.º 1
0
func uploadSurface(target gl33.Enum, surface *sdl.Surface) {
	if target == gl33.TEXTURE_CUBE_MAP && surface.W != surface.H {
		panic("Non-square texture in cube map")
	}
	var internalFormat gl33.Int
	var format gl33.Enum
	if surface.Format.BitsPerPixel == 32 {
		internalFormat = gl33.RGBA8
		format = gl33.RGBA
	} else {
		internalFormat = gl33.RGB8
		format = gl33.RGB
	}
	gl33.TexImage2D(target, 0, internalFormat, gl33.Sizei(surface.W), gl33.Sizei(surface.H), 0, format, gl33.UNSIGNED_BYTE, gl33.Pointer(surface.Pixels))
}
Exemplo n.º 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
}