add texture smoothiness

This commit is contained in:
faiface 2016-12-21 20:51:05 +01:00
parent 074d1cedaa
commit 4950d7d02c
2 changed files with 14 additions and 2 deletions

View File

@ -18,7 +18,7 @@ type Picture struct {
} }
// NewPicture creates a new picture from an image.Image. // NewPicture creates a new picture from an image.Image.
func NewPicture(img image.Image) *Picture { func NewPicture(img image.Image, smooth bool) *Picture {
// convert the image to RGBA format // convert the image to RGBA format
rgba := image.NewRGBA(image.Rect(0, 0, img.Bounds().Dx(), img.Bounds().Dy())) rgba := image.NewRGBA(image.Rect(0, 0, img.Bounds().Dx(), img.Bounds().Dy()))
draw.Draw(rgba, rgba.Bounds(), img, img.Bounds().Min, draw.Src) draw.Draw(rgba, rgba.Bounds(), img, img.Bounds().Min, draw.Src)
@ -27,6 +27,7 @@ func NewPicture(img image.Image) *Picture {
pixelgl.NoOpDoer, pixelgl.NoOpDoer,
img.Bounds().Dx(), img.Bounds().Dx(),
img.Bounds().Dy(), img.Bounds().Dy(),
smooth,
rgba.Pix, rgba.Pix,
) )
if err != nil { if err != nil {

View File

@ -12,7 +12,7 @@ type Texture struct {
// NewTexture creates a new texture with the specified width and height. // NewTexture creates a new texture with the specified width and height.
// The pixels must be a sequence of RGBA values. // The pixels must be a sequence of RGBA values.
func NewTexture(parent Doer, width, height int, pixels []uint8) (*Texture, error) { func NewTexture(parent Doer, width, height int, smooth bool, pixels []uint8) (*Texture, error) {
texture := &Texture{ texture := &Texture{
parent: parent, parent: parent,
tex: binder{ tex: binder{
@ -42,6 +42,17 @@ func NewTexture(parent Doer, width, height int, pixels []uint8) (*Texture, error
gl.Ptr(pixels), gl.Ptr(pixels),
) )
gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.MIRRORED_REPEAT)
gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.MIRRORED_REPEAT)
if smooth {
gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR_MIPMAP_LINEAR)
gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR)
} else {
gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST_MIPMAP_NEAREST)
gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST)
}
gl.GenerateMipmap(gl.TEXTURE_2D) gl.GenerateMipmap(gl.TEXTURE_2D)
}) })
}) })