// vertex draws vertices. // Used in classic render mode. func (a *Attr) vertex(i int) { i *= a.size switch a.size { case 2: switch v := a.data.(type) { case []int16: gl.Vertex2s(v[i], v[i+1]) case []int32: gl.Vertex2i(int(v[i]), int(v[i+1])) case []float32: gl.Vertex2f(v[i], v[i+1]) case []float64: gl.Vertex2d(v[i], v[i+1]) } case 3: switch v := a.data.(type) { case []int16: gl.Vertex3s(v[i], v[i+1], v[i+2]) case []int32: gl.Vertex3i(int(v[i]), int(v[i+1]), int(v[i+2])) case []float32: gl.Vertex3f(v[i], v[i+1], v[i+2]) case []float64: gl.Vertex3d(v[i], v[i+1], v[i+2]) } case 4: switch v := a.data.(type) { case []int16: gl.Vertex4s(v[i], v[i+1], v[i+2], v[i+3]) case []int32: gl.Vertex4i(int(v[i]), int(v[i+1]), int(v[i+2]), int(v[i+3])) case []float32: gl.Vertex4f(v[i], v[i+1], v[i+2], v[i+3]) case []float64: gl.Vertex4d(v[i], v[i+1], v[i+2], v[i+3]) } } }
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() }