Ejemplo n.º 1
0
func (v *Viewport) ResizeViewport(w, h int) {
	v.w = w
	v.h = h
	v.buildTrans()
	allegro.RunInThread(func() {
		gl.Viewport(0, 0, w, h)
	})
}
Ejemplo n.º 2
0
func (rm *ResourceManager) loadTile(name string) (*Bitmap, bool) {
	fname, _ := filepath.Abs(path.Join("resources", name))
	var tex gl.Texture
	allegro.RunInThread(func() {
		tex = gl.GenTexture()
		tex.Bind(gl.TEXTURE_2D)
		glfw.LoadTexture2D(fname, 0)
	})
	bmp := Bitmap{tex, 0, 0, DEFAULT_TILE_WIDTH, DEFAULT_TILE_HEIGHT}
	rm.tileBmps[name] = bmp
	return &bmp, true
}
Ejemplo n.º 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()
}