From e656130ce3db63a20865203d1cbaf2a01d104eb5 Mon Sep 17 00:00:00 2001
From: faiface <faiface@ksp.sk>
Date: Sun, 22 Jan 2017 14:16:06 +0100
Subject: [PATCH] change pixelgl.Texture.Pixels to work with OpenGL 3.3

---
 pixelgl/texture.go | 21 +++++++++++----------
 1 file changed, 11 insertions(+), 10 deletions(-)

diff --git a/pixelgl/texture.go b/pixelgl/texture.go
index 05b2987..2870d0a 100644
--- a/pixelgl/texture.go
+++ b/pixelgl/texture.go
@@ -1,6 +1,7 @@
 package pixelgl
 
 import (
+	"fmt"
 	"runtime"
 
 	"github.com/faiface/mainthread"
@@ -100,22 +101,22 @@ func (t *Texture) SetPixels(x, y, w, h int, pixels []uint8) {
 
 // Pixels returns the content of a sub-region of the Texture as an RGBA byte sequence.
 func (t *Texture) Pixels(x, y, w, h int) []uint8 {
-	pixels := make([]uint8, w*h*4)
-	gl.GetTextureSubImage(
+	pixels := make([]uint8, t.width*t.height*4)
+	gl.GetTexImage(
 		gl.TEXTURE_2D,
 		0,
-		int32(x),
-		int32(y),
-		0,
-		int32(w),
-		int32(h),
-		0,
 		gl.RGBA,
 		gl.UNSIGNED_BYTE,
-		int32(len(pixels)),
 		gl.Ptr(pixels),
 	)
-	return pixels
+	subPixels := make([]uint8, w*h*4)
+	for i := 0; i < h; i++ {
+		row := pixels[(i+y)*t.width*4+x*4 : (i+y)*t.width*4+(x+w)*4]
+		subRow := subPixels[i*w*4 : (i+1)*w*4]
+		fmt.Println((i+y)*t.width*4+x*4, (i+y)*t.width*4+(x+w)*4)
+		copy(subRow, row)
+	}
+	return subPixels
 }
 
 // Begin binds a texture. This is necessary before using the texture.
-- 
GitLab