diff --git a/Makefile b/Makefile index 4f7c775..e5c76c3 100644 --- a/Makefile +++ b/Makefile @@ -7,7 +7,7 @@ bindings: install_bindings: go install ./gl21 # go install ./gl30 - go install ./gl31 +# go install ./gl31 # go install ./gl31c # go install ./gl32 # go install ./gl32c diff --git a/examples/gopher/gopher.go b/examples/gopher/gopher.go index 550b3bc..bf34ab4 100644 --- a/examples/gopher/gopher.go +++ b/examples/gopher/gopher.go @@ -9,6 +9,7 @@ import ( "image" "image/png" "io" + "io/ioutil" "os" ) @@ -19,11 +20,11 @@ const ( ) var ( - texture gl.Uint - rotx, roty gl.Float - ambient []gl.Float = []gl.Float{0.5, 0.5, 0.5, 1} - diffuse []gl.Float = []gl.Float{1, 1, 1, 1} - lightpos []gl.Float = []gl.Float{-5, 5, 10, 0} + texture gl.Uint + rotx, roty gl.Float + ambient []gl.Float = []gl.Float{0.5, 0.5, 0.5, 1} + diffuse []gl.Float = []gl.Float{1, 1, 1, 1} + lightpos []gl.Float = []gl.Float{-5, 5, 10, 0} ) func main() { @@ -78,12 +79,12 @@ func createTexture(r io.Reader) (textureId gl.Uint, err error) { // flip image: first pixel is lower left corner imgWidth, imgHeight := img.Bounds().Dx(), img.Bounds().Dy() - data := make([]byte, imgWidth * imgHeight * 4) + data := make([]byte, imgWidth*imgHeight*4) lineLen := imgWidth * 4 - dest := len(data)-lineLen - for src := 0; src < len(rgbaImg.Pix); src+=rgbaImg.Stride { + dest := len(data) - lineLen + for src := 0; src < len(rgbaImg.Pix); src += rgbaImg.Stride { copy(data[dest:dest+lineLen], rgbaImg.Pix[src:src+rgbaImg.Stride]) - dest-=lineLen + dest -= lineLen } gl.TexImage2D(gl.TEXTURE_2D, 0, 4, gl.Sizei(imgWidth), gl.Sizei(imgHeight), 0, gl.RGBA, gl.UNSIGNED_BYTE, gl.Pointer(&data[0])) @@ -96,6 +97,7 @@ func createTextureFromBytes(data []byte) (gl.Uint, error) { } func initScene() (err error) { + gl.Enable(gl.TEXTURE_2D) gl.Enable(gl.DEPTH_TEST) gl.Enable(gl.LIGHTING) @@ -116,7 +118,12 @@ func initScene() (err error) { gl.MatrixMode(gl.MODELVIEW) gl.LoadIdentity() - texture, err = createTextureFromBytes(gopher_png[:]) + gopher_png, err := ioutil.ReadFile("gopher.png") + if err != nil { + panic("Could not load png") + } + + texture, err = createTextureFromBytes(gopher_png) return }