Exemple #1
0
func display() {
	gl.Clear(gl.COLOR_BUFFER_BIT)
	bitmap_output(40, 35, "This is written in a GLUT bitmap font.", glut.BITMAP_TIMES_ROMAN_24)
	bitmap_output(30, 210, "More bitmap text is a fixed 9 by 15 font.", glut.BITMAP_9_BY_15)
	bitmap_output(70, 240, "                Helvetica is yet another bitmap font.", glut.BITMAP_HELVETICA_18)

	gl.MatrixMode(gl.PROJECTION)
	gl.PushMatrix()
	gl.LoadIdentity()
	glu.Perspective(40.0, 1.0, 0.1, 20.0)
	gl.MatrixMode(gl.MODELVIEW)
	gl.PushMatrix()
	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)
	stroke_output(-2.5, 1.1, "  This is written in a", glut.STROKE_ROMAN)
	stroke_output(-2.5, 0, " GLUT stroke font.", glut.STROKE_ROMAN)
	stroke_output(-2.5, -1.1, "using 3D perspective.", glut.STROKE_ROMAN)
	gl.PopMatrix()
	gl.MatrixMode(gl.MODELVIEW)
	gl.PopMatrix()
	gl.MatrixMode(gl.PROJECTION)
	gl.PopMatrix()
	gl.MatrixMode(gl.MODELVIEW)
	gl.Flush()
}
Exemple #2
0
// OpenGL draw function & timing
func draw() {
	gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)

	gl.PushMatrix()
	gl.Rotated(view_rotx, 1.0, 0.0, 0.0)
	gl.Rotated(view_roty, 0.0, 1.0, 0.0)
	gl.Rotated(view_rotz, 0.0, 0.0, 1.0)

	gl.PushMatrix()
	gl.Translated(-3.0, -2.0, 0.0)
	gl.Rotated(angle, 0.0, 0.0, 1.0)
	gl.CallList(gear1)
	gl.PopMatrix()

	gl.PushMatrix()
	gl.Translated(3.1, -2.0, 0.0)
	gl.Rotated(-2.0*angle-9.0, 0.0, 0.0, 1.0)
	gl.CallList(gear2)
	gl.PopMatrix()

	gl.PushMatrix()
	gl.Translated(-3.1, 4.2, 0.0)
	gl.Rotated(-2.0*angle-25.0, 0.0, 0.0, 1.0)
	gl.CallList(gear3)
	gl.PopMatrix()

	gl.PopMatrix()
}
Exemple #3
0
func (r *RenderTarget) pushGlStates() {
	gl.PushClientAttrib(gl.CLIENT_ALL_ATTRIB_BITS)
	gl.PushAttrib(gl.ALL_ATTRIB_BITS)
	gl.MatrixMode(gl.MODELVIEW)
	gl.PushMatrix()
	gl.MatrixMode(gl.PROJECTION)
	gl.PushMatrix()
	gl.MatrixMode(gl.TEXTURE)
	gl.PushMatrix()

	r.resetGlStates()
}
Exemple #4
0
func renderSwitchBlocks(s *Switch) {
	// TODO constant
	v := SwitchSize / 2
	x, y := float32(s.X+v), float32(s.Y+v)
	gl.LoadIdentity()
	gl.Translatef(x, y, 0)
	if s.rotate != 0 {
		gl.Rotatef(float32(s.rotate), 0, 0, 1)
	}
	bsf := float32(BlockSize - s.Z)
	padding := float32(BlockPadding)

	var b *Block
	// Render block top left
	b = g.level.blocks[s.line][s.col]
	if !b.Rendered {
		gl.PushMatrix()
		gl.Translatef(-bsf-padding, -bsf-padding, 0)
		renderBlock(b, bsf)
		gl.PopMatrix()
		b.Rendered = true
	}

	// Render block top right
	b = g.level.blocks[s.line][s.col+1]
	if !b.Rendered {
		gl.PushMatrix()
		gl.Translatef(padding, -bsf-padding, 0)
		renderBlock(b, bsf)
		gl.PopMatrix()
		b.Rendered = true
	}

	// Render block bottom right
	b = g.level.blocks[s.line+1][s.col+1]
	if !b.Rendered {
		gl.PushMatrix()
		gl.Translatef(padding, padding, 0)
		renderBlock(b, bsf)
		gl.PopMatrix()
		b.Rendered = true
	}

	// render block bottom left
	b = g.level.blocks[s.line+1][s.col]
	if !b.Rendered {
		gl.PushMatrix()
		gl.Translatef(-bsf-padding, padding, 0)
		renderBlock(b, bsf)
		gl.PopMatrix()
		b.Rendered = true
	}
}
Exemple #5
0
func (m *Map) Draw() {

	gl.PushMatrix()
	gl.PushAttrib(gl.CURRENT_BIT | gl.ENABLE_BIT | gl.LIGHTING_BIT | gl.POLYGON_BIT | gl.LINE_BIT)

	gl.EnableClientState(gl.VERTEX_ARRAY)
	gl.VertexPointer(3, gl.FLOAT, 0, m.vertices)

	gl.EnableClientState(gl.NORMAL_ARRAY)
	gl.NormalPointer(gl.FLOAT, 0, m.normals)

	// gl.EnableClientState(gl.TEXTURE_COORD_ARRAY)
	// gl.TexCoordPointer(2, gl.FLOAT, 0, m.texcoords)

	gl.EnableClientState(gl.COLOR_ARRAY)
	gl.ColorPointer(3, gl.FLOAT, 0, m.colors)

	// draw solids
	gl.Enable(gl.COLOR_MATERIAL)
	// gl.DrawArrays(gl.TRIANGLE_STRIP, 0, len(m.vertices)/3)

	gl.PolygonMode(gl.FRONT_AND_BACK, gl.LINE)
	gl.LineWidth(1.0)
	gl.Color4f(1, 1, 1, 1)
	gl.DrawArrays(gl.TRIANGLE_STRIP, 0, len(m.vertices)/3)

	gl.PopAttrib()
	gl.PopMatrix()

}
Exemple #6
0
func main() {

	if !glfw.Init() {
		log.Fatal("glfw failed to initialize")
	}
	defer glfw.Terminate()

	window, err := glfw.CreateWindow(640, 480, "Deformable", nil, nil)
	if err != nil {
		log.Fatal(err.Error())
	}

	window.MakeContextCurrent()
	glfw.SwapInterval(1)
	window.SetMouseButtonCallback(handleMouseButton)
	window.SetKeyCallback(handleKeyDown)
	window.SetInputMode(glfw.Cursor, glfw.CursorHidden)

	gl.Init()
	initGL()

	i := 16
	m = GenerateMap(1600/i, 1200/i, i)
	for running && !window.ShouldClose() {

		x, y := window.GetCursorPosition()

		if drawing != 0 {
			m.Add(int(x)+int(camera[0]), int(y)+int(camera[1]), drawing, brushSizes[currentBrushSize])
		}

		gl.Clear(gl.COLOR_BUFFER_BIT)
		gl.LoadIdentity()

		gl.PushMatrix()
		gl.PushAttrib(gl.CURRENT_BIT | gl.ENABLE_BIT | gl.LIGHTING_BIT | gl.POLYGON_BIT | gl.LINE_BIT)
		gl.Translatef(-camera[0], -camera[1], 0)
		m.Draw()
		gl.PopAttrib()
		gl.PopMatrix()

		gl.PushAttrib(gl.COLOR_BUFFER_BIT)
		gl.LineWidth(2)
		gl.Enable(gl.BLEND)
		gl.BlendFunc(gl.ONE_MINUS_DST_COLOR, gl.ZERO)
		// gl.Enable(gl.LINE_SMOOTH)
		// gl.Hint(gl.LINE_SMOOTH_HINT, gl.NICEST)

		gl.Translatef(float32(x), float32(y), 0)

		gl.EnableClientState(gl.VERTEX_ARRAY)
		gl.VertexPointer(2, gl.DOUBLE, 0, cursorVerts)
		gl.DrawArrays(gl.LINE_LOOP, 0, 24)
		gl.PopAttrib()

		window.SwapBuffers()
		glfw.PollEvents()
	}

}
Exemple #7
0
// OpenGL draw function
func draw() {
	gl.Clear(gl.COLOR_BUFFER_BIT)
	gl.Enable(gl.BLEND)
	gl.Enable(gl.POINT_SMOOTH)
	gl.Enable(gl.LINE_SMOOTH)
	gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)
	gl.LoadIdentity()

	gl.Begin(gl.LINES)
	gl.Color3f(.2, .2, .2)
	for i := range staticLines {
		x := staticLines[i].GetAsSegment().A.X
		y := staticLines[i].GetAsSegment().A.Y
		gl.Vertex3f(float32(x), float32(y), 0)
		x = staticLines[i].GetAsSegment().B.X
		y = staticLines[i].GetAsSegment().B.Y
		gl.Vertex3f(float32(x), float32(y), 0)
	}
	gl.End()

	gl.Color4f(.3, .3, 1, .8)
	// draw balls
	for _, ball := range balls {
		gl.PushMatrix()
		pos := ball.Body.Position()
		rot := ball.Body.Angle() * chipmunk.DegreeConst
		gl.Translatef(float32(pos.X), float32(pos.Y), 0.0)
		gl.Rotatef(float32(rot), 0, 0, 1)
		drawCircle(float64(ballRadius), 60)
		gl.PopMatrix()
	}
}
Exemple #8
0
func runGameLoop(window *glfw.Window) {
	for !window.ShouldClose() {
		// update objects
		updateObjects()

		// hit detection
		hitDetection()

		// ---------------------------------------------------------------
		// draw calls
		gl.Clear(gl.COLOR_BUFFER_BIT)

		drawCurrentScore()
		drawHighScore()

		if isGameWon() {
			drawWinningScreen()
		} else if isGameLost() {
			drawGameOverScreen()
		}

		// draw everything 9 times in a 3x3 grid stitched together for seamless clipping
		for x := -1.0; x < 2.0; x++ {
			for y := -1.0; y < 2.0; y++ {
				gl.MatrixMode(gl.MODELVIEW)
				gl.PushMatrix()
				gl.Translated(gameWidth*x, gameHeight*y, 0)

				drawObjects()

				gl.PopMatrix()
			}
		}

		gl.Flush()
		window.SwapBuffers()
		glfw.PollEvents()

		// switch resolution
		if altEnter {
			window.Destroy()

			fullscreen = !fullscreen
			var err error
			window, err = initWindow()
			if err != nil {
				panic(err)
			}

			altEnter = false

			gl.LineWidth(1)
			if fullscreen {
				gl.LineWidth(2)
			}
		}
	}
}
Exemple #9
0
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)
	for _, ch := range str {
		font.Character(ch)
	}
	gl.PopMatrix()
}
Exemple #10
0
func PlaceObject(compiledPrim gl.List, scale [3]double, translation [3]double, rotation [4]double) {
	// objects are placed and transformed when necessary
	gl.PushMatrix()
	gl.Scaled(scale)
	gl.Translated(translation)
	gl.Rotated(rotation)
	gl.CallList(compiledPrim)
	gl.PopMatrix()
}
Exemple #11
0
func drawPaddle(x float32, y float32) {
	gl.PushMatrix()
	gl.Translatef(float32(x), float32(y), 0)
	gl.Color3f(1.0, 1.0, 1.0)
	gl.Begin(gl.LINE_STRIP)
	gl.Vertex2f(0, -5)
	gl.Vertex2f(0, 5)
	gl.End()
	gl.PopMatrix()
}
Exemple #12
0
func draw() {

	gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)

	gl.PushMatrix()
	gl.Rotated(view_rotx, 1.0, 0.0, 0.0)
	gl.Rotated(view_roty, 0.0, 1.0, 0.0)
	gl.Rotated(view_rotz, 0.0, 0.0, 1.0)

	gl.PushMatrix()
	gl.Translated(-3.0, -2.0, 0.0)
	gl.Rotated(angle, 0.0, 0.0, 1.0)
	gl.CallList(gear1)
	gl.PopMatrix()

	gl.PushMatrix()
	gl.Translated(3.1, -2.0, 0.0)
	gl.Rotated(-2.0*angle-9.0, 0.0, 0.0, 1.0)
	gl.CallList(gear2)
	gl.PopMatrix()

	gl.PushMatrix()
	gl.Translated(-3.1, 4.2, 0.0)
	gl.Rotated(-2.0*angle-25.0, 0.0, 0.0, 1.0)
	gl.CallList(gear3)
	gl.PopMatrix()

	gl.PopMatrix()

	sdl.GL_SwapBuffers()

	Frames++
	{
		t := sdl.GetTicks()
		if t-T0 >= 5000 {
			seconds := (t - T0) / 1000.0
			fps := Frames / seconds
			print(Frames, " frames in ", seconds, " seconds = ", fps, " FPS\n")
			T0 = t
			Frames = 0
		}
	}
}
Exemple #13
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()

}
Exemple #14
0
func drawPool(cards [5]DeckCard, x float32) {
	gl.PushMatrix()
	gl.Translatef(x, 590-CardHeight, 0)

	for i, card := range cards {
		if i > 0 {
			gl.Translatef(0, -(CardHeight + 5), 0)
		}

		card.Draw()
	}
	gl.PopMatrix()
}
Exemple #15
0
// Draws a cross on the screen with known lengths, useful for understanding
// screen dimensions
func DebugLines() {
	gl.MatrixMode(gl.PROJECTION)
	gl.PushMatrix()
	//gl.LoadIdentity()
	//gl.Ortho(-2.1, 6.1, -4, 8, 1, -1)
	gl.MatrixMode(gl.MODELVIEW)
	gl.PushMatrix()
	gl.LoadIdentity()

	gl.LoadIdentity()
	gl.LineWidth(5)
	gl.Color4f(1, 1, 0, 1)
	gl.Begin(gl.LINES)
	gl.Vertex2d(0, -1.6)
	gl.Vertex2d(0, 0.8)
	gl.Vertex2d(-0.8, 0)
	gl.Vertex2d(0.8, 0)
	gl.End()
	gl.PopMatrix()

	gl.MatrixMode(gl.PROJECTION)
	gl.PopMatrix()
	gl.MatrixMode(gl.MODELVIEW)
}
Exemple #16
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()

}
Exemple #17
0
func (m HexMap) Render() {
	for x := 0; x < 11; x++ {
		maxy := 8
		if x%2 == 1 {
			maxy = 9
		}
		for y := 0; y < maxy; y++ {
			if m[x][y].State != StateNormal {
				continue
			}
			gl.PushMatrix()
			posX, posY := m.GetTopLeft(x, y).WithOffset()
			gl.Translatef(float32(posX), float32(posY), 0)
			m[x][y].Render(1, false)
			gl.PopMatrix()
		}
	}
}
Exemple #18
0
func (p *Playfield) Draw() {
	drawPool(p.playerCards, 10)
	drawPool(p.opponentCards, 790-CardWidth)

	// draw the slots
	gl.PushMatrix()
	gl.Translatef(CardWidth+60, 580-CardHeight, 0)
	for i, slot := range p.slots {
		if i > 0 {
			gl.Translatef(CardWidth+2, 0, 0)
			if i%4 == 0 {
				gl.Translatef(-((CardWidth + 2) * 4), -(CardHeight + 2), 0)
			}
		}
		slot.card.Draw()
	}
	gl.PopMatrix()
}
Exemple #19
0
func drawBall(angle float32, ball_x float32, ball_y float32) {
	gl.PushMatrix()
	gl.Color3f(1, 1, 1)
	gl.Translatef(ball_x, ball_y, 0.0)
	gl.Begin(gl.LINE_LOOP)
	for rad := 0.0; rad < 1.0; rad += 0.01 {
		gl.Vertex2f(
			float32(2.0*math.Cos(2.0*math.Pi*rad)),
			float32(2.0*math.Sin(2.0*math.Pi*rad)+0.2))
	}
	gl.End()
	gl.Rotatef(angle, 0.0, 0.0, 1.0)

	gl.Begin(gl.LINE_STRIP)
	gl.Vertex2f(0, 0)
	gl.Vertex2f(2, 0)
	gl.End()

	gl.PopMatrix()
}
Exemple #20
0
func drawBlock(loc Loc, b *Block) {
	// Save current modelview matrix on to the stack
	gl.PushMatrix()
	// Move block
	gl.Translatef(loc.X, loc.Y, loc.Z)
	// Rotate block
	gl.Rotatef(b.Pitch, 1, 0, 0)
	gl.Rotatef(b.Yaw, 0, 1, 0)
	gl.Rotatef(b.Roll, 0, 0, 1)
	// Start specifying the vertices of quads.
	gl.Begin(gl.QUADS)
	for _, quad := range b.Quads {
		gl.Color3fv(quad.Color)
		for _, vertex := range quad.Vertices {
			gl.Vertex3fv(b.Vertices[vertex])
		}
	}
	gl.End()
	// Restore old modelview matrix
	gl.PopMatrix()
}
Exemple #21
0
func (f *AnimateFall) AnimateAndExecute() {
	if len(f.FallHex) == 0 {
		return
	}
	stillFalling := 0
	for _, hex := range f.FallHex {
		gl.PushMatrix()
		x, y := hexMap2.GetTopLeft(hex.Pos.X, hex.Pos.Y).WithOffset()
		displaceY := hex.Accel * math.Pow(f.FallTicks, 2) / 2
		_, tY := hexMap2.GetTopLeft(hex.Pos.X, hex.Target.Y).WithOffset()
		newY := math.Min(y+displaceY, tY)
		gl.Translatef(float32(x), float32(newY), 0)
		hex.Hex.Render(1, false)
		gl.PopMatrix()
		if newY < tY {
			stillFalling++
		}
	}
	f.FallTicks++
	if stillFalling == 0 {
		for _, hex := range f.FallHex {
			hex.Hex.State = StateNormal
		}
		f.FallHex = nil
		f.FallHex = make([]FallHex, 0)
		if hexMap2.CheckCollision() {
			hexShrink.InitAnimation()
			if f.postHook != nil {
				hexShrink.postHook = f.postHook
			}
		} else {
			if f.postHook != nil {
				f.postHook()
			}
		}
	}
}
Exemple #22
0
func drawBorderAtXY(x, y float32, reverse int) {
	if x <= 80 || y <= 80 {
		return
	}
	gl.PushMatrix()
	gl.Translatef(x, y, 0)
	if reverse == 1 {
		gl.Rotatef(60, 0, 0, 1)
	}
	gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)
	gl.TexEnvf(gl.TEXTURE_ENV, gl.TEXTURE_ENV_MODE, gl.REPLACE)
	borderTex.Bind(gl.TEXTURE_2D)
	gl.Begin(gl.QUADS)
	gl.TexCoord2f(0, 0)
	gl.Vertex2i(-38, -38)
	gl.TexCoord2f(0, 1)
	gl.Vertex2i(-38, 38)
	gl.TexCoord2f(1, 1)
	gl.Vertex2i(38, 38)
	gl.TexCoord2f(1, 0)
	gl.Vertex2i(38, -38)
	gl.End()
	gl.PopMatrix()
}
Exemple #23
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()

	}

}
Exemple #24
0
func (m Matrix) Enter() {
	gl.PushAttrib(gl.TRANSFORM_BIT)
	gl.MatrixMode(m.Type)
	gl.PushMatrix()
}
Exemple #25
0
// Printf draws the given string at the specified coordinates.
// It expects the string to be a single line. Line breaks are not
// handled as line breaks and are rendered as glyphs.
//
// In order to render multi-line text, it is up to the caller to split
// the text up into individual lines of adequate length and then call
// this method for each line seperately.
func (f *Font) Printf(x, y float32, fs string, argv ...interface{}) error {
	indices := []rune(fmt.Sprintf(fs, argv...))

	if len(indices) == 0 {
		return nil
	}

	// Runes form display list indices.
	// For this purpose, they need to be offset by -FontConfig.Low
	low := f.Config.Low
	for i := range indices {
		indices[i] -= low
	}

	var vp [4]int32
	gl.GetIntegerv(gl.VIEWPORT, vp[:])

	gl.PushAttrib(gl.TRANSFORM_BIT)
	gl.MatrixMode(gl.PROJECTION)
	gl.PushMatrix()
	gl.LoadIdentity()
	gl.Ortho(float64(vp[0]), float64(vp[2]), float64(vp[1]), float64(vp[3]), 0, 1)
	gl.PopAttrib()

	gl.PushAttrib(gl.LIST_BIT | gl.CURRENT_BIT | gl.ENABLE_BIT | gl.TRANSFORM_BIT)
	{
		gl.MatrixMode(gl.MODELVIEW)
		gl.Disable(gl.LIGHTING)
		gl.Disable(gl.DEPTH_TEST)
		gl.Enable(gl.BLEND)
		gl.Enable(gl.TEXTURE_2D)

		gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)
		gl.TexEnvf(gl.TEXTURE_ENV, gl.TEXTURE_ENV_MODE, gl.MODULATE)
		f.Texture.Bind(gl.TEXTURE_2D)

		var mv [16]float32
		gl.GetFloatv(gl.MODELVIEW_MATRIX, mv[:])

		gl.PushMatrix()
		{
			gl.LoadIdentity()

			mgw := float32(f.maxGlyphWidth)
			mgh := float32(f.maxGlyphHeight)

			switch f.Config.Dir {
			case LeftToRight, TopToBottom:
				gl.Translatef(x, float32(vp[3])-y-mgh, 0)
			case RightToLeft:
				gl.Translatef(x-mgw, float32(vp[3])-y-mgh, 0)
			}

			gl.MultMatrixf(&mv)
			gl.CallLists(len(indices), gl.UNSIGNED_INT, indices)
		}
		gl.PopMatrix()
		f.Texture.Unbind(gl.TEXTURE_2D)
	}
	gl.PopAttrib()

	gl.PushAttrib(gl.TRANSFORM_BIT)
	gl.MatrixMode(gl.PROJECTION)
	gl.PopMatrix()
	gl.PopAttrib()
	return glh.CheckGLError()
}
Exemple #26
0
func renderHexMap() {
	gl.Enable(gl.TEXTURE_2D)
	gl.Enable(gl.BLEND)
	gl.Disable(gl.DEPTH_TEST)
	wallpaper.Bind(gl.TEXTURE_2D)
	gl.TexEnvf(gl.TEXTURE_ENV, gl.TEXTURE_ENV_MODE, gl.REPLACE)
	gl.Begin(gl.QUADS)
	gl.TexCoord2f(0, 0)
	gl.Vertex2i(0, 0)
	gl.TexCoord2f(0, 1)
	gl.Vertex2i(0, 768)
	gl.TexCoord2f(1, 1)
	gl.Vertex2i(1024, 768)
	gl.TexCoord2f(1, 0)
	gl.Vertex2i(1024, 0)
	gl.End()
	gl.TexEnvf(gl.TEXTURE_ENV, gl.TEXTURE_ENV_MODE, gl.DECAL)
	gl.TexEnvf(gl.TEXTURE_ENV, gl.TEXTURE_ENV_MODE, gl.MODULATE)
	gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)
	gl.PushMatrix()
	gl.Translatef(80, 80, 0)
	for x := 0; x < 10; x++ {
		maxy := 8
		topy := 19
		if x%2 == 1 {
			maxy = 9
			topy = 0
		}
		starty := 0
		for y := starty; y < maxy; y++ {
			if currExX > -1 && currExY > -1 && starRotate {
				if y == currExY && x == currExX || y == currExY+1 && x == currExX || y == currExY-1 && x == currExX || currExX%2 == 0 && ((currExX == x-1 || currExX == x+1) && currExY == y-1 || (currExX == x-1 || currExX == x+1) && currExY == y) || currExX%2 == 1 && ((currExX == x-1 || currExX == x+1) && currExY == y || (currExX == x-1 || currExX == x+1) && currExY == y+1) {
					continue
				}
			} else if timesToRotate > 0 {
				// if y == currExY && x == currExX || currExX%2 == 0 && (x == currExX+1 && y == currExY || x == currExX+1 && y == currExY+1) || currExX%2 == 1 && (x == currExX+1 && y == currExY || x == currExX+1 && y == currExY-1) {
				// 	continue
				// }
				found := false
				for _, v := range selectedHex {
					if y == v[1] && x == v[0] {
						found = true
						break
					}
				}
				if found {
					continue
				}
			}
			found := false
			for _, v := range currentMatches {
				if scale > 0 && v[0] == x && v[1] == y || scale <= 0 && v[0] == x && v[1] >= y {
					found = true
					break
				}
			}
			for _, v := range starMatches {
				if starAlpha > 0 && v[0] == x && v[1] == y || starAlpha <= 0 && v[0] == x && v[1] >= y {
					found = true
					break
				}
			}
			if found || len(currStarCenter) > 0 && currStarCenter[0] == x && currStarCenter[1] == y {
				continue
			}
			gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)
			drawHex(x*33, topy+y*38, hexMap[x][y], 1)
		}
	}
	gl.PopMatrix()
	if len(currentMatches) > 0 || len(starMatches) > 0 {
		mouseLock = true
		if len(currentMatches) > 0 && scale > 0 {
			scale -= 0.1
			for _, v := range currentMatches {
				gl.PushMatrix()
				topy := 19
				if v[0]%2 == 1 {
					topy = 0
				}
				gl.Translatef(float32(v[0]*33+102), float32(v[1]*38+topy+94), 0)
				gl.Scalef(scale, scale, 1)
				gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)
				drawHex(-22, -14, hexMap[v[0]][v[1]], 1)
				gl.PopMatrix()
			}
		} else if len(starMatches) > 0 && starAlpha > 0 {
			starAlpha -= 0.05
			// starAlpha = 0.7
			starScale += 0.05
			// starScale = 1.4
			gl.PushMatrix()
			topy := 19
			pm := 0
			if currStarCenter[0]%2 == 1 {
				topy = 0
				pm = -1
			}
			gl.Translatef(float32(currStarCenter[0]*33+102), float32(currStarCenter[1]*38+topy+94), 0)
			drawHex(-22, -14, 6, 1)
			gl.PopMatrix()
			gl.PushMatrix()
			gl.Translatef(float32(currStarCenter[0]*33+102), float32(currStarCenter[1]*38+topy+94), 0)
			gl.Scalef(starScale, starScale, 1)
			drawHex(-22, -14-HEX_HEIGHT, hexMap[currStarCenter[0]][currStarCenter[1]-1], starAlpha)
			drawHex(-22, -20+HEX_HEIGHT, hexMap[currStarCenter[0]][currStarCenter[1]+1], starAlpha)
			drawHex(-52, -36, hexMap[currStarCenter[0]-1][currStarCenter[1]+pm], starAlpha)
			drawHex(-52, -40+HEX_HEIGHT, hexMap[currStarCenter[0]-1][currStarCenter[1]+pm+1], starAlpha)
			drawHex(8, -36, hexMap[currStarCenter[0]+1][currStarCenter[1]+pm], starAlpha)
			drawHex(8, -40+HEX_HEIGHT, hexMap[currStarCenter[0]+1][currStarCenter[1]+pm+1], starAlpha)
			gl.PopMatrix()
		} else {
			if fallticks == 0 {
				animateFall = make([]*freefall, 0)
				for x := 0; x < 10; x++ {
					topy := 19
					if x%2 == 1 {
						topy = 0
					}
					fromy := -1
					for _, v := range currentMatches {
						if v[0] != x {
							continue
						}
						if v[1] > fromy {
							fromy = v[1]
						}
					}
					for _, v := range starMatches {
						if v[0] != x {
							continue
						}
						if v[1] > fromy {
							fromy = v[1]
						}
					}
					if fromy == -1 {
						continue
					}
					for y := fromy; y >= 0; y-- {
						found := false
						for _, v := range currentMatches {
							if v[0] == x && v[1] == y {
								found = true
								break
							}
						}
						for _, v := range starMatches {
							if v[0] == x && v[1] == y {
								found = true
								break
							}
						}
						if found {
							continue
						}
						animateFall = append(animateFall, &freefall{x, y, getFallTargetY(x, y), math.Pow(float64(y), 2)/16 + 0.5})
						gl.PushMatrix()
						gl.Translatef(float32(x*33+102), float32(y*38+topy+94), 0)
						gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)
						drawHex(-22, -14, hexMap[x][y], 1)
						gl.PopMatrix()
					}
				}
				fallticks++
			} else {
				stillFalling := 0
				for _, v := range animateFall {
					topy := 19
					if v.x%2 == 1 {
						topy = 0
					}
					newy := v.accel * math.Pow(float64(fallticks), 2) / 2
					gl.PushMatrix()
					gl.Translatef(float32(v.x*33+102), float32(math.Min(float64(v.y*38+topy+94)+newy, float64(v.targetY*38+topy+94))), 0)
					gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)
					drawHex(-22, -14, hexMap[v.x][v.y], 1)
					gl.PopMatrix()
					if float64(v.y*38+topy+94)+newy < float64(v.targetY*38+topy+94) {
						stillFalling++
					}
				}
				fallticks++
				if stillFalling == 0 {
					starScale = 1
					starAlpha = 0
					removeHexAndGenNew(currentMatches)
					makeStarAndGenNew(starMatches)
					currentMatches = checkHexMap()
					starMatches = checkHexStar()
					currStarCenter = []int{}
					scale = 1
					fallticks = 0
					mouseLock = false
					fmt.Println("Mouse unlocked 1")
					animateFall = nil
				}
			}
		}
	}
	if currExX > -1 && currExY > -1 {
		gl.PushMatrix()
		topy := 19
		if currExX%2 == 1 {
			topy = 0
		}
		if starRotate {
			timesToRotate = 0
			gl.Translatef(float32(currExX*33+102), float32(currExY*38+topy+94), 0)
			gl.Scalef(1.3, 1.3, 1)
			gl.Rotatef(rotate, 0, 0, 1)
			drawHex(-22, -14, 6, 1)
			drawHex(-22, -14-HEX_HEIGHT, hexMap[currExX][currExY-1], 1)
			drawHex(-22, -20+HEX_HEIGHT, hexMap[currExX][currExY+1], 1)
			pm := 0
			if currExX%2 == 1 {
				pm = -1
			}
			drawHex(-52, -36, hexMap[currExX-1][currExY+pm], 1)
			drawHex(-52, -40+HEX_HEIGHT, hexMap[currExX-1][currExY+pm+1], 1)
			drawHex(8, -36, hexMap[currExX+1][currExY+pm], 1)
			drawHex(8, -40+HEX_HEIGHT, hexMap[currExX+1][currExY+pm+1], 1)
		} else {
			// gl.Translatef(float32(currExX*33+HEX_WIDTH+80), float32(currExxY*38+topy+20+80), 0)
			gl.Translatef(float32(prevSelectPos[0]), float32(prevSelectPos[1]), 0)
			gl.Scalef(1.3, 1.3, 1)
			gl.Rotatef(rotate, 0, 0, 1)
			for _, v := range selectedHex {
				switch v[2] {
				case 1:
					drawHex(-32, -34, hexMap[v[0]][v[1]], 1)
				case 2:
					drawHex(0, -17, hexMap[v[0]][v[1]], 1)
				case 3:
					drawHex(-32, 0, hexMap[v[0]][v[1]], 1)
				case 4:
					drawHex(-44, -19, hexMap[v[0]][v[1]], 1)
				case 5:
					drawHex(-12, -36, hexMap[v[0]][v[1]], 1)
				case 6:
					drawHex(-12, -2, hexMap[v[0]][v[1]], 1)
				}
			}
			// if currExX%2 == 0 {
			// 	gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)
			// 	drawHex(-12, -36, hexMap[currExX+1][currExY], 1)
			// } else {
			// 	gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)
			// 	drawHex(-12, -36, hexMap[currExX+1][currExY-1], 1)
			// }
			// gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)
			// drawHex(-44, -19, hexMap[currExX][currExY], 1)
			// if currExX%2 == 0 {
			// 	gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)
			// 	drawHex(-12, -2, hexMap[currExX+1][currExY+1], 1)
			// } else {
			// 	gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)
			// 	drawHex(-12, -2, hexMap[currExX+1][currExY], 1)
			// }
		}
		gl.PopMatrix()
		if !starRotate && rotate < 120 {
			rotate += 15
			// rotate = 15
		} else if starRotate && rotate < 60 {
			rotate += 6
		} else {
			if starRotate {
				if currExX%2 == 0 {
					hexMap[currExX][currExY-1], hexMap[currExX+1][currExY], hexMap[currExX+1][currExY+1], hexMap[currExX][currExY+1], hexMap[currExX-1][currExY+1], hexMap[currExX-1][currExY] = hexMap[currExX-1][currExY], hexMap[currExX][currExY-1], hexMap[currExX+1][currExY], hexMap[currExX+1][currExY+1], hexMap[currExX][currExY+1], hexMap[currExX-1][currExY+1]
				} else {
					hexMap[currExX][currExY-1], hexMap[currExX+1][currExY-1], hexMap[currExX+1][currExY], hexMap[currExX][currExY+1], hexMap[currExX-1][currExY], hexMap[currExX-1][currExY-1] = hexMap[currExX-1][currExY-1], hexMap[currExX][currExY-1], hexMap[currExX+1][currExY-1], hexMap[currExX+1][currExY], hexMap[currExX][currExY+1], hexMap[currExX-1][currExY]
				}
			} else {
				v2 := make([][]int, 3)
				for _, v := range selectedHex {
					idx := 0
					switch v[2] {
					case 1, 4:
						idx = 0
					case 2, 5:
						idx = 1
					case 3, 6:
						idx = 2
					}
					v2[idx] = []int{v[0], v[1]}
					fmt.Println(idx, v[0], v[1])
				}
				hexMap[v2[0][0]][v2[0][1]], hexMap[v2[1][0]][v2[1][1]], hexMap[v2[2][0]][v2[2][1]] = hexMap[v2[2][0]][v2[2][1]], hexMap[v2[0][0]][v2[0][1]], hexMap[v2[1][0]][v2[1][1]]
			}
			starMatches = checkHexStar()
			if len(starMatches) > 6 {
				fmt.Println(starMatches)
			}
			if len(starMatches) >= 6 {
				timesToRotate = 0
				rotate = 0
				currExX = -1
				currExY = -1
				starScale = 1
				starAlpha = 1
				starRotate = false
				currStarCenter = getStarCenter(starMatches)
				hexMap[currStarCenter[0]][currStarCenter[1]] = 6
				// makeStarAndGenNew(starMatches)
			} else {
				matches := checkHexMap()
				if len(matches) > 0 {
					currentMatches = matches
					scale = 1
					currExX = -1
					currExY = -1
					rotate = 0
					timesToRotate = 0
					starRotate = false
				} else {
					if timesToRotate == 0 {
						currExX = -1
						currExY = -1
						rotate = 0
						timesToRotate = 0
						starRotate = false
						mouseLock = false
						fmt.Println("Mouse unlocked 3")
					}
					rotate = 0
					timesToRotate--
				}
			}
		}
	}
	if !mouseLock {
		prevSelectPos = calcClosestCenter(posX, posY)
		drawBorderAtXY(float32(prevSelectPos[0]), float32(prevSelectPos[1]), prevSelectPos[2])
	}
	gl.Flush()
	gl.Disable(gl.TEXTURE_2D)
	gl.Disable(gl.BLEND)
}
Exemple #27
0
func (r *AnimateRotate) AnimateAndExecute() {
	if len(r.SelectedHex) == 0 {
		return
	}
	gl.PushMatrix()
	var p Point
	for _, hex := range r.SelectedHex {
		p.X += hexMap2.GetCenter(hex.Pos.X, hex.Pos.Y).X
		p.Y += hexMap2.GetCenter(hex.Pos.X, hex.Pos.Y).Y
	}
	p.X /= 3
	p.Y /= 3
	x, y := p.WithOffset()
	gl.Translatef(float32(x), float32(y), 0)
	if r.PauseTicks == 0 {
		gl.Scalef(1.3, 1.3, 1)
		gl.Rotatef(r.RotateAngle, 0, 0, 1)
	} else {
		r.PauseTicks--
	}
	for _, hex := range r.SelectedHex {
		gl.PushMatrix()
		x2, y2 := hexMap2.GetTopLeft(hex.Pos.X, hex.Pos.Y).WithOffset()
		gl.Translatef(float32(x2-x), float32(y2-y), 0)
		hex.Hex.Render(1, false)
		gl.PopMatrix()
	}
	gl.PopMatrix()
	if r.PauseTicks > 0 {
		return
	}
	if r.RotateAngle < 120 {
		r.RotateAngle += 20
	} else {
		fmt.Println(r.SelectedHex[0].Hex, r.SelectedHex[1].Hex, r.SelectedHex[2].Hex)
		hexMap2[r.SelectedHex[0].Pos.X][r.SelectedHex[0].Pos.Y], hexMap2[r.SelectedHex[1].Pos.X][r.SelectedHex[1].Pos.Y], hexMap2[r.SelectedHex[2].Pos.X][r.SelectedHex[2].Pos.Y] = hexMap2[r.SelectedHex[2].Pos.X][r.SelectedHex[2].Pos.Y], hexMap2[r.SelectedHex[0].Pos.X][r.SelectedHex[0].Pos.Y], hexMap2[r.SelectedHex[1].Pos.X][r.SelectedHex[1].Pos.Y]
		r.SelectedHex[0].Hex, r.SelectedHex[1].Hex, r.SelectedHex[2].Hex = r.SelectedHex[2].Hex, r.SelectedHex[0].Hex, r.SelectedHex[1].Hex
		collide := hexMap2.CheckCollision()
		if r.TimesToRotate == 0 || collide {
			for _, hex := range r.SelectedHex {
				if hex.Hex.State == StateRotating {
					hex.Hex.State = StateNormal
				}
			}
			r.SelectedHex = nil
			r.SelectedHex = make([]SelectedHex, 0)
			if collide {
				hexShrink.InitAnimation()
				if r.postHook != nil {
					hexShrink.postHook = r.postHook
				}
			} else {
				if r.postHook != nil {
					r.postHook()
				}
			}
		} else {
			r.TimesToRotate--
			r.RotateAngle = 0
			r.PauseTicks = 5
		}
	}
}
Exemple #28
0
func (s *ShrinkHex) AnimateAndExecute() {
	if len(s.SelectedHex) == 0 {
		return
	}
	if s.Scale > 0.2 {
		s.Scale -= 0.15
		fmt.Println(s.Scale)
		for _, hex := range s.SelectedHex {
			gl.PushMatrix()
			x, y := hexMap2.GetCenter(hex.Pos.X, hex.Pos.Y).WithOffset()
			gl.Translatef(float32(x), float32(y), 0)
			gl.Scalef(s.Scale, s.Scale, 1)
			hex.Hex.Render(1, true)
			gl.PopMatrix()
		}
	} else {
		fallHexes := make([]FallHex, 0)
		for x := 0; x < 11; x++ {
			maxy := 7
			if x%2 == 1 {
				maxy = 8
			}
			fell := false
			for y := maxy; y >= 0; y-- {
				if hexMap2[x][y].State == StateShrinking && !fell {
					hexMap2[x][y] = nil
					for y2 := y; y2 > 0; y2-- {
						hexMap2[x][y2] = hexMap2[x][y2-1]
						if hexMap2[x][y2].State == StateShrinking {
							continue
						}
						hexMap2[x][y2].State = StateFalling
						fallHexes = append(fallHexes, FallHex{hexMap2[x][y2], FieldPoint{x, y2}, FieldPoint{x, y2 - 1}, 0})
						fmt.Println(1, x, y2, x, y2-1)
					}
					hexMap2[x][0] = &Hex{HexType(rand.Intn(int(HexFlower)-1) + 1), StateFalling}
					fallHexes = append(fallHexes, FallHex{hexMap2[x][0], FieldPoint{x, 0}, FieldPoint{x, -1}, 0})
					fell = true
				} else if hexMap2[x][y].State == StateShrinking && fell {
					hexMap2[x][y] = nil
					for y2 := y; y2 > 0; y2-- {
						hexMap2[x][y2] = hexMap2[x][y2-1]
						if hexMap2[x][y2].State == StateShrinking {
							continue
						}
						hexMap2[x][y2].State = StateFalling
						// found := false
						// for i, hex := range fallHexes {
						// 	if hex.Hex == hexMap2[x][y2] {
						// 		found = true
						// 		fallHexes[i].Target.Y++
						// 		break
						// 	}
						// }
						fmt.Println(2, x, y2, x, y2-1)
					}
					miny := 0
					for i, hex := range fallHexes {
						if hex.Pos.X == x {
							fallHexes[i].Target.Y++
							if hex.Pos.Y < miny {
								miny = hex.Pos.Y
							}
						}
					}
					hexMap2[x][0] = &Hex{HexType(rand.Intn(int(HexFlower)-1) + 1), StateFalling}
					fallHexes = append(fallHexes, FallHex{hexMap2[x][0], FieldPoint{x, 0}, FieldPoint{x, miny - 1}, 0})
				}
				if hexMap2[x][y].State == StateShrinking {
					y = maxy + 1
				}
			}
		}
		hexFall.InitAnimation(fallHexes)
		if s.postHook != nil {
			hexFall.SetPostHook(s.postHook)
		}
		s.SelectedHex = nil
		s.SelectedHex = make([]SelectedHex, 0)
	}
}