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+ #ifdef _WIN32
30+ void RGFW_sleep (u64 ms ) {
31+ Sleep ((u32 )ms );
32+ }
33+
34+ u64 RGFW_getTimerFreq (void ) {
35+ static u64 frequency = 0 ;
36+ if (frequency == 0 ) QueryPerformanceFrequency ((LARGE_INTEGER * )& frequency );
37+
38+ return frequency ;
39+ }
40+
41+ u64 RGFW_getTimerValue (void ) {
42+ u64 value ;
43+ QueryPerformanceCounter ((LARGE_INTEGER * )& value );
44+ return value ;
45+ }
46+ #else
47+ // TODO: make RGFW_getTimerFreq, RGFW_getTimerValue, RGFW_sleep compile on the rest of the platforms (Windows, MacOS)
48+ void RGFW_sleep (u64 ms ) {
49+ struct timespec time ;
50+ time .tv_sec = 0 ;
51+ time .tv_nsec = (long int )((double )ms * 1e+6 );
52+
53+ #ifndef RGFW_NO_UNIX_CLOCK
54+ nanosleep (& time , NULL );
55+ #endif
56+ }
57+
58+ u64 RGFW_getTimerFreq (void ) { return 1000000000LLU ; }
59+ u64 RGFW_getTimerValue (void ) {
60+ struct timespec ts ;
61+ clock_gettime (CLOCK_REALTIME , & ts );
62+ return (u64 )ts .tv_sec * RGFW_getTimerFreq () + (u64 )ts .tv_nsec ;
63+ }
64+
65+ #endif // _WIN32
66+
2667#define RGL_LOAD_IMPLEMENTATION
2768#include "rglLoad.h"
2869
@@ -231,12 +272,16 @@ int main(int argc, char **argv)
231272
232273 parse_state_from_args (& state , argc , argv );
233274
234- RGFW_setGLHint (RGFW_glProfile , RGFW_glCore );
235- RGFW_setGLHint (RGFW_glMajor , 3 );
236- RGFW_setGLHint (RGFW_glMinor , 3 );
275+ RGFW_glHints * hints = RGFW_getGlobalHints_OpenGL ();
276+ hints -> profile = RGFW_glCore ;
277+ hints -> major = 3 ;
278+ hints -> minor = 3 ;
279+ RGFW_setGlobalHints_OpenGL (hints );
280+
281+ RGFW_rect win_rect = {0 , 0 , TEXT_WIDTH , TEXT_HEIGHT * 2 };
282+ RGFW_window * win = RGFW_createWindow ("sowon (RGFW)" , win_rect .x , win_rect .y , win_rect .w , win_rect .h , RGFW_windowOpenGL );
237283
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 );
284+ RGFW_window_makeCurrentContext_OpenGL (win );
240285
241286 glEnable (GL_BLEND );
242287 glBlendFunc (GL_SRC_ALPHA , GL_ONE_MINUS_SRC_ALPHA );
@@ -284,14 +329,15 @@ int main(int argc, char **argv)
284329 last_time = now ;
285330
286331 // INPUT BEGIN //////////////////////////////
287- while (RGFW_window_checkEvent (win )) {
288- switch (win -> event .type ) {
332+ RGFW_event event = {0 };
333+ while (RGFW_window_checkEvent (win , & event )) {
334+ switch (event .type ) {
289335 case RGFW_windowResized : {
290- glViewport (0 , 0 , win -> r . w , win -> r . h );
291- glUniform2f (scr_size_uni , win -> r . w , win -> r . h );
336+ glViewport (0 , 0 , win -> w , win -> h );
337+ glUniform2f (scr_size_uni , win -> w , win -> h );
292338 } break ;
293339 case RGFW_keyPressed : {
294- switch (win -> event .key ) {
340+ switch (event .key . value ) {
295341 case RGFW_space : {
296342 state .paused = !state .paused ;
297343 if (state .paused ) {
@@ -329,7 +375,7 @@ int main(int argc, char **argv)
329375 } break ;
330376
331377 case RGFW_F11 : {
332- RGFW_windowFlags window_flags = win -> _flags ; // TODO: use RGFW_window_getFlags() when RGFW 1.8.0 is released
378+ RGFW_windowFlags window_flags = RGFW_window_getFlags ( win ) ; // TODO: use RGFW_window_getFlags() when RGFW 1.8.0 is released
333379 if (window_flags & RGFW_windowFullscreen ) {
334380 RGFW_window_setFlags (win , window_flags & (~RGFW_windowFullscreen ));
335381 } else {
@@ -339,10 +385,10 @@ int main(int argc, char **argv)
339385 }
340386 } break ;
341387 case RGFW_mouseButtonPressed : {
342- if (win -> event .keyMod & RGFW_modControl ) {
343- if (win -> event .scroll > 0 ) {
388+ if (event .key . mod & RGFW_modControl ) {
389+ if (event .scroll . y > 0 ) {
344390 state .user_scale += SCALE_FACTOR * state .user_scale ;
345- } else if (win -> event .scroll < 0 ) {
391+ } else if (event .scroll . y < 0 ) {
346392 state .user_scale -= SCALE_FACTOR * state .user_scale ;
347393 }
348394 }
@@ -360,15 +406,15 @@ int main(int argc, char **argv)
360406 // PENGER BEGIN //////////////////////////////
361407
362408 #ifdef PENGER
363- render_penger_at (penger_tex_unit , win -> r . w , win -> r . h , state .displayed_time , state .mode == MODE_COUNTDOWN );
409+ render_penger_at (penger_tex_unit , win -> w , win -> h , state .displayed_time , state .mode == MODE_COUNTDOWN );
364410 #endif
365411
366412 // PENGER END //////////////////////////////
367413
368414 // DIGITS BEGIN //////////////////////////////
369415 int pen_x , pen_y ;
370416 float fit_scale = 1.0 ;
371- initial_pen (win -> r . w , win -> r . h , & pen_x , & pen_y , state .user_scale , & fit_scale );
417+ initial_pen (win -> w , win -> h , & pen_x , & pen_y , state .user_scale , & fit_scale );
372418
373419 // TODO: support amount of hours >99
374420 const size_t hours = t / 60 / 60 ;
@@ -394,7 +440,7 @@ int main(int argc, char **argv)
394440 // DIGITS END //////////////////////////////
395441 }
396442
397- RGFW_window_swapBuffers (win );
443+ RGFW_window_swapBuffers_OpenGL (win );
398444 // RENDER END //////////////////////////////
399445
400446 // UPDATE BEGIN //////////////////////////////
0 commit comments