From 4950d7d02cb7b1454ff25e6796851e09b7496297 Mon Sep 17 00:00:00 2001
From: faiface <faiface@ksp.sk>
Date: Wed, 21 Dec 2016 20:51:05 +0100
Subject: [PATCH] add texture smoothiness

---
 picture.go         |  3 ++-
 pixelgl/texture.go | 13 ++++++++++++-
 2 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/picture.go b/picture.go
index 9d07b8f..e852d84 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 acdde9e..dad02ac 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)
 		})
 	})
-- 
GitLab