Example #1
0
func main() {
	fmt.Println("Starting")

	allegro.Init()
	allegro.InstallKeyboard()
	allegro.InstallMouse()

	runtime.GOMAXPROCS(10)

	doneChan := make(chan bool)
	var disp *allegro.Display
	alFuncs <- func() {
		disp = allegro.CreateDisplay(600, 400, allegro.WINDOWED)

		color = allegro.CreateColor(100, 0, 0, 255)
		color.Clear()
		allegro.Flip()
		doneChan <- true
	}

	<-doneChan
	fmt.Println("Created window")

	handleEvents(disp)

	fmt.Println("Ended")
}
Example #2
0
func DisplayColor() {
	r, g, b, _ := color.GetRGBA()
	color = allegro.CreateColor(r+5, g+5, b+5, 255)
	color.Clear()
	allegro.Flip()
}
Example #3
0
func (d *DisplayEngine) drawFrame() {
	toDraw := make([][]*resources.Bitmap, d.config.MapW*d.config.MapH)
	drawPasses := 0
	for x := 0; x < d.config.MapW; x++ {
		for y := 0; y < d.config.MapH; y++ {
			toDraw[x*d.config.MapW+y] = (*d.gameEngine).GetTile(x, y)
			length := len(toDraw[x*d.config.MapW+y])
			if length > drawPasses {
				drawPasses = length
			}
		}
	}

	viewport := d.viewport
	font := allegro.CreateBuiltinFont()

	// Don't want anyone changing the viewport mid frame or any such highjinks
	d.Display.SetTargetBackbuffer()

	allegro.RunInThread(func() {
		r, g, b, a := d.config.BGColor.GetRGBA()
		gl.ClearColor(
			gl.GLclampf(r)/255.0,
			gl.GLclampf(g)/255.0,
			gl.GLclampf(b)/255.0,
			gl.GLclampf(a)/255.0)

		gl.Clear(gl.COLOR_BUFFER_BIT)

		viewport.SetupTransform()

		for p := 0; p < drawPasses; p++ {
			m := d.config.MapW
			n := d.config.MapH
			for s := 0; s < m+n; s++ {
				for x := 0; x < s; x++ {
					y := s - x - 1
					if x >= m || y < 0 || y >= n {
						continue
					}
					if len(toDraw[x*d.config.MapW+y]) < p {
						continue
					}

					// Coordinates in terms of pixels
					px := (y - x) * d.config.TileW / 2
					py := (x + y) * d.config.TileH / 2
					bmp := toDraw[x*d.config.MapW+y][p]
					/*					ox := bmp.OffX
										oy := bmp.OffY*/
					bw, bh := bmp.W, bmp.H
					if viewport.OnScreen(px, py, bw, bh) {
						gl.Begin(gl.QUADS)
						bmp.Tex.Bind(gl.TEXTURE_2D)
						gl.TexCoord2f(0, 0)
						gl.Vertex3i(px, py, 0)
						gl.TexCoord2f(0, 1)
						gl.Vertex3i(px, py+bw, 0)
						gl.TexCoord2f(1, 1)
						gl.Vertex3i(px+bh, py+bw, 0)
						gl.TexCoord2f(1, 0)
						gl.Vertex3i(px+bh, py, 0)
						gl.End()
					}
				}
			}
		}

		gl.Flush()
	})

	var trans allegro.Transform
	trans.Identity()
	trans.Use()

	font.Draw(allegro.CreateColor(0, 255, 0, 255), 0, 0, 0, fmt.Sprint(int(d.fps)))

	allegro.Flip()

	d.frameDrawing.Unlock()
}