Skip to content
This repository has been archived by the owner on Jan 20, 2019. It is now read-only.

Commit

Permalink
samples updated for Banthar's new Go-OpenGL
Browse files Browse the repository at this point in the history
  • Loading branch information
rhencke committed Jan 27, 2011
1 parent d4b896f commit 0717b99
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 126 deletions.
84 changes: 0 additions & 84 deletions Go-OpenGL.patch

This file was deleted.

5 changes: 2 additions & 3 deletions README
Expand Up @@ -2,10 +2,9 @@ Go bindings for GLUT: https://github.com/rhencke/Go-GLUT

Requires: https://github.com/banthar/Go-OpenGL

If you are using Mac OS X, and are unable to install Go-OpenGL, please apply Go-OpenGL.patch:
patch -p1 -d your/path/to/Go-OpenGL < Go-OpenGL.patch
cd your/path/to/Go-OpenGL
When installing Go-OpenGL, please use:
make install
(just make will attempt to compile the Go-OpenGL examples, which require SDL)

If you are using Linux, please ensure you have installed GLUT or freeglut.

Expand Down
46 changes: 23 additions & 23 deletions examples/asteroids.go
Expand Up @@ -15,15 +15,15 @@ import "gl"
import "glut"

var (
angle gl.GLfloat
angle float32
left, right bool
leftTime, rightTime int
thrust bool
thrustTime int
joyThrust, joyLeft, joyRight bool
x gl.GLfloat = 20
y gl.GLfloat = 20
xv, yv, v gl.GLfloat
x float32 = 20
y float32 = 20
xv, yv, v float32
shield, joyShield bool
cursor bool = true
lastTime int
Expand All @@ -34,7 +34,7 @@ var (

type Bullet struct {
inuse bool
x, y, v, xv, yv gl.GLfloat
x, y, v, xv, yv float32
expire int
}

Expand All @@ -52,8 +52,8 @@ func allocBullet() int {
}

func initBullet(i, time int) {
c := gl.GLfloat(math.Cos(float64(angle) * math.Pi / 180.0))
s := gl.GLfloat(math.Sin(float64(angle) * math.Pi / 180.0))
c := float32(math.Cos(float64(angle) * math.Pi / 180.0))
s := float32(math.Sin(float64(angle) * math.Pi / 180.0))

bullet[i].inuse = true
bullet[i].x = x + 2*c
Expand All @@ -71,12 +71,12 @@ func advanceBullets(delta, time int) {
bullet[i].inuse = false
continue
}
x := bullet[i].x + bullet[i].xv*gl.GLfloat(delta)
y := bullet[i].y + bullet[i].yv*gl.GLfloat(delta)
x := bullet[i].x + bullet[i].xv*float32(delta)
y := bullet[i].y + bullet[i].yv*float32(delta)
x = x / 40.0
bullet[i].x = (x - gl.GLfloat(math.Floor(float64(x)))) * 40.0
bullet[i].x = (x - float32(math.Floor(float64(x)))) * 40.0
y = y / 40.0
bullet[i].y = (y - gl.GLfloat(math.Floor(float64(x)))) * 40.0
bullet[i].y = (y - float32(math.Floor(float64(x)))) * 40.0
}
}
}
Expand All @@ -99,7 +99,7 @@ func drawBullets() {
gl.End()
}

func drawShip(angle gl.GLfloat) {
func drawShip(angle float32) {
gl.PushMatrix()
gl.Translatef(x, y, 0.0)
gl.Rotatef(angle, 0.0, 0.0, 1.0)
Expand All @@ -124,8 +124,8 @@ func drawShip(angle gl.GLfloat) {
gl.Begin(gl.LINE_LOOP)
for rad := 0.0; rad < 12.0; rad += 1.0 {
gl.Vertex2f(
gl.GLfloat(2.3*math.Cos(2*float64(rad)/math.Pi)+0.2),
gl.GLfloat(2.0*math.Sin(2*float64(rad)/math.Pi)))
float32(2.3*math.Cos(2*float64(rad)/math.Pi)+0.2),
float32(2.0*math.Sin(2*float64(rad)/math.Pi)))
}
gl.End()
}
Expand All @@ -149,28 +149,28 @@ func idle() {
}
if left {
delta = time - leftTime
angle = angle + gl.GLfloat(delta)*gl.GLfloat(0.4)
angle = angle + float32(delta)*float32(0.4)
leftTime = time
}
if right {
delta = time - rightTime
angle = angle - gl.GLfloat(delta)*gl.GLfloat(0.4)
angle = angle - float32(delta)*float32(0.4)
rightTime = time
}
if thrust {
delta = time - thrustTime
v = gl.GLfloat(delta) * 0.00004
xv = xv + gl.GLfloat(math.Cos(float64(angle)*math.Pi/180.0))*v
yv = yv + gl.GLfloat(math.Sin(float64(angle)*math.Pi/180.0))*v
v = float32(delta) * 0.00004
xv = xv + float32(math.Cos(float64(angle)*math.Pi/180.0))*v
yv = yv + float32(math.Sin(float64(angle)*math.Pi/180.0))*v
thrustTime = time
}
delta = time - lastTime
x = x + xv*gl.GLfloat(delta)
y = y + yv*gl.GLfloat(delta)
x = x + xv*float32(delta)
y = y + yv*float32(delta)
x = x / 40.0
x = (x - gl.GLfloat(math.Floor(float64(x)))) * 40.0
x = (x - float32(math.Floor(float64(x)))) * 40.0
y = y / 40.0
y = (y - gl.GLfloat(math.Floor(float64(y)))) * 40.0
y = (y - float32(math.Floor(float64(y)))) * 40.0
lastTime = time
advanceBullets(delta, time)
currentWindow.PostRedisplay()
Expand Down
19 changes: 9 additions & 10 deletions examples/fontdemo.go
Expand Up @@ -9,17 +9,17 @@
package main

import "gl"
import "glu"
import "gl/glu"
import "glut"

func bitmap_output(x, y gl.GLfloat, str string, font glut.BitmapFont) {
func bitmap_output(x, y float32, str string, font glut.BitmapFont) {
gl.RasterPos2f(x, y)
for _, ch := range str {
font.Character(ch)
}
}

func stroke_output(x, y gl.GLfloat, str string, font glut.StrokeFont) {
func stroke_output(x, y float32, str string, font glut.StrokeFont) {
gl.PushMatrix()
gl.Translatef(x, y, 0)
gl.Scalef(0.005, 0.005, 0.005)
Expand All @@ -41,10 +41,9 @@ func display() {
glu.Perspective(40.0, 1.0, 0.1, 20.0)
gl.MatrixMode(gl.MODELVIEW)
gl.PushMatrix()
// Banthar's glu doesn't have this right now.
// glu.LookAt(0.0, 0.0, 4.0, /* eye is at (0,0,30) */
// 0.0, 0.0, 0.0, /* center is at (0,0,0) */
// 0.0, 1.0, 0.) /* up is in postivie Y direction */
glu.LookAt(0.0, 0.0, 4.0, /* eye is at (0,0,30) */
0.0, 0.0, 0.0, /* center is at (0,0,0) */
0.0, 1.0, 0.0) /* up is in postivie Y direction */
gl.PushMatrix()
gl.Translatef(0, 0, -4)
gl.Rotatef(50, 0, 1, 0)
Expand All @@ -61,12 +60,12 @@ func display() {
}

func reshape(w, h int) {
gl.Viewport(0, 0, gl.GLsizei(w), gl.GLsizei(h))
gl.Viewport(0, 0, w, h)
gl.MatrixMode(gl.PROJECTION)
gl.LoadIdentity()
gl.Ortho(0, gl.GLdouble(w), 0, gl.GLdouble(h), -1, 1)
gl.Ortho(0, float64(w), 0, float64(h), -1, 1)
gl.Scalef(1, -1, 1)
gl.Translatef(0, gl.GLfloat(-h), 0)
gl.Translatef(0, float32(-h), 0)
gl.MatrixMode(gl.MODELVIEW)
}

Expand Down
12 changes: 6 additions & 6 deletions examples/simple.go
Expand Up @@ -27,12 +27,12 @@ func reshape(w, h int) {
wouldn't be required if you chose a (more typical in 3D) abstract
coordinate system. */

gl.Viewport(0, 0, gl.GLsizei(w), gl.GLsizei(h)) /* Establish viewing area to cover entire window. */
gl.MatrixMode(gl.PROJECTION) /* Start modifying the projection matrix. */
gl.LoadIdentity() /* Reset project matrix. */
gl.Ortho(0, gl.GLdouble(w), 0, gl.GLdouble(h), -1, 1) /* Map abstract coords directly to window coords. */
gl.Scalef(1, -1, 1) /* Invert Y axis so increasing Y goes down. */
gl.Translatef(0, gl.GLfloat(-h), 0) /* Shift origin up to upper-left corner. */
gl.Viewport(0, 0, w, h) /* Establish viewing area to cover entire window. */
gl.MatrixMode(gl.PROJECTION) /* Start modifying the projection matrix. */
gl.LoadIdentity() /* Reset project matrix. */
gl.Ortho(0, float64(w), 0, float64(h), -1, 1) /* Map abstract coords directly to window coords. */
gl.Scalef(1, -1, 1) /* Invert Y axis so increasing Y goes down. */
gl.Translatef(0, float32(-h), 0) /* Shift origin up to upper-left corner. */
}

func display() {
Expand Down

0 comments on commit 0717b99

Please sign in to comment.