59 lines
1.2 KiB
C
59 lines
1.2 KiB
C
#include "raybri.h"
|
|
|
|
#include "rlgl.h"
|
|
|
|
#include <dlfcn.h>
|
|
#include <stddef.h>
|
|
|
|
static int sr_width = 1;
|
|
static int sr_height = 1;
|
|
|
|
static int sr_ready = 0;
|
|
|
|
// raylib is built as a static/dynamic library with GLFW baked in, but we never
|
|
// call InitWindow(). Instead we render into an OpenGL context owned by the
|
|
// macOS app, so we must supply the OpenGL entry point loader ourselves.
|
|
static void *sr_gl_loader(const char *name)
|
|
{
|
|
static void *handle = NULL;
|
|
if (handle == NULL)
|
|
{
|
|
handle = dlopen("/System/Library/Frameworks/OpenGL.framework/OpenGL", RTLD_LAZY | RTLD_LOCAL);
|
|
}
|
|
if (handle == NULL) return NULL;
|
|
return dlsym(handle, name);
|
|
}
|
|
|
|
void raybri_init(void) {
|
|
//SetTraceLogLevel(LOG_WARNING);
|
|
rlLoadExtensions((void *)sr_gl_loader);
|
|
// Init with default 1x1 size
|
|
rlglInit(1, 1);
|
|
rlClearColor(0, 0, 255, 255);
|
|
|
|
sr_ready = 1;
|
|
}
|
|
|
|
void raybri_resize(int width, int height)
|
|
{
|
|
if (width > 0) sr_width = width;
|
|
if (height > 0) sr_height = height;
|
|
}
|
|
|
|
void raybri_render(void)
|
|
{
|
|
if (!sr_ready) return;
|
|
|
|
rlViewport(0, 0, sr_width, sr_height);
|
|
rlClearScreenBuffers();
|
|
rlDrawRenderBatchActive();
|
|
}
|
|
|
|
void raybri_shutdown(void)
|
|
{
|
|
if (!sr_ready) return;
|
|
|
|
rlglClose();
|
|
sr_ready = 0;
|
|
}
|