diff --git a/picture.go b/picture.go index 9d07b8f5ee0dac4e0ec5707e74cbc18e714f9e65..e852d84e541508861adf1d6ef0e9106f0a22ebcf 100644 --- a/picture.go +++ b/picture.go @@ -18,7 +18,7 @@ type Picture struct { } // 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 rgba := image.NewRGBA(image.Rect(0, 0, img.Bounds().Dx(), img.Bounds().Dy())) draw.Draw(rgba, rgba.Bounds(), img, img.Bounds().Min, draw.Src) @@ -27,6 +27,7 @@ func NewPicture(img image.Image) *Picture { pixelgl.NoOpDoer, img.Bounds().Dx(), img.Bounds().Dy(), + smooth, rgba.Pix, ) if err != nil { diff --git a/pixelgl/texture.go b/pixelgl/texture.go index acdde9e2262df8128a46b3b04e74324a07f3d43f..dad02acc16273153b24fc6eecbf882dd56d060de 100644 --- a/pixelgl/texture.go +++ b/pixelgl/texture.go @@ -12,7 +12,7 @@ type Texture struct { // NewTexture creates a new texture with the specified width and height. // 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{ parent: parent, tex: binder{ @@ -42,6 +42,17 @@ func NewTexture(parent Doer, width, height int, pixels []uint8) (*Texture, error 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) }) })