Skip to content

Commit 5af32e3

Browse files
committed
Upgrade RGFW to 1.8.1
1 parent 4631d35 commit 5af32e3

4 files changed

Lines changed: 10632 additions & 7301 deletions

File tree

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
UNAMEOS = $(shell uname)
22

3-
COMMON_CFLAGS= -Wall -Wextra -ggdb -std=c99 -pedantic -Ithirdparty -Ibuild
3+
COMMON_CFLAGS= -Wall -Wextra -ggdb -std=c99 -pedantic -Ithirdparty -Ibuild -DPENGER
44
SDL2_CFLAGS= `pkg-config --cflags sdl2` $(COMMON_CFLAGS)
55
RGFW_CFLAGS= $(COMMON_CFLAGS)
66
COMMON_LIBS= -lm

src/main_rgfw.c

Lines changed: 43 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,28 @@
2222
#endif
2323

2424
#define RGFW_IMPLEMENTATION
25+
#define RGFW_OPENGL
2526
#include "RGFW.h"
27+
typedef struct { i32 x, y, w, h; } RGFW_rect;
28+
29+
// TODO: make RGFW_getTimerFreq, RGFW_getTimerValue, RGFW_sleep compile on the rest of the platforms (Windows, MacOS)
30+
void RGFW_sleep(u64 ms) {
31+
struct timespec time;
32+
time.tv_sec = 0;
33+
time.tv_nsec = (long int)((double)ms * 1e+6);
34+
35+
#ifndef RGFW_NO_UNIX_CLOCK
36+
nanosleep(&time, NULL);
37+
#endif
38+
}
39+
40+
u64 RGFW_getTimerFreq(void) { return 1000000000LLU; }
41+
u64 RGFW_getTimerValue(void) {
42+
struct timespec ts;
43+
clock_gettime(CLOCK_REALTIME, &ts);
44+
return (u64)ts.tv_sec * RGFW_getTimerFreq() + (u64)ts.tv_nsec;
45+
}
46+
2647
#define RGL_LOAD_IMPLEMENTATION
2748
#include "rglLoad.h"
2849

@@ -231,12 +252,16 @@ int main(int argc, char **argv)
231252

232253
parse_state_from_args(&state, argc, argv);
233254

234-
RGFW_setGLHint(RGFW_glProfile, RGFW_glCore);
235-
RGFW_setGLHint(RGFW_glMajor, 3);
236-
RGFW_setGLHint(RGFW_glMinor, 3);
255+
RGFW_glHints *hints = RGFW_getGlobalHints_OpenGL();
256+
hints->profile = RGFW_glCore;
257+
hints->major = 3;
258+
hints->minor = 3;
259+
RGFW_setGlobalHints_OpenGL(hints);
260+
261+
RGFW_rect win_rect = {0, 0, TEXT_WIDTH, TEXT_HEIGHT*2};
262+
RGFW_window* win = RGFW_createWindow("sowon (RGFW)", win_rect.x, win_rect.y, win_rect.w, win_rect.h, RGFW_windowOpenGL);
237263

238-
RGFW_rect win_rect = RGFW_RECT(0, 0, TEXT_WIDTH, TEXT_HEIGHT*2);
239-
RGFW_window* win = RGFW_createWindow("sowon (RGFW)", win_rect, 0);
264+
RGFW_window_makeCurrentContext_OpenGL(win);
240265

241266
glEnable(GL_BLEND);
242267
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
@@ -284,14 +309,15 @@ int main(int argc, char **argv)
284309
last_time = now;
285310

286311
// INPUT BEGIN //////////////////////////////
287-
while (RGFW_window_checkEvent(win)) {
288-
switch (win->event.type) {
312+
RGFW_event event = {0};
313+
while (RGFW_window_checkEvent(win, &event)) {
314+
switch (event.type) {
289315
case RGFW_windowResized: {
290-
glViewport(0, 0, win->r.w, win->r.h);
291-
glUniform2f(scr_size_uni, win->r.w, win->r.h);
316+
glViewport(0, 0, win->w, win->h);
317+
glUniform2f(scr_size_uni, win->w, win->h);
292318
} break;
293319
case RGFW_keyPressed: {
294-
switch (win->event.key) {
320+
switch (event.key.value) {
295321
case RGFW_space: {
296322
state.paused = !state.paused;
297323
if (state.paused) {
@@ -329,7 +355,7 @@ int main(int argc, char **argv)
329355
} break;
330356

331357
case RGFW_F11: {
332-
RGFW_windowFlags window_flags = win->_flags; // TODO: use RGFW_window_getFlags() when RGFW 1.8.0 is released
358+
RGFW_windowFlags window_flags = RGFW_window_getFlags(win); // TODO: use RGFW_window_getFlags() when RGFW 1.8.0 is released
333359
if (window_flags & RGFW_windowFullscreen) {
334360
RGFW_window_setFlags(win, window_flags & (~RGFW_windowFullscreen));
335361
} else {
@@ -339,10 +365,10 @@ int main(int argc, char **argv)
339365
}
340366
} break;
341367
case RGFW_mouseButtonPressed: {
342-
if (win->event.keyMod & RGFW_modControl) {
343-
if (win->event.scroll > 0) {
368+
if (event.key.mod & RGFW_modControl) {
369+
if (event.scroll.y > 0) {
344370
state.user_scale += SCALE_FACTOR * state.user_scale;
345-
} else if (win->event.scroll < 0) {
371+
} else if (event.scroll.y < 0) {
346372
state.user_scale -= SCALE_FACTOR * state.user_scale;
347373
}
348374
}
@@ -360,15 +386,15 @@ int main(int argc, char **argv)
360386
// PENGER BEGIN //////////////////////////////
361387

362388
#ifdef PENGER
363-
render_penger_at(penger_tex_unit, win->r.w, win->r.h, state.displayed_time, state.mode==MODE_COUNTDOWN);
389+
render_penger_at(penger_tex_unit, win->w, win->h, state.displayed_time, state.mode==MODE_COUNTDOWN);
364390
#endif
365391

366392
// PENGER END //////////////////////////////
367393

368394
// DIGITS BEGIN //////////////////////////////
369395
int pen_x, pen_y;
370396
float fit_scale = 1.0;
371-
initial_pen(win->r.w, win->r.h, &pen_x, &pen_y, state.user_scale, &fit_scale);
397+
initial_pen(win->w, win->h, &pen_x, &pen_y, state.user_scale, &fit_scale);
372398

373399
// TODO: support amount of hours >99
374400
const size_t hours = t / 60 / 60;
@@ -394,7 +420,7 @@ int main(int argc, char **argv)
394420
// DIGITS END //////////////////////////////
395421
}
396422

397-
RGFW_window_swapBuffers(win);
423+
RGFW_window_swapBuffers_OpenGL(win);
398424
// RENDER END //////////////////////////////
399425

400426
// UPDATE BEGIN //////////////////////////////

src/rglLoad.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ PROCS
210210
static inline RGFW_proc load_proc_or_die(const char *name, RGFW_proc *proc)
211211
{
212212
printf("INFO: loading OpenGL function %s\n", name);
213-
*proc = RGFW_getProcAddress(name);
213+
*proc = RGFW_getProcAddress_OpenGL(name);
214214
if (*proc) return *proc;
215215
fprintf(stderr, "ERROR: could not load OpenGL function %s\n", name);
216216
abort();

0 commit comments

Comments
 (0)