Skip to content

Commit

Permalink
use RL_MALLOC for RGFW
Browse files Browse the repository at this point in the history
  • Loading branch information
ColleagueRiley committed Dec 1, 2024
1 parent 9ecd1ce commit 0760667
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 59 deletions.
124 changes: 65 additions & 59 deletions src/external/RGFW.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,69 @@
#define RGFW_USE_INT - force the use c-types rather than stdint.h (for systems that might not have stdint.h (msvc))
*/

/*
Example to get you started :
linux : gcc main.c -lX11 -lXrandr -lGL
windows : gcc main.c -lopengl32 -lwinmm -lshell32 -lgdi32
macos : gcc main.c -framework Foundation -framework AppKit -framework OpenGL -framework CoreVideo
#define RGFW_IMPLEMENTATION
#include "RGFW.h"
u8 icon[4 * 3 * 3] = {0xFF, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0xFF, 0xFF, 0xFF, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0xFF};
int main() {
RGFW_window* win = RGFW_createWindow("name", RGFW_RECT(500, 500, 500, 500), (u64)0);
RGFW_window_setIcon(win, icon, RGFW_AREA(3, 3), 4);
for (;;) {
RGFW_window_checkEvent(win); // NOTE: checking events outside of a while loop may cause input lag
if (win->event.type == RGFW_quit || RGFW_isPressed(win, RGFW_Escape))
break;
RGFW_window_swapBuffers(win);
glClearColor(0xFF, 0XFF, 0xFF, 0xFF);
glClear(GL_COLOR_BUFFER_BIT);
}
RGFW_window_close(win);
}
compiling :
if you wish to compile the library all you have to do is create a new file with this in it
rgfw.c
#define RGFW_IMPLEMENTATION
#include "RGFW.h"
You may also want to add
`#define RGFW_EXPORT` when compiling and
`#define RGFW_IMPORT`when linking RGFW on it's own:
this reduces inline functions and prevents bloat in the object file
then you can use gcc (or whatever compile you wish to use) to compile the library into object file
ex. gcc -c RGFW.c -fPIC
after you compile the library into an object file, you can also turn the object file into an static or shared library
(commands ar and gcc can be replaced with whatever equivalent your system uses)
static : ar rcs RGFW.a RGFW.o
shared :
windows:
gcc -shared RGFW.o -lwinmm -lopengl32 -lshell32 -lgdi32 -o RGFW.dll
linux:
gcc -shared RGFW.o -lX11 -lGL -lXrandr -o RGFW.so
macos:
gcc -shared RGFW.o -framework Foundation -framework AppKit -framework OpenGL -framework CoreVideo
*/



/*
Credits :
EimaMei/Sacode : Much of the code for creating windows using winapi, Wrote the Silicon library, helped with MacOS Support, siliapp.h -> referencing
Expand Down Expand Up @@ -1151,63 +1214,6 @@ typedef RGFW_ENUM(u8, RGFW_mouseIcons) {
/** @} */

#endif /* RGFW_HEADER */

/*
Example to get you started :
linux : gcc main.c -lX11 -lXrandr -lGL
windows : gcc main.c -lopengl32 -lwinmm -lshell32 -lgdi32
macos : gcc main.c -framework Foundation -framework AppKit -framework OpenGL -framework CoreVideo
#define RGFW_IMPLEMENTATION
#include "RGFW.h"
u8 icon[4 * 3 * 3] = {0xFF, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0xFF, 0xFF, 0xFF, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0xFF};
int main() {
RGFW_window* win = RGFW_createWindow("name", RGFW_RECT(500, 500, 500, 500), (u64)0);
RGFW_window_setIcon(win, icon, RGFW_AREA(3, 3), 4);
for (;;) {
RGFW_window_checkEvent(win); // NOTE: checking events outside of a while loop may cause input lag
if (win->event.type == RGFW_quit || RGFW_isPressed(win, RGFW_Escape))
break;
RGFW_window_swapBuffers(win);
glClearColor(0xFF, 0XFF, 0xFF, 0xFF);
glClear(GL_COLOR_BUFFER_BIT);
}
RGFW_window_close(win);
}
compiling :
if you wish to compile the library all you have to do is create a new file with this in it
rgfw.c
#define RGFW_IMPLEMENTATION
#include "RGFW.h"
then you can use gcc (or whatever compile you wish to use) to compile the library into object file
ex. gcc -c RGFW.c -fPIC
after you compile the library into an object file, you can also turn the object file into an static or shared library
(commands ar and gcc can be replaced with whatever equivalent your system uses)
static : ar rcs RGFW.a RGFW.o
shared :
windows:
gcc -shared RGFW.o -lwinmm -lopengl32 -lshell32 -lgdi32 -o RGFW.dll
linux:
gcc -shared RGFW.o -lX11 -lGL -lXrandr -o RGFW.so
macos:
gcc -shared RGFW.o -framework Foundation -framework AppKit -framework OpenGL -framework CoreVideo
*/

#ifdef RGFW_X11
#define RGFW_OS_BASED_VALUE(l, w, m, h, ww) l
#elif defined(RGFW_WINDOWS)
Expand Down Expand Up @@ -8391,16 +8397,16 @@ EM_BOOL Emscripten_on_fullscreenchange(int eventType, const EmscriptenFullscreen
#else
emscripten_request_fullscreen("#canvas", 1);
#endif

}

emscripten_set_canvas_element_size("#canvas", RGFW_root->r.w, RGFW_root->r.h);

RGFW_windowResizeCallback(RGFW_root, RGFW_root->r);

return EM_TRUE;
}



EM_BOOL Emscripten_on_focusin(int eventType, const EmscriptenFocusEvent* e, void* userData) {
RGFW_UNUSED(eventType); RGFW_UNUSED(userData); RGFW_UNUSED(e);

Expand Down
4 changes: 4 additions & 0 deletions src/platforms/rcore_desktop_rgfw.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ void CloseWindow(void);
#define Size NSSIZE
#endif

#define RGFW_MALLOC RL_MALLOC
#define RGFW_FREE RL_FREE
#define RGFW_CALLOC RL_CALLOC

#include "../external/RGFW.h"

#if defined(_WIN32) || defined(_WIN64)
Expand Down

0 comments on commit 0760667

Please sign in to comment.