Files
__mahjong/components/raybri/raybri.c
T

74 lines
1.5 KiB
C

#include "raybri.h"
#include "raylib.h"
#include "rlgl.h"
#include "raymath.h"
#include <dlfcn.h>
#include <math.h>
#include <stddef.h>
#include <stdio.h>
#include <string.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);
sr_ready = 1;
}
void raybri_resize(int width, int height)
{
if (width > 0) sr_width = width;
if (height > 0) sr_height = height;
}
static void sr_render_main_pass(void)
{
// --- Main pass: camera ---
rlViewport(0, 0, sr_width, sr_height);
rlSetFramebufferWidth(sr_width);
rlSetFramebufferHeight(sr_height);
rlClearColor(0, 0, 255, 255);
rlClearScreenBuffers();
}
void raybri_render(void)
{
if (!sr_ready) return;
rlDrawRenderBatchActive();
sr_render_main_pass();
}
void raybri_shutdown(void)
{
if (!sr_ready) return;
rlglClose();
sr_ready = 0;
}