func (e *engine) LoadTexture(src image.Image) (sprite.Texture, error) { b := src.Bounds() t := &texture{glutil.NewImage(b.Dx(), b.Dy()), b} t.Upload(b, src) // TODO: set "glImage.Pix = nil"?? We don't need the CPU-side image any more. return t, nil }
// DrawFPS draws the per second framerate in the bottom-left of the screen. func DrawFPS(c config.Event) { const imgW, imgH = 7*(fontWidth+1) + 1, fontHeight + 2 fps.mu.Lock() if fps.c != c || fps.m == nil { fps.c = c fps.m = glutil.NewImage(imgW, imgH) } fps.mu.Unlock() display := [7]byte{ 4: 'F', 5: 'P', 6: 'S', } now := time.Now() f := 0 if dur := now.Sub(lastDraw); dur > 0 { f = int(time.Second / dur) } display[2] = '0' + byte((f/1e0)%10) display[1] = '0' + byte((f/1e1)%10) display[0] = '0' + byte((f/1e2)%10) draw.Draw(fps.m.RGBA, fps.m.RGBA.Bounds(), image.White, image.Point{}, draw.Src) for i, c := range display { glyph := glyphs[c] if len(glyph) != fontWidth*fontHeight { continue } for y := 0; y < fontHeight; y++ { for x := 0; x < fontWidth; x++ { if glyph[fontWidth*y+x] == ' ' { continue } fps.m.RGBA.SetRGBA((fontWidth+1)*i+x+1, y+1, color.RGBA{A: 0xff}) } } } fps.m.Upload() fps.m.Draw( c, geom.Point{0, c.Height - imgH}, geom.Point{imgW, c.Height - imgH}, geom.Point{0, c.Height}, fps.m.RGBA.Bounds(), ) lastDraw = now }
func DrawResult(c config.Event, rate int) { const imgW, imgH = 8*(fontWidth+1) + 1, fontHeight + 2 image_result := glutil.NewImage(imgW, imgH) display := [8]byte{ 4: 'M', 5: 'B', 6: 'P', 7: 'S', } display[2] = '0' + byte((rate/1e0)%10) display[1] = '0' + byte((rate/1e1)%10) display[0] = '0' + byte((rate/1e2)%10) draw.Draw(image_result.RGBA, image_result.RGBA.Bounds(), image.White, image.Point{}, draw.Src) for i, c := range display { glyph := glyphs[c] if len(glyph) != fontWidth*fontHeight { continue } for y := 0; y < fontHeight; y++ { for x := 0; x < fontWidth; x++ { if glyph[fontWidth*y+x] == ' ' { continue } image_result.RGBA.SetRGBA((fontWidth+1)*i+x+1, y+1, color.RGBA{A: 0xff}) } } } image_result.Upload() image_result.Draw( c, geom.Point{0, c.HeightPt - imgH}, geom.Point{imgW, c.HeightPt - imgH}, geom.Point{0, c.HeightPt}, image_result.RGBA.Bounds(), ) }