Esempio n. 1
0
func (cube *Cube) Render() {
	x, y, z := cube.Position.X, cube.Position.Y, cube.Position.Z

	gl.Begin(gl.QUADS)

	gl.Color3d(0.5-(x/50), 0.5-(y/50), 0.5-(z/50))

	// Front Side
	gl.TexCoord2f(0, 0)
	gl.Vertex3d(x-0.5, y-0.5, z+0.5)
	gl.TexCoord2f(1, 0)
	gl.Vertex3d(x+0.5, y-0.5, z+0.5)
	gl.TexCoord2f(1, 1)
	gl.Vertex3d(x+0.5, y+0.5, z+0.5)
	gl.TexCoord2f(0, 1)
	gl.Vertex3d(x-0.5, y+0.5, z+0.5)

	// Left Side
	gl.Color3d(0.5-(x/20), 0.5-(y/20), 0.5-(z/20))
	gl.TexCoord2f(0, 0)
	gl.Vertex3d(x-0.5, y-0.5, z-0.5)
	gl.TexCoord2f(1, 0)
	gl.Vertex3d(x-0.5, y-0.5, z+0.5)
	gl.TexCoord2f(1, 1)
	gl.Vertex3d(x-0.5, y+0.5, z+0.5)
	gl.TexCoord2f(0, 1)
	gl.Vertex3d(x-0.5, y+0.5, z-0.5)

	gl.End()
}
Esempio n. 2
0
func DrawEntity(en Entity) {

	x := en.Xpos
	y := en.Ypos
	r := en.Rot
	s := en.Size
	col := en.Colour

	switch col {
	case "grey":
		gl.Color3d(0.5, 0.5, 0.5)
	case "red":
		gl.Color3d(1, 0, 0)
	case "green":
		gl.Color3d(0, 1, 0)
	case "blue":
		gl.Color3d(0, 0, 1)
	case "lblue":
		gl.Color3d(0.3, 0.3, 1)
	case "orange":
		gl.Color3d(1, 0.5, 0)
	case "yellow":
		gl.Color3d(1, 1, 0)
	case "purple":
		gl.Color3d(1, 0, 1)
	case "white":
		gl.Color3d(1, 1, 1)
	default:
		gl.Color3d(1, 1, 1)
	}

	gl.PushMatrix()

	gl.Translated(x, y, 0)
	gl.Scaled(s, s, s)
	//gl.Rotated(r*180/math.Pi, 0, 0, 1)
	gl.Rotated(r, 0, 0, 1)

	enx := [3]float64{-0.7, 0.7, 0}
	eny := [3]float64{1, 1, -1}

	//in OpenGL 3.2, the vertices below would be stored on the GPU
	//so all you would need to do is say DrawShape(A) or something

	gl.Begin(gl.TRIANGLES)
	gl.Vertex3d(enx[0], eny[0], 0)
	gl.Vertex3d(enx[1], eny[1], 0)
	gl.Vertex3d(enx[2], eny[2], 0)
	gl.End()

	gl.PopMatrix()

}
Esempio n. 3
0
// Draws lines of unit length along the X, Y, Z axis in R, G, B
func DrawAxes() {
	gl.Begin(gl.LINES)

	gl.Color3d(1, 0, 0)
	gl.Vertex3d(0, 0, 0)
	gl.Vertex3d(1, 0, 0)

	gl.Color3d(0, 1, 0)
	gl.Vertex3d(0, 0, 0)
	gl.Vertex3d(0, 1, 0)

	gl.Color3d(0, 0, 1)
	gl.Vertex3d(0, 0, 0)
	gl.Vertex3d(0, 0, 1)

	gl.End()
}
Esempio n. 4
0
func DrawSizeableTri(Tr SizeableTri) {
	ax := Tr.Ax
	bx := Tr.Bx
	cx := Tr.Cx

	ay := Tr.Ay
	by := Tr.By
	cy := Tr.Cy

	col := Tr.Colour

	switch col {
	case "grey":
		gl.Color3d(0.5, 0.5, 0.5)
	case "red":
		gl.Color3d(1, 0, 0)
	case "green":
		gl.Color3d(0, 1, 0)
	case "blue":
		gl.Color3d(0, 0, 1)
	case "lblue":
		gl.Color3d(0.3, 0.3, 1)
	case "orange":
		gl.Color3d(1, 0.5, 0)
	case "yellow":
		gl.Color3d(1, 1, 0)
	case "purple":
		gl.Color3d(1, 0, 1)
	default:
		gl.Color3d(1, 1, 1)
	}

	gl.PushMatrix()

	//	gl.Translated(x, y, 0)
	//	gl.Scaled(s, s, s)

	//	gl.Rotated(r, 0, 0, 1)

	gl.Begin(gl.TRIANGLES)
	gl.Vertex3d(ax, ay, 0)
	gl.Vertex3d(bx, by, 0)
	gl.Vertex3d(cx, cy, 0)
	gl.End()

	gl.PopMatrix()

}
Esempio n. 5
0
func DrawRTri(Red float64) {
	gl.ClearColor(0.2, 0.2, 0.2, 1)
	gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)

	gl.Color3d(game.Red, 0, 0)
	gl.Begin(gl.TRIANGLES)
	gl.Vertex3d(0, 0, 0)
	gl.Vertex3d(0, 1, 0)
	gl.Vertex3d(1, 1, 0)
	gl.Vertex3d(1, 0, 0)
	gl.End()
}
Esempio n. 6
0
func drawFrame(screenData *Screen) {
	gl.Clear(gl.COLOR_BUFFER_BIT)
	gl.Begin(gl.POINTS)

	for i := 0; i < SCREEN_WIDTH; i++ {
		for j := 0; j < SCREEN_HEIGHT; j++ {
			var pixel Color = screenData[i][j]
			gl.Color3d(pixel.Red, pixel.Green, pixel.Blue)
			gl.Vertex2i(i, j)
		}
	}
	gl.End()
}
Esempio n. 7
0
func (explosion *Explosion) Draw() {
	if explosion.IsAlive() {
		for l, _ := range explosion.Lines {
			gl.Begin(gl.LINES)

			for v, _ := range explosion.Lines[l].Shape.Vectors {
				gl.Color3d(explosion.Lines[l].Shape.Colors[v].R, explosion.Lines[l].Shape.Colors[v].G, explosion.Lines[l].Shape.Colors[v].B)
				explosion.Lines[l].GlVertex2d(explosion.Lines[l].Shape.Vectors[v])
			}

			gl.End()
		}
	}
}
Esempio n. 8
0
func (ent *Entity) Draw(invertColors bool) {
	if ent.IsAlive() {
		//gl.LoadIdentity()
		gl.Begin(gl.POLYGON)

		for v := range ent.Shape.Vectors {
			if invertColors {
				ent.Color3d(ent.Shape.Colors[v])
			} else {
				gl.Color3d(ent.Shape.Colors[v].R, ent.Shape.Colors[v].G, ent.Shape.Colors[v].B)
			}
			ent.GlVertex2d(ent.Shape.Vectors[v])
		}

		gl.End()
	}
}
Esempio n. 9
0
// Used in classic render mode.
// Defines vertex colors.
func (a *Attr) color(i int) {
	i *= a.size

	switch a.size {
	case 3:
		switch v := a.data.(type) {
		case []int8:
			gl.Color3b(v[i], v[i+1], v[i+2])
		case []uint8:
			gl.Color3ub(v[i], v[i+1], v[i+2])
		case []int16:
			gl.Color3s(v[i], v[i+1], v[i+2])
		case []int32:
			gl.Color3i(int(v[i]), int(v[i+1]), int(v[i+2]))
		case []float32:
			gl.Color3f(v[i], v[i+1], v[i+2])
		case []float64:
			gl.Color3d(v[i], v[i+1], v[i+2])
		}
	case 4:
		switch v := a.data.(type) {
		case []int8:
			gl.Color4b(v[i], v[i+1], v[i+2], v[i+3])
		case []uint8:
			gl.Color4ub(v[i], v[i+1], v[i+2], v[i+3])
		case []int16:
			gl.Color4s(v[i], v[i+1], v[i+2], v[i+3])
		case []int32:
			gl.Color4i(int(v[i]), int(v[i+1]), int(v[i+2]), int(v[i+3]))
		case []float32:
			gl.Color4f(v[i], v[i+1], v[i+2], v[i+3])
		case []float64:
			gl.Color4d(v[i], v[i+1], v[i+2], v[i+3])
		}
	}
}
Esempio n. 10
0
func (ent *Entity) Color3d(c Color) {
	gl.Color3d(Colorize(c.R), Colorize(c.G), Colorize(c.B))
}
Esempio n. 11
0
// this is silly, but oh well.. ;)
func drawCharacter(x, y, size float64, color Color, char string) {
	//gl.LoadIdentity()
	gl.Begin(gl.LINES)

	gl.Color3d(Colorize(color.R), Colorize(color.G), Colorize(color.B))

	c := Char{x, y, size}
	switch char {
	case "0":
		c.glVertex2d(0, 0)
		c.glVertex2d(0, 8)
		c.glVertex2d(0, 8)
		c.glVertex2d(4, 8)
		c.glVertex2d(4, 8)
		c.glVertex2d(4, 0)
		c.glVertex2d(4, 0)
		c.glVertex2d(0, 0)
		c.glVertex2d(2, 4)
		c.glVertex2d(2, 5)
	case "1":
		c.glVertex2d(2, 0)
		c.glVertex2d(2, 8)
		c.glVertex2d(2, 8)
		c.glVertex2d(0, 6)
	case "2":
		c.glVertex2d(0, 8)
		c.glVertex2d(4, 8)
		c.glVertex2d(4, 8)
		c.glVertex2d(4, 4)
		c.glVertex2d(4, 4)
		c.glVertex2d(0, 4)
		c.glVertex2d(0, 4)
		c.glVertex2d(0, 0)
		c.glVertex2d(0, 0)
		c.glVertex2d(4, 0)
	case "3":
		c.glVertex2d(4, 0)
		c.glVertex2d(4, 8)
		c.glVertex2d(0, 8)
		c.glVertex2d(4, 8)
		c.glVertex2d(0, 4)
		c.glVertex2d(4, 4)
		c.glVertex2d(0, 0)
		c.glVertex2d(4, 0)
	case "4":
		c.glVertex2d(0, 8)
		c.glVertex2d(0, 4)
		c.glVertex2d(0, 4)
		c.glVertex2d(4, 4)
		c.glVertex2d(4, 8)
		c.glVertex2d(4, 0)
	case "6":
		c.glVertex2d(0, 8)
		c.glVertex2d(0, 0)
		c.glVertex2d(0, 0)
		c.glVertex2d(4, 0)
		c.glVertex2d(4, 0)
		c.glVertex2d(4, 4)
		c.glVertex2d(4, 4)
		c.glVertex2d(0, 4)
	case "7":
		c.glVertex2d(0, 8)
		c.glVertex2d(4, 8)
		c.glVertex2d(4, 8)
		c.glVertex2d(4, 0)
	case "8":
		c.glVertex2d(0, 0)
		c.glVertex2d(0, 8)
		c.glVertex2d(0, 8)
		c.glVertex2d(4, 8)
		c.glVertex2d(4, 8)
		c.glVertex2d(4, 0)
		c.glVertex2d(4, 0)
		c.glVertex2d(0, 0)
		c.glVertex2d(0, 4)
		c.glVertex2d(4, 4)
	case "9":
		c.glVertex2d(0, 8)
		c.glVertex2d(4, 8)
		c.glVertex2d(4, 8)
		c.glVertex2d(4, 0)
		c.glVertex2d(0, 8)
		c.glVertex2d(0, 4)
		c.glVertex2d(0, 4)
		c.glVertex2d(4, 4)
	case "A":
		c.glVertex2d(0, 0)
		c.glVertex2d(0, 8)
		c.glVertex2d(0, 8)
		c.glVertex2d(4, 8)
		c.glVertex2d(4, 8)
		c.glVertex2d(4, 0)
		c.glVertex2d(0, 4)
		c.glVertex2d(4, 4)
	case "C":
		c.glVertex2d(4, 8)
		c.glVertex2d(0, 8)
		c.glVertex2d(0, 8)
		c.glVertex2d(0, 0)
		c.glVertex2d(0, 0)
		c.glVertex2d(4, 0)
	case "D":
		c.glVertex2d(0, 0)
		c.glVertex2d(0, 8)
		c.glVertex2d(0, 0)
		c.glVertex2d(3, 0)
		c.glVertex2d(3, 0)
		c.glVertex2d(4, 2)
		c.glVertex2d(4, 2)
		c.glVertex2d(4, 6)
		c.glVertex2d(4, 6)
		c.glVertex2d(3, 8)
		c.glVertex2d(3, 8)
		c.glVertex2d(0, 8)
	case "E":
		c.glVertex2d(0, 0)
		c.glVertex2d(0, 8)
		c.glVertex2d(0, 8)
		c.glVertex2d(4, 8)
		c.glVertex2d(0, 4)
		c.glVertex2d(3, 4)
		c.glVertex2d(0, 0)
		c.glVertex2d(4, 0)
	case "F":
		c.glVertex2d(0, 0)
		c.glVertex2d(0, 8)
		c.glVertex2d(0, 8)
		c.glVertex2d(4, 8)
		c.glVertex2d(0, 4)
		c.glVertex2d(3, 4)
	case "G":
		c.glVertex2d(4, 8)
		c.glVertex2d(0, 8)
		c.glVertex2d(0, 8)
		c.glVertex2d(0, 0)
		c.glVertex2d(0, 0)
		c.glVertex2d(4, 0)
		c.glVertex2d(4, 0)
		c.glVertex2d(4, 4)
		c.glVertex2d(4, 4)
		c.glVertex2d(2, 4)
	case "H":
		c.glVertex2d(0, 0)
		c.glVertex2d(0, 8)
		c.glVertex2d(4, 8)
		c.glVertex2d(4, 0)
		c.glVertex2d(0, 4)
		c.glVertex2d(4, 4)
	case "I":
		c.glVertex2d(2, 0)
		c.glVertex2d(2, 8)
	case "L":
		c.glVertex2d(0, 8)
		c.glVertex2d(0, 0)
		c.glVertex2d(0, 0)
		c.glVertex2d(4, 0)
	case "M":
		c.glVertex2d(0, 0)
		c.glVertex2d(0, 8)
		c.glVertex2d(0, 8)
		c.glVertex2d(2, 5)
		c.glVertex2d(2, 5)
		c.glVertex2d(4, 8)
		c.glVertex2d(4, 8)
		c.glVertex2d(4, 0)
	case "N":
		c.glVertex2d(0, 0)
		c.glVertex2d(0, 8)
		c.glVertex2d(0, 8)
		c.glVertex2d(4, 0)
		c.glVertex2d(4, 0)
		c.glVertex2d(4, 8)
	case "O":
		c.glVertex2d(0, 0)
		c.glVertex2d(0, 8)
		c.glVertex2d(0, 8)
		c.glVertex2d(4, 8)
		c.glVertex2d(4, 8)
		c.glVertex2d(4, 0)
		c.glVertex2d(4, 0)
		c.glVertex2d(0, 0)
	case "P":
		c.glVertex2d(0, 0)
		c.glVertex2d(0, 8)
		c.glVertex2d(0, 8)
		c.glVertex2d(4, 8)
		c.glVertex2d(4, 8)
		c.glVertex2d(4, 4)
		c.glVertex2d(4, 4)
		c.glVertex2d(0, 4)
	case "R":
		c.glVertex2d(0, 0)
		c.glVertex2d(0, 8)
		c.glVertex2d(0, 8)
		c.glVertex2d(4, 8)
		c.glVertex2d(4, 8)
		c.glVertex2d(4, 4)
		c.glVertex2d(4, 4)
		c.glVertex2d(0, 4)
		c.glVertex2d(2, 4)
		c.glVertex2d(4, 0)
	case "S", "5":
		c.glVertex2d(4, 8)
		c.glVertex2d(0, 8)
		c.glVertex2d(0, 8)
		c.glVertex2d(0, 4)
		c.glVertex2d(0, 4)
		c.glVertex2d(4, 4)
		c.glVertex2d(4, 4)
		c.glVertex2d(4, 0)
		c.glVertex2d(4, 0)
		c.glVertex2d(0, 0)
	case "T":
		c.glVertex2d(0, 8)
		c.glVertex2d(4, 8)
		c.glVertex2d(2, 8)
		c.glVertex2d(2, 0)
	case "U":
		c.glVertex2d(0, 0)
		c.glVertex2d(0, 8)
		c.glVertex2d(0, 0)
		c.glVertex2d(4, 0)
		c.glVertex2d(4, 0)
		c.glVertex2d(4, 8)
	case "V":
		c.glVertex2d(0, 8)
		c.glVertex2d(2, 0)
		c.glVertex2d(2, 0)
		c.glVertex2d(4, 8)
	case "W":
		c.glVertex2d(0, 8)
		c.glVertex2d(1, 0)
		c.glVertex2d(1, 0)
		c.glVertex2d(2, 3)
		c.glVertex2d(2, 3)
		c.glVertex2d(3, 0)
		c.glVertex2d(3, 0)
		c.glVertex2d(4, 8)
	case "X":
		c.glVertex2d(0, 8)
		c.glVertex2d(4, 0)
		c.glVertex2d(0, 0)
		c.glVertex2d(4, 8)
	case "Y":
		c.glVertex2d(0, 8)
		c.glVertex2d(2, 4)
		c.glVertex2d(2, 4)
		c.glVertex2d(4, 8)
		c.glVertex2d(2, 4)
		c.glVertex2d(2, 0)
	case " ":
	case "-":
		c.glVertex2d(1, 4)
		c.glVertex2d(3, 4)
	case ":":
		c.glVertex2d(1, 2)
		c.glVertex2d(1, 3)
		c.glVertex2d(1, 5)
		c.glVertex2d(1, 6)
	case "!":
		c.glVertex2d(1, 0)
		c.glVertex2d(1, 1)
		c.glVertex2d(1, 3)
		c.glVertex2d(1, 8)

	}

	gl.End()
}
Esempio n. 12
0
func DrawLine(Ln Line) {

	ax := Ln.Ax
	ay := Ln.Ay

	bx := Ln.Bx
	by := Ln.By

	col := Ln.Colour

	switch col {
	case "grey":
		gl.Color3d(0.5, 0.5, 0.5)
	case "red":
		gl.Color3d(1, 0, 0)
	case "green":
		gl.Color3d(0, 1, 0)
	case "blue":
		gl.Color3d(0, 0, 1)
	case "lblue":
		gl.Color3d(0.3, 0.3, 1)
	case "orange":
		gl.Color3d(1, 0.5, 0)
	case "yellow":
		gl.Color3d(1, 1, 0)
	case "purple":
		gl.Color3d(1, 0, 1)
	default:
		gl.Color3d(1, 1, 1)
	}
	if ay != by {
		gl.PushMatrix()
		gl.Begin(gl.TRIANGLES)
		gl.Vertex3d(ax-0.2, ay, 0)
		gl.Vertex3d(ax+0.2, ay, 0)
		gl.Vertex3d(ax-0.2, by, 0)
		gl.End()
		gl.PopMatrix()

		gl.PushMatrix()
		gl.Begin(gl.TRIANGLES)
		gl.Vertex3d(ax+0.2, ay, 0)
		gl.Vertex3d(ax+0.2, by, 0)
		gl.Vertex3d(ax-0.2, by, 0)
		gl.End()
		gl.PopMatrix()
	} else {

		gl.PushMatrix()
		gl.Begin(gl.TRIANGLES)
		gl.Vertex3d(ax, ay+0.2, 0)
		gl.Vertex3d(bx, by+0.2, 0)
		gl.Vertex3d(bx, by-0.2, 0)
		gl.End()
		gl.PopMatrix()

		gl.PushMatrix()
		gl.Begin(gl.TRIANGLES)
		gl.Vertex3d(ax, ay+0.2, 0)
		gl.Vertex3d(ax, ay-0.2, 0)
		gl.Vertex3d(bx, by-0.2, 0)
		gl.End()
		gl.PopMatrix()

	}

}