Example #1
0
func (sp *SpawnPoint) Render(pos mathgl.Vec2, width float32) {
	gl.Disable(gl.TEXTURE_2D)
	gl.Color4d(1, 1, 1, 0.1)
	gl.Begin(gl.QUADS)
	gl.Vertex2f(pos.X-width/2, pos.Y)
	gl.Vertex2f(pos.X-width/2, pos.Y+width)
	gl.Vertex2f(pos.X+width/2, pos.Y+width)
	gl.Vertex2f(pos.X+width/2, pos.Y)
	gl.End()
}
Example #2
0
func drawGrid() {
	gl.Color4f(0.2, 0.2, 0.2, 1)
	gl.Begin(gl.LINES)
	for i := -0.5; i < Width; i += 1 {
		gl.Vertex2f(gl.Float(-0.5), gl.Float(i))
		gl.Vertex2f(gl.Float(life.Size), gl.Float(i))

		gl.Vertex2f(gl.Float(i), -0.5)
		gl.Vertex2f(gl.Float(i), gl.Float(life.Size))
	}
	gl.End()
}
Example #3
0
func Ellipse(rX, rY gl.Float, slices int, solid bool) {
	mode := gl.LINE_LOOP
	if solid {
		mode = gl.POLYGON
	}
	res := 2 * math.Pi / float64(slices)
	gl.Begin(gl.Enum(mode))
	gl.Vertex2f(0, 0)
	for a := 0.0; a < 2*math.Pi; a += res {
		gl.Vertex2f(rX*gl.Float(math.Cos(a)), rY*gl.Float(math.Sin(a)))
	}
	gl.End()
}
Example #4
0
func drawMatrix(m *[][]Point, xby, yby gl.Float) {
	for x, row := range *m {
		for y, p := range row {
			UseColor(PointColor(p))
			// fmt.Println(p, PointColor(p))
			// gl.Color4f(1, 0, 0, 1)
			gl.Vertex2f(gl.Float(x)*xby, gl.Float(y)*yby)
		}
	}
}
Example #5
0
func DrawStarTex(t *data.Star) {

	// Find the center point of the texture to rotate around
	xav := (t.X1 + t.X2) / 2
	yav := (t.Y1 + t.Y2) / 2

	//Translate there, rotate, translate back
	gl.MatrixMode(gl.MODELVIEW)
	gl.Translatef(xav, yav, 0)
	gl.Rotatef(gl.Float(t.Theta), 0, 0, 1)
	gl.Translatef(-xav, -yav, 0)

	//Bind our texture to be drawn by id
	gl.Color3f(1, 1, 1)
	gl.Enable(gl.TEXTURE_2D)
	gl.BindTexture(gl.TEXTURE_2D, t.TexId)

	// Draw a rectangle with the texture stretched to the corners
	gl.Begin(gl.QUADS)

	// Stretch the texture to its 4 corners.
	gl.TexCoord2d(0, 0)
	gl.Vertex2f(t.X1, t.Y1)

	gl.TexCoord2d(0, 1)
	gl.Vertex2f(t.X1, t.Y2)

	gl.TexCoord2d(1, 1)
	gl.Vertex2f(t.X2, t.Y2)

	gl.TexCoord2d(1, 0)
	gl.Vertex2f(t.X2, t.Y1)

	gl.End()

	// Unbind the texture in case something else wants to draw
	gl.Disable(gl.TEXTURE_2D)

	// Reset the matrix
	gl.LoadIdentity()

}
Example #6
0
func (e *Entity) Render(pos mathgl.Vec2, width float32) {
	var rgba [4]float64
	gl.GetDoublev(gl.CURRENT_COLOR, &rgba[0])
	e.last_render_width = width
	gl.Enable(gl.TEXTURE_2D)
	e.drawReticle(pos, rgba)
	if e.sprite.sp != nil {
		dxi, dyi := e.sprite.sp.Dims()
		dx := float32(dxi)
		dy := float32(dyi)
		tx, ty, tx2, ty2 := e.sprite.sp.Bind()
		gl.Begin(gl.QUADS)
		gl.TexCoord2d(tx, -ty)
		gl.Vertex2f(pos.X, pos.Y)
		gl.TexCoord2d(tx, -ty2)
		gl.Vertex2f(pos.X, pos.Y+dy*width/dx)
		gl.TexCoord2d(tx2, -ty2)
		gl.Vertex2f(pos.X+width, pos.Y+dy*width/dx)
		gl.TexCoord2d(tx2, -ty)
		gl.Vertex2f(pos.X+width, pos.Y)
		gl.End()
	}
}
Example #7
0
// draw draws the triangle.
func draw() {
	gl.ClearColor(0.3, 0.3, 0.3, 0.0)
	gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)

	gl.ShadeModel(gl.SMOOTH)

	gl.LoadIdentity()
	gl.Translatef(-15.0, -15.0, 0.0)

	gl.Begin(gl.TRIANGLES)

	gl.Color3f(1.0, 0.0, 0.0)
	gl.Vertex2f(0.0, 0.0)

	gl.Color3f(0.0, 1.0, 0.0)
	gl.Vertex2f(30.0, 0.0)

	gl.Color3f(0.0, 0.0, 1.0)
	gl.Vertex2f(0.0, 30.0)

	gl.End()

	win.SwapBuffers()
}
Example #8
0
func drawCells() {

	if input.Zoom > 0 {
		gl.PointSize(gl.Float(float64(Width) / float64(*flagSize) * input.Zoom))
	}

	gl.Color4f(1, 1, 1, 1)
	gl.Enable(gl.POINT_SMOOTH)
	gl.Begin(gl.POINTS)

	for i, j := 0, 0; i < (life.Size * life.Size); i, j = i+life.Size, j+1 {
		for k, v := range life.Cells[i : i+life.Size] {
			if v {
				gl.Vertex2f(gl.Float(k), gl.Float(j))
			}
		}
	}

	gl.End()
	gl.Disable(gl.POINT_SMOOTH)
}