This commit is contained in:
ColleagueRiley 2025-01-01 14:13:15 -05:00
parent 6d776075ff
commit ef950c43d4
5 changed files with 89 additions and 31 deletions

View File

@ -311,6 +311,8 @@ int main(void) {
RSGL_clear(RSGL_RGB(0, 0, 0));
Clay_RenderCommandArray renderCommands = CreateLayout();
Clay_RSGL_Render(renderCommands);
RSGL_draw();
glfwSwapBuffers(window);
}

View File

@ -295,13 +295,15 @@ int main(void) {
deltaTime = NOW - LAST;
Clay_Vector2 scrollDelta = {};
while (RGFW_window_checkEvent(win)); {
while (RGFW_window_checkEvent(win)) {
clay_RGFW_update(win, deltaTime);
}
RSGL_clear(RSGL_RGB(0, 0, 0));
Clay_RenderCommandArray renderCommands = CreateLayout();
Clay_RSGL_Render(renderCommands);
RSGL_draw();
RGFW_window_swapBuffers(win);
}

View File

@ -264,6 +264,7 @@ RSGLDEF void RSGL_init(
void* loader /* opengl prozc address ex. wglProcAddress */
);
RSGLDEF void RSGL_updateSize(RSGL_area r);
RSGLDEF void RSGL_draw(void); /* draw current batch */
RSGLDEF void RSGL_clear(RSGL_color c);
RSGLDEF void RSGL_free(void);
@ -403,6 +404,10 @@ RSGLDEF RSGL_texture RSGL_renderCreateTexture(u8* bitmap, RSGL_area memsize, u8
RSGLDEF void RSGL_renderUpdateTexture(RSGL_texture texture, u8* bitmap, RSGL_area memsize, u8 channels);
/* delete a texture */
RSGLDEF void RSGL_renderDeleteTexture(RSGL_texture tex);
/* starts scissoring */
RSGLDEF void RSGL_renderScissorStart(RSGL_rectF scissor);
/* stops scissoring */
RSGLDEF void RSGL_renderScissorEnd(void);
/* custom shader program */
typedef struct RSGL_programInfo {
@ -498,6 +503,7 @@ struct RFont_font;
RSGLDEF void RSGL_setRFont(struct RFont_font* font);
RSGLDEF void RSGL_drawText_len(const char* text, size_t len, RSGL_circle c, RSGL_color color);
RSGLDEF void RSGL_drawText_pro(const char* text, size_t len, float spacing, RSGL_circle c, RSGL_color color);
RSGLDEF void RSGL_drawText(const char* text, RSGL_circle c, RSGL_color color);
#define RSGL_drawTextF(text, font, c, color) \
RSGL_setFont(font);\
@ -854,10 +860,12 @@ void RSGL_init(RSGL_area r, void* loader) {
}
}
void RSGL_draw(void) {
RSGL_renderBatch(&RSGL_renderInfo);
}
void RSGL_clear(RSGL_color color) {
RSGL_renderClear(color.r / 255.0f, color.g / 255.0f, color.b / 255.0f, color.a / 255.0f);
RSGL_renderBatch(&RSGL_renderInfo);
}
void RSGL_updateSize(RSGL_area r) {
@ -1389,11 +1397,15 @@ void RSGL_setRFont(RFont_font* font) {
}
void RSGL_drawText_len(const char* text, size_t len, RSGL_circle c, RSGL_color color) {
RSGL_drawText_pro(text, len, 0.0f, c, color);
}
void RSGL_drawText_pro(const char* text, size_t len, float spacing, RSGL_circle c, RSGL_color color) {
if (text == NULL || RSGL_font.f == NULL)
return;
RFont_set_color(color.r / 255.0f, color.b / 255.0f, color.g / 255.0f, color.a / 255.0f);
RFont_draw_text_len(RSGL_font.f, text, len, c.x, c.y, c.d, 0.0f);
RFont_draw_text_len(RSGL_font.f, text, len, c.x, c.y, c.d, spacing);
}
void RSGL_drawText(const char* text, RSGL_circle c, RSGL_color color) {

View File

@ -497,6 +497,19 @@ void RSGL_renderBatch(RSGL_RENDER_INFO* info) {
info->vert_len = 0;
}
void RSGL_renderScissorStart(RSGL_rectF scissor) {
RSGL_draw();
glEnable(GL_SCISSOR_TEST);
glScissor(scissor.x, RSGL_args.currentRect.h - (scissor.y + scissor.h), scissor.w, scissor.h);
glScissor(scissor.x, scissor.y, scissor.w, scissor.h);
}
void RSGL_renderScissorEnd(void) {
RSGL_draw();
glDisable(GL_SCISSOR_TEST);
}
#ifndef GL_RG
#define GL_RG 0x8227
#endif

View File

@ -3,37 +3,35 @@
#include <stdio.h>
#define RFONT_FONT_SCALE 1
#define CLAY_COLOR_TO_RSGL_COLOR(color) \
RSGL_RGBA((unsigned char)roundf(color.r), (unsigned char)roundf(color.g), (unsigned char)roundf(color.b), (unsigned char)roundf(color.a))
static Clay_Dimensions RSGL_MeasureText(Clay_String *text, Clay_TextElementConfig *config)
{
RSGL_area area = RSGL_textArea(text->chars, config->fontSize, text->length);
RSGL_area area = RSGL_textArea(text->chars, config->fontSize / RFONT_FONT_SCALE, text->length);
return (Clay_Dimensions) {
.width = (float)area.w,
.height = (float)area.h,
};
}
RSGL_rectF currentClippingRectangle;
static void Clay_RSGL_Render(Clay_RenderCommandArray renderCommands)
{
for (uint32_t i = 0; i < renderCommands.length; i++)
{
Clay_RenderCommand *renderCommand = Clay_RenderCommandArray_Get(&renderCommands, i);
Clay_BoundingBox boundingBox = renderCommand->boundingBox;
RSGL_rectF boundingBox = RSGL_RECTF(renderCommand->boundingBox.x,
renderCommand->boundingBox.y,
renderCommand->boundingBox.width,
renderCommand->boundingBox.height);
switch (renderCommand->commandType)
{
case CLAY_RENDER_COMMAND_TYPE_RECTANGLE: {
Clay_RectangleElementConfig *config = renderCommand->config.rectangleElementConfig;
RSGL_rectF rect = RSGL_RECTF(
boundingBox.x,
boundingBox.y,
boundingBox.width,
boundingBox.height);
RSGL_color color = RSGL_RGBA( (u8)(config->color.r),
(u8)(config->color.g),
(u8)(config->color.b),
(u8)(config->color.a));
RSGL_drawRectF(rect, color);
RSGL_drawRectF(boundingBox, CLAY_COLOR_TO_RSGL_COLOR(config->color));
break;
}
case CLAY_RENDER_COMMAND_TYPE_TEXT: {
@ -47,26 +45,57 @@ static void Clay_RSGL_Render(Clay_RenderCommandArray renderCommands)
(u8)(config->textColor.a));
RSGL_circle destination = RSGL_CIRCLE(
boundingBox.x,
boundingBox.y,
boundingBox.height);
RSGL_drawText_len(text.chars, text.length, destination, color);
boundingBox.x,
boundingBox.y,
config->fontSize / RFONT_FONT_SCALE);
RSGL_drawText_pro(text.chars, text.length, config->letterSpacing, destination, color);
break;
}
case CLAY_RENDER_COMMAND_TYPE_IMAGE:
Clay_ImageElementConfig* config = renderCommand->config.imageElementConfig;
RSGL_setTexture((RSGL_texture)config->imageData);
RSGL_drawRectF(boundingBox, RSGL_RGBA(255, 255, 255, 255));
break;
case CLAY_RENDER_COMMAND_TYPE_BORDER: {
Clay_BorderElementConfig *config = renderCommand->config.borderElementConfig;
if (config->left.width > 0) {
RSGL_drawRectF(RSGL_RECTF(boundingBox.x,
boundingBox.y + config->cornerRadius.topLeft,
config->left.width,
boundingBox.h - config->cornerRadius.topLeft - config->cornerRadius.bottomLeft),
CLAY_COLOR_TO_RSGL_COLOR(config->left.color));
}
if (config->right.width > 0) {
RSGL_drawRectF(RSGL_RECTF(boundingBox.x + boundingBox.w - config->right.width,
boundingBox.y + config->cornerRadius.topRight,
config->right.width,
boundingBox.h - config->cornerRadius.topRight - config->cornerRadius.bottomRight),
CLAY_COLOR_TO_RSGL_COLOR(config->right.color));
}
if (config->top.width > 0) {RSGL_drawRectF(RSGL_RECTF(boundingBox.x + config->cornerRadius.topLeft, boundingBox.y,
boundingBox.w - config->cornerRadius.topLeft - config->cornerRadius.topRight,
config->top.width),
CLAY_COLOR_TO_RSGL_COLOR(config->top.color));
}
if (config->bottom.width > 0) {RSGL_drawRectF(RSGL_RECTF(boundingBox.x + config->cornerRadius.bottomLeft, \
boundingBox.y + boundingBox.h - config->bottom.width,
boundingBox.w - config->cornerRadius.bottomLeft - config->cornerRadius.bottomRight,
config->bottom.width),
CLAY_COLOR_TO_RSGL_COLOR(config->bottom.color));
}
break;
}
case CLAY_RENDER_COMMAND_TYPE_SCISSOR_START: {
currentClippingRectangle = (RSGL_rectF) {
boundingBox.x,
boundingBox.y,
boundingBox.width,
boundingBox.height,
};
//printf("Clipping rectangle has not been implemented yet\n");
RSGL_renderScissorStart(boundingBox);
break;
}
case CLAY_RENDER_COMMAND_TYPE_SCISSOR_END: {
//printf("Clipping rectangle has not been implemented yet\n");
RSGL_renderScissorEnd();
break;
}
case CLAY_RENDER_COMMAND_TYPE_CUSTOM:
printf("Custom render commands have not been implemented yet\n");
break;
default: {
fprintf(stderr, "Error: unhandled render command: %d\n", renderCommand->commandType);
}