예제 #1
0
파일: voronoi.go 프로젝트: glenn-brown/vu
func (v *Voronoi) Render(w, h, d float64) {
	gl.PushMatrix()
	gl.Scaled(w, h, 1)

	rng := rand.New(rand.NewSource(42))
	rng.Seed(42)

	// Draw fill colors

	for _, wall := range v.cellWalls {
		gl.Color3ub(
			uint8(100+rng.Int31n(128)),
			uint8(100+rng.Int31n(128)),
			uint8(100+rng.Int31n(128)))
		gl.Begin(gl.TRIANGLE_FAN)
		for _, p := range wall {
			if p != nil && boundedPoint(p) {
				gl.Vertex2d(p.X, p.Y)
			}
		}
		gl.End()
	}

	// Draw lines

	gl.LineWidth(1.5)
	gl.Color3ub(0, 128, 0)
	gl.Begin(gl.LINES)
	for _, edge := range v.edges {
		if boundedEdge(edge) {
			gl.Vertex2d(edge.Start.X, edge.Start.Y)
			gl.Vertex2d(edge.End.X, edge.End.Y)
		}
	}
	gl.End()

	// Draw points.

	gl.PointSize(2)
	gl.Color3ub(255, 255, 255)
	gl.Begin(gl.POINTS)
	for _, point := range v.points {
		gl.Vertex2d(point.X, point.Y)
	}
	gl.End()
	gl.PopMatrix()
}
예제 #2
0
파일: gotris.go 프로젝트: nsf/gotris
func (self *GameSession) drawPlaying() {
	self.Field.Draw(self.cx, self.cy)
	self.Figure.Draw(self.cx, self.cy)

	gl.Color3ub(255, 255, 255)
	self.font.Draw(self.cx+self.Field.PixelsWidth()+50, self.cy+5, "Next:")
	self.NextFigure.Draw(self.cx+self.Field.PixelsWidth(), self.cy+50)
}
예제 #3
0
파일: gotris.go 프로젝트: nsf/gotris
func drawBlock(x, y int, color TetrisBlockColor) {
	glx := gl.GLint(x)
	gly := gl.GLint(y)

	gl.Color3ub(color.R/2, color.G/2, color.B/2)
	gl.Begin(gl.QUADS)
	gl.Vertex2i(int(glx), int(gly))
	gl.Vertex2i(int(glx+blockSize), int(gly))
	gl.Vertex2i(int(glx+blockSize), int(gly+blockSize))
	gl.Vertex2i(int(glx), int(gly+blockSize))
	gl.Color3ub(color.R, color.G, color.B)
	gl.Vertex2i(int(glx+smallBlockOffset), int(gly+smallBlockOffset))
	gl.Vertex2i(int(glx+blockSize-smallBlockOffset), int(gly+smallBlockOffset))
	gl.Vertex2i(int(glx+blockSize-smallBlockOffset), int(gly+blockSize-smallBlockOffset))
	gl.Vertex2i(int(glx+smallBlockOffset), int(gly+blockSize-smallBlockOffset))
	gl.End()
}
예제 #4
0
파일: window.go 프로젝트: glenn-brown/vu
// Draw unit vectors at the origin.
// The X vector is red, Y is green, and Z is blue.
func drawOrigin() {
	gl.Color3ub(0xff, 0, 0)
	gl.Begin(gl.LINES)
	gl.Vertex3d(0, 0, 0)
	gl.Vertex3d(1, 0, 0)
	gl.End()

	gl.Color3ub(0, 0xff, 0)
	gl.Begin(gl.LINES)
	gl.Vertex3d(0, 0, 0)
	gl.Vertex3d(0, 1, 0)
	gl.End()

	gl.Color3ub(0, 0, 0xff)
	gl.Begin(gl.LINES)
	gl.Vertex3d(0, 0, 0)
	gl.Vertex3d(0, 0, 1)
	gl.End()
}
예제 #5
0
파일: gomandel.go 프로젝트: nkostelnik/gl
func drawSelection(p1, p2 Point) {
	min, max := minMaxPoints(p1, p2)

	gl.Color3ub(255, 0, 0)
	gl.Begin(gl.LINES)
	gl.Vertex2i(int(min.X), int(min.Y))
	gl.Vertex2i(int(max.X), int(min.Y))

	gl.Vertex2i(int(min.X), int(min.Y))
	gl.Vertex2i(int(min.X), int(max.Y))

	gl.Vertex2i(int(max.X), int(max.Y))
	gl.Vertex2i(int(max.X), int(min.Y))

	gl.Vertex2i(int(max.X), int(max.Y))
	gl.Vertex2i(int(min.X), int(max.Y))
	gl.End()
	gl.Color3ub(255, 255, 255)
}
예제 #6
0
파일: world.go 프로젝트: glenn-brown/aima
func (world *World) Render(w, h, d float64) {
	gl.PushMatrix()
	gl.Scaled(w, h, d)

	// Draw the goal
	gl.Begin(gl.POINTS)
	gl.Color3ub(255, 0, 0)
	gl.PointSize(6)
	gl.Vertex2d(world.goal.X, world.goal.Y)
	gl.End()

	// Draw the obstacles
	gl.Color4ub(0, 0, 255, 63)
	world.obstacles.Render()

	// Draw the percept
	gl.Color4ub(0, 255, 0, 127)
	gl.LineWidth(1.5)
	gl.Begin(gl.LINES)
	for _, pt := range world.percept {
		gl.Vertex2d(world.robot.X, world.robot.Y)
		gl.Vertex2d(world.robot.X+pt.X, world.robot.Y+pt.Y)
	}
	gl.End()

	// Draw the map
	gl.Color3ub(0, 0, 255)
	gl.LineWidth(2)
	// FIXME

	// Draw the robot
	gl.Color3ub(0, 255, 0)
	gl.PointSize(4)
	gl.Begin(gl.POINTS)
	gl.Vertex2d(world.robot.X, world.robot.Y)
	gl.End()

	gl.PopMatrix()
}
예제 #7
0
파일: gomandel.go 프로젝트: nkostelnik/gl
func drawProgress(w, h, percents, pending int) {
	switch pending {
	case None:
		gl.Color3ub(200, 0, 0)
		drawQuad(0, h-BarSize, w, BarSize, 0, 0, 1, 1)
		gl.Color3ub(255, 255, 255)
		return
	case Small:
		gl.Color3ub(200, 200, 0)
	case Big:
		gl.Color3ub(200, 200, 0)
		drawQuad(0, h-BarSize, w, BarSize, 0, 0, 1, 1)
		gl.Color3ub(200, 0, 0)
	}
	step := float32(w) / 100
	drawQuad(0, h-BarSize, int(float32(percents)*step), BarSize, 0, 0, 1, 1)
	gl.Color3ub(255, 255, 255)
}
예제 #8
0
파일: gotris.go 프로젝트: nsf/gotris
func main() {
	runtime.LockOSThread()
	flag.Parse()
	sdl.Init(sdl.INIT_VIDEO)
	defer sdl.Quit()

	sdl.GL_SetAttribute(sdl.GL_SWAP_CONTROL, 1)

	if sdl.SetVideoMode(640, 480, 32, sdl.OPENGL) == nil {
		panic("sdl error")
	}

	sdl.WM_SetCaption("Gotris", "Gotris")
	sdl.EnableKeyRepeat(250, 45)

	gl.Enable(gl.TEXTURE_2D)
	gl.Enable(gl.BLEND)
	gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)
	gl.Viewport(0, 0, 640, 480)
	gl.MatrixMode(gl.PROJECTION)
	gl.LoadIdentity()
	gl.Ortho(0, 640, 480, 0, -1, 1)

	gl.ClearColor(0, 0, 0, 0)

	//-----------------------------------------------------------------------------

	font, err := LoadFontFromFile("dejavu.font")
	if err != nil {
		panic(err)
	}

	rand.Seed(int64(sdl.GetTicks()))

	gs := NewGameSession(*initLevel, font)
	lastTime := sdl.GetTicks()
	ticker := time.NewTicker(10 * time.Millisecond)

	stop := make(chan byte, 1)
	go func() {
		for {
			switch e := (<-sdl.Events).(type) {
			case sdl.QuitEvent:
				stop <- 0
			case sdl.KeyboardEvent:
				if e.Type == sdl.KEYDOWN {
					running := gs.HandleKey(e.Keysym.Sym)
					if !running {
						stop <- 0
					}
					gs.update <- 0
				}
			}
		}
	}()
loop:
	for {
		select {
		case <-ticker.C:
			gs.update <- 0

		case <-gs.update:
			now := sdl.GetTicks()
			delta := now - lastTime
			lastTime = now

			gs.Update(delta)

			gl.Clear(gl.COLOR_BUFFER_BIT)
			font.Draw(5, 5, fmt.Sprintf("Level: %d | Score: %d", gs.Level, gs.Score))
			gs.Draw()
			gl.Color3ub(255, 255, 255)
			sdl.GL_SwapBuffers()

		case <-stop:
			break loop
		}
	}
}
예제 #9
0
파일: gotris.go 프로젝트: nsf/gotris
func (self *GameSession) drawGamePaused() {
	self.drawPlaying()
	gl.Color3ub(200, 200, 0)
	self.font.Draw(self.pauseCx, 5, "Game paused, press P to resume")
}
예제 #10
0
파일: gotris.go 프로젝트: nsf/gotris
func (self *GameSession) drawGameOver() {
	self.drawPlaying()
	gl.Color3ub(200, 0, 0)
	self.font.Draw(self.gameOverCx, 5, "Game Over, restart? y/n")
}
예제 #11
0
파일: scatter.go 프로젝트: glenn-brown/vu
func (s *Scatter) Render(w, h, d float64) {
	gl.PushMatrix()
	min, max := s.points.Bounds()
	dim := max.Sub(min)
	gl.Scaled(w/dim.X, h/dim.Y, d/dim.Z)
	gl.Translated(-min.X, -min.Y, -min.Z)

	// Draw axes: red X, green Y, blue Z.

	gl.Begin(gl.LINES)
	gl.LineWidth(1.5)
	gl.Color3ub(255, 0, 0)
	gl.Vertex3d(min.X, min.Y, min.Z)
	gl.Vertex3d(max.X, min.Y, min.Z)
	gl.Color3ub(0, 255, 0)
	gl.Vertex3d(min.X, min.Y, min.Z)
	gl.Vertex3d(min.X, max.Y, min.Z)
	gl.Color3ub(0, 0, 255)
	gl.Vertex3d(min.X, min.Y, min.Z)
	gl.Vertex3d(min.X, min.Y, max.Z)
	gl.End()

	// Draw 2d plots on the XY, YZ, and XZ planes.

	gl.PointSize(10.0)
	gl.Begin(gl.POINTS)

	// X plot
	gl.Color4ub(255, 0, 0, 31)
	for _, p := range s.points {
		gl.Vertex3d(p.X, min.Y, min.Z)
	}
	// Y plot
	gl.Color4ub(0, 255, 0, 31)
	for _, p := range s.points {
		gl.Vertex3d(min.X, p.Y, min.Z)
	}
	// Z plot
	gl.Color4ub(0, 0, 255, 31)
	for _, p := range s.points {
		gl.Vertex3d(min.X, min.Y, p.Z)
	}

	// XY plot
	gl.Color4ub(255, 255, 0, 63)
	for _, p := range s.points {
		gl.Vertex3d(p.X, p.Y, min.Z)
	}
	// YZ plot
	gl.Color4ub(0, 255, 255, 63)
	for _, p := range s.points {
		gl.Vertex3d(min.X, p.Y, p.Z)
	}
	// XZ plot
	gl.Color4ub(255, 0, 255, 63)
	for _, p := range s.points {
		gl.Vertex3d(p.X, min.Y, p.Z)
	}

	// XYZ plot
	gl.Color4ub(255, 255, 255, 128)
	for _, p := range s.points {
		gl.Vertex3d(p.X, p.Y, p.Z)
	}
	gl.End()
	gl.PopMatrix()
}
예제 #12
0
func (this *Color24) Gl() {
	gl.Color3ub(this.R, this.G, this.B)
}