Skip to content

Commit a568dde

Browse files
update examples
1 parent 8b5666e commit a568dde

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

examples/rgfw_gamepad.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ typedef struct my_rect { i32 x, y, w, h; } my_rect;
2323

2424
void drawGamepad(RGFW_window* w, mg_gamepad* gamepad);
2525

26+
#define RT_IMPLEMENTATION
27+
#include "rtime.h"
28+
2629
int main(void) {
2730
RGFW_window* win = RGFW_createWindow("RGFW Example Window", 0, 0, 800, 450, RGFW_windowCenter | RGFW_windowOpenGL);
2831
RGFW_window_setExitKey(win, RGFW_escape);
@@ -33,12 +36,23 @@ int main(void) {
3336
mg_gamepads_init(&gamepads);
3437
mg_gamepad* gamepad = gamepads.list.head;
3538

39+
float t1 = rt_getTime();
40+
size_t frames = 0;
41+
3642
while (RGFW_window_shouldClose(win) == RGFW_FALSE) {
3743
mg_gamepads_poll(&gamepads);
3844
if (gamepad == NULL) {
3945
gamepad = gamepads.list.head;
4046
}
4147

48+
float t2 = (float)rt_getTime();
49+
if (t2 - t1 >= 1.0 && RGFW_isKeyDown(RGFW_space)) {
50+
51+
printf("FPS %f\n", (frames / (t2 - t1)));
52+
frames = 0;
53+
t1 = t2;
54+
}
55+
4256
RGFW_event event;
4357
while (RGFW_window_checkEvent(win, &event)) {
4458
if (event.type == RGFW_quit) break;
@@ -82,6 +96,7 @@ int main(void) {
8296
}
8397

8498
RGFW_window_swapBuffers_OpenGL(win);
99+
frames++;
85100
}
86101

87102
RGFW_window_close(win);

0 commit comments

Comments
 (0)