Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
27 changes: 17 additions & 10 deletions examples/gopher/gopher.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"image"
"image/png"
"io"
"io/ioutil"
"os"
)

Expand All @@ -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() {
Expand Down Expand Up @@ -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]))

Expand All @@ -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)
Expand All @@ -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
}

Expand Down