mirror of
https://github.com/colby-swandale/waterfoul
synced 2024-12-26 21:58:54 +01:00
Add FPS in window title
This commit is contained in:
parent
2e58037c48
commit
85d2afe7da
2 changed files with 9 additions and 0 deletions
|
@ -14,6 +14,7 @@ module Waterfoul
|
|||
SDL.SetHint "SDL_HINT_RENDER_SCALE_QUALITY", "2"
|
||||
SDL.RenderSetLogicalSize(@renderer, WINDOW_WIDTH, WINDOW_HEIGHT)
|
||||
@texture = SDL.CreateTexture @renderer, SDL::PIXELFORMAT_ARGB8888, 1, SCREEN_WIDTH, SCREEN_HEIGHT
|
||||
@last = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
||||
end
|
||||
|
||||
def render(framebuffer)
|
||||
|
@ -22,6 +23,13 @@ module Waterfoul
|
|||
SDL.RenderClear @renderer
|
||||
SDL.RenderCopy @renderer, @texture, nil, nil
|
||||
SDL.RenderPresent @renderer
|
||||
|
||||
t = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
||||
fps = 1.0 / (t - @last)
|
||||
fps = fps.floor.to_s
|
||||
@last = t
|
||||
|
||||
SDL.SetWindowTitle(@window, "waterfoul (#{fps} fps)")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -36,5 +36,6 @@ module Waterfoul
|
|||
attach_function :GetKeyboardState, 'SDL_GetKeyboardState', [:pointer], :pointer
|
||||
attach_function :SetHint, 'SDL_SetHint', [:string, :string], :int
|
||||
attach_function :RenderSetLogicalSize, 'SDL_RenderSetLogicalSize', [:pointer, :int, :int], :int
|
||||
attach_function :SetWindowTitle, 'SDL_SetWindowTitle', [:pointer, :string], :void
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue