mirror of
https://github.com/nicbarker/clay.git
synced 2025-04-22 06:08:03 +00:00
Compare commits
4 Commits
1f92a81c7c
...
ef950c43d4
Author | SHA1 | Date | |
---|---|---|---|
|
ef950c43d4 | ||
|
6d776075ff | ||
|
faaaa6b52e | ||
|
4802e02571 |
@ -12,4 +12,7 @@ if(NOT MSVC)
|
|||||||
add_subdirectory("examples/clay-official-website")
|
add_subdirectory("examples/clay-official-website")
|
||||||
add_subdirectory("examples/introducing-clay-video-demo")
|
add_subdirectory("examples/introducing-clay-video-demo")
|
||||||
add_subdirectory("examples/SDL2-video-demo")
|
add_subdirectory("examples/SDL2-video-demo")
|
||||||
|
add_subdirectory("examples/SDL2-video-demo")
|
||||||
|
add_subdirectory("examples/RSGL_rendering/GLFW_windowing")
|
||||||
|
add_subdirectory("examples/RSGL_rendering/RGFW_windowing")
|
||||||
endif()
|
endif()
|
||||||
|
25
examples/RSGL_rendering/GLFW_windowing/CMakeLists.txt
Normal file
25
examples/RSGL_rendering/GLFW_windowing/CMakeLists.txt
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
cmake_minimum_required(VERSION 3.10)
|
||||||
|
|
||||||
|
project(GLFWExample)
|
||||||
|
|
||||||
|
set(SRC main.c)
|
||||||
|
|
||||||
|
# Set libraries and extensions based on OS
|
||||||
|
if(WIN32)
|
||||||
|
set(LIBS -lglfw3 -lgdi32 -lopengl32)
|
||||||
|
elseif(APPLE)
|
||||||
|
set(LIBS -lglfw -framework Cocoa -framework OpenGL -framework IOKit -framework CoreVideo)
|
||||||
|
elseif(UNIX)
|
||||||
|
set(LIBS -lglfw -lGL -lm -ldl -lpthread)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# Include directories
|
||||||
|
include_directories(${CMAKE_SOURCE_DIR})
|
||||||
|
|
||||||
|
# Add executable
|
||||||
|
add_executable(main${EXT} ${SRC})
|
||||||
|
|
||||||
|
# Link libraries
|
||||||
|
target_include_directories(main PRIVATE ../../../renderers/RSGL)
|
||||||
|
target_include_directories(main PRIVATE ../../../)
|
||||||
|
target_link_libraries(main${EXT} ${LIBS})
|
@ -1,90 +0,0 @@
|
|||||||
CC = gcc
|
|
||||||
|
|
||||||
LIBS = -lglfw3 -lm
|
|
||||||
EXT = .exe
|
|
||||||
STATIC =
|
|
||||||
|
|
||||||
WARNINGS = -Wall -Werror -Wextra
|
|
||||||
OS_DIR = \\
|
|
||||||
|
|
||||||
SRC = main.c
|
|
||||||
|
|
||||||
ifneq (,$(filter $(CC),winegcc x86_64-w64-mingw32-gcc i686-w64-mingw32-gcc))
|
|
||||||
STATIC = --static
|
|
||||||
detected_OS := WindowsCross
|
|
||||||
OS_DIR = /
|
|
||||||
ifeq ($(CC),x86_64-w64-mingw32-gcc)
|
|
||||||
CC = x86_64-w64-mingw32-gcc
|
|
||||||
else
|
|
||||||
CC = i686-w64-mingw32-gcc
|
|
||||||
endif
|
|
||||||
else
|
|
||||||
ifeq '$(findstring ;,$(PATH))' ';'
|
|
||||||
detected_OS := Windows
|
|
||||||
else
|
|
||||||
detected_OS := $(shell uname 2>/dev/null || echo Unknown)
|
|
||||||
detected_OS := $(patsubst CYGWIN%,Cygwin,$(detected_OS))
|
|
||||||
detected_OS := $(patsubst MSYS%,MSYS,$(detected_OS))
|
|
||||||
detected_OS := $(patsubst MINGW%,MSYS,$(detected_OS))
|
|
||||||
endif
|
|
||||||
endif
|
|
||||||
|
|
||||||
ifeq ($(detected_OS),Windows)
|
|
||||||
EXT = .exe
|
|
||||||
OS_DIR = \\
|
|
||||||
endif
|
|
||||||
ifeq ($(detected_OS),Darwin) # Mac OS X
|
|
||||||
EXT =
|
|
||||||
OS_DIR = /
|
|
||||||
endif
|
|
||||||
ifeq ($(detected_OS),Linux)
|
|
||||||
EXT =
|
|
||||||
OS_DIR = /
|
|
||||||
endif
|
|
||||||
|
|
||||||
ifneq (,$(filter $(CC),cl))
|
|
||||||
OS_DIR = \\
|
|
||||||
|
|
||||||
endif
|
|
||||||
|
|
||||||
ifneq (,$(filter $(CC),/opt/msvc/bin/x64/cl.exe /opt/msvc/bin/x86/cl.exe))
|
|
||||||
OS_DIR = /
|
|
||||||
endif
|
|
||||||
|
|
||||||
ifneq (,$(filter $(CC),cl /opt/msvc/bin/x64/cl.exe /opt/msvc/bin/x86/cl.exe))
|
|
||||||
WARNINGS =
|
|
||||||
STATIC = /static
|
|
||||||
LIBS += $(STATIC)
|
|
||||||
EXT = .exe
|
|
||||||
endif
|
|
||||||
|
|
||||||
LINK_GL1 =
|
|
||||||
LINK_GL3 =
|
|
||||||
LINK_GL2 =
|
|
||||||
|
|
||||||
ifneq (,$(filter $(CC),emcc))
|
|
||||||
LINK_GL1 = -s LEGACY_GL_EMULATION -D LEGACY_GL_EMULATION -sGL_UNSAFE_OPTS=0
|
|
||||||
LINK_GL3 = -s FULL_ES3
|
|
||||||
LINK_GL2 = -s FULL_ES2
|
|
||||||
EXPORTED_JS = -s EXPORTED_RUNTIME_METHODS="['stringToNewUTF8']"
|
|
||||||
LIBS = -s WASM=1 -s ASYNCIFY -s USE_WEBGL2=1 -s GL_SUPPORT_EXPLICIT_SWAP_CONTROL=1 $(EXPORTED_JS)
|
|
||||||
LIBS += -s EXPORTED_FUNCTIONS="['_malloc', '_main']"
|
|
||||||
EXT = .js
|
|
||||||
CC=emcc
|
|
||||||
|
|
||||||
LIBS += --preload-file ./
|
|
||||||
endif
|
|
||||||
|
|
||||||
LIBS += -I../../../ -I../../../renderers/RSGL
|
|
||||||
|
|
||||||
all: $(SRC)
|
|
||||||
$(CC) $(SRC) $(LINK_GL1) $(LIBS) -o main$(EXT)
|
|
||||||
|
|
||||||
clean:
|
|
||||||
rm -f *.exe main *.o
|
|
||||||
|
|
||||||
debug: $(SRC)
|
|
||||||
$(CC) $(SRC) $(LINK_GL1) $(LIBS) -D RGFW_DEBUG -o main$(EXT)
|
|
||||||
ifeq (,$(filter $(CC),emcc))
|
|
||||||
.$(OS_DIR)main$(EXT)
|
|
||||||
endif
|
|
@ -311,6 +311,8 @@ int main(void) {
|
|||||||
RSGL_clear(RSGL_RGB(0, 0, 0));
|
RSGL_clear(RSGL_RGB(0, 0, 0));
|
||||||
Clay_RenderCommandArray renderCommands = CreateLayout();
|
Clay_RenderCommandArray renderCommands = CreateLayout();
|
||||||
Clay_RSGL_Render(renderCommands);
|
Clay_RSGL_Render(renderCommands);
|
||||||
|
RSGL_draw();
|
||||||
|
|
||||||
glfwSwapBuffers(window);
|
glfwSwapBuffers(window);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
38
examples/RSGL_rendering/RGFW_windowing/CMakeLists.txt
Normal file
38
examples/RSGL_rendering/RGFW_windowing/CMakeLists.txt
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
cmake_minimum_required(VERSION 3.10)
|
||||||
|
|
||||||
|
project(MyProject)
|
||||||
|
|
||||||
|
set(SRC main.c)
|
||||||
|
|
||||||
|
# Detect OS
|
||||||
|
if(WIN32)
|
||||||
|
set(LIBS -ggdb -lshell32 -lwinmm -lgdi32 -lopengl32)
|
||||||
|
set(EXT ".exe")
|
||||||
|
elseif(APPLE)
|
||||||
|
set(LIBS -lm -framework Foundation -framework AppKit -framework IOKit -framework OpenGL)
|
||||||
|
set(EXT "")
|
||||||
|
elseif(UNIX)
|
||||||
|
set(LIBS -lXrandr -lX11 -lm -lGL -ldl -lpthread)
|
||||||
|
set(EXT "")
|
||||||
|
else()
|
||||||
|
set(detected_OS "Unknown")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# Settings for emcc
|
||||||
|
if(CMAKE_C_COMPILER MATCHES "emcc")
|
||||||
|
set(EXPORTED_JS "-s EXPORTED_RUNTIME_METHODS=['stringToNewUTF8']")
|
||||||
|
set(LIBS "-s FULL_ES3 -s WASM=1 -s ASYNCIFY -s USE_WEBGL2=1 -s GL_SUPPORT_EXPLICIT_SWAP_CONTROL=1 ${EXPORTED_JS}")
|
||||||
|
set(LIBS "${LIBS} -s EXPORTED_FUNCTIONS=['_malloc', '_main']")
|
||||||
|
set(EXT ".js")
|
||||||
|
set(CMAKE_C_COMPILER "emcc")
|
||||||
|
set(LIBS "${LIBS} --preload-file ./")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# Include directories
|
||||||
|
include_directories(../../../ ../../../renderers/RSGL)
|
||||||
|
|
||||||
|
# Add executable
|
||||||
|
add_executable(main${EXT} ${SRC})
|
||||||
|
|
||||||
|
# Link libraries
|
||||||
|
target_link_libraries(main${EXT} ${LIBS})
|
@ -1,94 +0,0 @@
|
|||||||
CC = gcc
|
|
||||||
|
|
||||||
LIBS :=-lgdi32 -lm -lwinmm -ggdb -lopengl32
|
|
||||||
EXT = .exe
|
|
||||||
STATIC =
|
|
||||||
|
|
||||||
WARNINGS = -Wall -Werror -Wextra
|
|
||||||
OS_DIR = \\
|
|
||||||
|
|
||||||
SRC = main.c
|
|
||||||
|
|
||||||
ifneq (,$(filter $(CC),winegcc x86_64-w64-mingw32-gcc i686-w64-mingw32-gcc))
|
|
||||||
STATIC = --static
|
|
||||||
detected_OS := WindowsCross
|
|
||||||
OS_DIR = /
|
|
||||||
ifeq ($(CC),x86_64-w64-mingw32-gcc)
|
|
||||||
CC = x86_64-w64-mingw32-gcc
|
|
||||||
else
|
|
||||||
CC = i686-w64-mingw32-gcc
|
|
||||||
endif
|
|
||||||
else
|
|
||||||
ifeq '$(findstring ;,$(PATH))' ';'
|
|
||||||
detected_OS := Windows
|
|
||||||
else
|
|
||||||
detected_OS := $(shell uname 2>/dev/null || echo Unknown)
|
|
||||||
detected_OS := $(patsubst CYGWIN%,Cygwin,$(detected_OS))
|
|
||||||
detected_OS := $(patsubst MSYS%,MSYS,$(detected_OS))
|
|
||||||
detected_OS := $(patsubst MINGW%,MSYS,$(detected_OS))
|
|
||||||
endif
|
|
||||||
endif
|
|
||||||
|
|
||||||
ifeq ($(detected_OS),Windows)
|
|
||||||
LIBS := -ggdb -lshell32 -lwinmm -lgdi32 $(STATIC)
|
|
||||||
EXT = .exe
|
|
||||||
OS_DIR = \\
|
|
||||||
|
|
||||||
endif
|
|
||||||
ifeq ($(detected_OS),Darwin) # Mac OS X
|
|
||||||
LIBS := -lm -framework Foundation -framework AppKit -framework IOKit$(STATIC) -framework OpenGL
|
|
||||||
EXT =
|
|
||||||
OS_DIR = /
|
|
||||||
endif
|
|
||||||
ifeq ($(detected_OS),Linux)
|
|
||||||
LIBS := -lXrandr -lX11 -lm -lGL -ldl -lpthread $(STATIC)
|
|
||||||
EXT =
|
|
||||||
OS_DIR = /
|
|
||||||
endif
|
|
||||||
|
|
||||||
ifneq (,$(filter $(CC),cl))
|
|
||||||
OS_DIR = \\
|
|
||||||
|
|
||||||
endif
|
|
||||||
|
|
||||||
ifneq (,$(filter $(CC),/opt/msvc/bin/x64/cl.exe /opt/msvc/bin/x86/cl.exe))
|
|
||||||
OS_DIR = /
|
|
||||||
endif
|
|
||||||
|
|
||||||
ifneq (,$(filter $(CC),cl /opt/msvc/bin/x64/cl.exe /opt/msvc/bin/x86/cl.exe))
|
|
||||||
WARNINGS =
|
|
||||||
STATIC = /static
|
|
||||||
LIBS = $(STATIC)
|
|
||||||
EXT = .exe
|
|
||||||
endif
|
|
||||||
|
|
||||||
LINK_GL1 =
|
|
||||||
LINK_GL3 =
|
|
||||||
LINK_GL2 =
|
|
||||||
|
|
||||||
ifneq (,$(filter $(CC),emcc))
|
|
||||||
LINK_GL1 = -s LEGACY_GL_EMULATION -D LEGACY_GL_EMULATION -sGL_UNSAFE_OPTS=0
|
|
||||||
LINK_GL3 = -s FULL_ES3
|
|
||||||
LINK_GL2 = -s FULL_ES2
|
|
||||||
EXPORTED_JS = -s EXPORTED_RUNTIME_METHODS="['stringToNewUTF8']"
|
|
||||||
LIBS = -s WASM=1 -s ASYNCIFY -s USE_WEBGL2=1 -s GL_SUPPORT_EXPLICIT_SWAP_CONTROL=1 $(EXPORTED_JS)
|
|
||||||
LIBS += -s EXPORTED_FUNCTIONS="['_malloc', '_main']"
|
|
||||||
EXT = .js
|
|
||||||
CC=emcc
|
|
||||||
|
|
||||||
LIBS += --preload-file ./
|
|
||||||
endif
|
|
||||||
|
|
||||||
LIBS += -I../../../ -I../../../renderers/RSGL
|
|
||||||
|
|
||||||
all: $(SRC)
|
|
||||||
$(CC) $(SRC) $(LINK_GL1) $(LIBS) -o main$(EXT)
|
|
||||||
|
|
||||||
clean:
|
|
||||||
rm -f *.exe main *.o
|
|
||||||
|
|
||||||
debug: $(SRC)
|
|
||||||
$(CC) $(SRC) $(LINK_GL1) $(LIBS) -D RGFW_DEBUG -o main$(EXT)
|
|
||||||
ifeq (,$(filter $(CC),emcc))
|
|
||||||
.$(OS_DIR)main$(EXT)
|
|
||||||
endif
|
|
@ -295,13 +295,15 @@ int main(void) {
|
|||||||
deltaTime = NOW - LAST;
|
deltaTime = NOW - LAST;
|
||||||
|
|
||||||
Clay_Vector2 scrollDelta = {};
|
Clay_Vector2 scrollDelta = {};
|
||||||
while (RGFW_window_checkEvent(win)); {
|
while (RGFW_window_checkEvent(win)) {
|
||||||
clay_RGFW_update(win, deltaTime);
|
clay_RGFW_update(win, deltaTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
RSGL_clear(RSGL_RGB(0, 0, 0));
|
RSGL_clear(RSGL_RGB(0, 0, 0));
|
||||||
Clay_RenderCommandArray renderCommands = CreateLayout();
|
Clay_RenderCommandArray renderCommands = CreateLayout();
|
||||||
Clay_RSGL_Render(renderCommands);
|
Clay_RSGL_Render(renderCommands);
|
||||||
|
RSGL_draw();
|
||||||
|
|
||||||
RGFW_window_swapBuffers(win);
|
RGFW_window_swapBuffers(win);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -264,6 +264,7 @@ RSGLDEF void RSGL_init(
|
|||||||
void* loader /* opengl prozc address ex. wglProcAddress */
|
void* loader /* opengl prozc address ex. wglProcAddress */
|
||||||
);
|
);
|
||||||
RSGLDEF void RSGL_updateSize(RSGL_area r);
|
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_clear(RSGL_color c);
|
||||||
RSGLDEF void RSGL_free(void);
|
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);
|
RSGLDEF void RSGL_renderUpdateTexture(RSGL_texture texture, u8* bitmap, RSGL_area memsize, u8 channels);
|
||||||
/* delete a texture */
|
/* delete a texture */
|
||||||
RSGLDEF void RSGL_renderDeleteTexture(RSGL_texture tex);
|
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 */
|
/* custom shader program */
|
||||||
typedef struct RSGL_programInfo {
|
typedef struct RSGL_programInfo {
|
||||||
@ -498,6 +503,7 @@ struct RFont_font;
|
|||||||
RSGLDEF void RSGL_setRFont(struct RFont_font* 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_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);
|
RSGLDEF void RSGL_drawText(const char* text, RSGL_circle c, RSGL_color color);
|
||||||
#define RSGL_drawTextF(text, font, c, color) \
|
#define RSGL_drawTextF(text, font, c, color) \
|
||||||
RSGL_setFont(font);\
|
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) {
|
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_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) {
|
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) {
|
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)
|
if (text == NULL || RSGL_font.f == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
RFont_set_color(color.r / 255.0f, color.b / 255.0f, color.g / 255.0f, color.a / 255.0f);
|
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) {
|
void RSGL_drawText(const char* text, RSGL_circle c, RSGL_color color) {
|
||||||
|
@ -497,6 +497,19 @@ void RSGL_renderBatch(RSGL_RENDER_INFO* info) {
|
|||||||
info->vert_len = 0;
|
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
|
#ifndef GL_RG
|
||||||
#define GL_RG 0x8227
|
#define GL_RG 0x8227
|
||||||
#endif
|
#endif
|
||||||
|
@ -3,37 +3,35 @@
|
|||||||
|
|
||||||
#include <stdio.h>
|
#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)
|
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) {
|
return (Clay_Dimensions) {
|
||||||
.width = (float)area.w,
|
.width = (float)area.w,
|
||||||
.height = (float)area.h,
|
.height = (float)area.h,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
RSGL_rectF currentClippingRectangle;
|
|
||||||
|
|
||||||
static void Clay_RSGL_Render(Clay_RenderCommandArray renderCommands)
|
static void Clay_RSGL_Render(Clay_RenderCommandArray renderCommands)
|
||||||
{
|
{
|
||||||
for (uint32_t i = 0; i < renderCommands.length; i++)
|
for (uint32_t i = 0; i < renderCommands.length; i++)
|
||||||
{
|
{
|
||||||
Clay_RenderCommand *renderCommand = Clay_RenderCommandArray_Get(&renderCommands, 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)
|
switch (renderCommand->commandType)
|
||||||
{
|
{
|
||||||
case CLAY_RENDER_COMMAND_TYPE_RECTANGLE: {
|
case CLAY_RENDER_COMMAND_TYPE_RECTANGLE: {
|
||||||
Clay_RectangleElementConfig *config = renderCommand->config.rectangleElementConfig;
|
Clay_RectangleElementConfig *config = renderCommand->config.rectangleElementConfig;
|
||||||
RSGL_rectF rect = RSGL_RECTF(
|
RSGL_drawRectF(boundingBox, CLAY_COLOR_TO_RSGL_COLOR(config->color));
|
||||||
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);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case CLAY_RENDER_COMMAND_TYPE_TEXT: {
|
case CLAY_RENDER_COMMAND_TYPE_TEXT: {
|
||||||
@ -49,24 +47,55 @@ static void Clay_RSGL_Render(Clay_RenderCommandArray renderCommands)
|
|||||||
RSGL_circle destination = RSGL_CIRCLE(
|
RSGL_circle destination = RSGL_CIRCLE(
|
||||||
boundingBox.x,
|
boundingBox.x,
|
||||||
boundingBox.y,
|
boundingBox.y,
|
||||||
boundingBox.height);
|
config->fontSize / RFONT_FONT_SCALE);
|
||||||
RSGL_drawText_len(text.chars, text.length, destination, color);
|
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;
|
break;
|
||||||
}
|
}
|
||||||
case CLAY_RENDER_COMMAND_TYPE_SCISSOR_START: {
|
case CLAY_RENDER_COMMAND_TYPE_SCISSOR_START: {
|
||||||
currentClippingRectangle = (RSGL_rectF) {
|
RSGL_renderScissorStart(boundingBox);
|
||||||
boundingBox.x,
|
|
||||||
boundingBox.y,
|
|
||||||
boundingBox.width,
|
|
||||||
boundingBox.height,
|
|
||||||
};
|
|
||||||
//printf("Clipping rectangle has not been implemented yet\n");
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case CLAY_RENDER_COMMAND_TYPE_SCISSOR_END: {
|
case CLAY_RENDER_COMMAND_TYPE_SCISSOR_END: {
|
||||||
//printf("Clipping rectangle has not been implemented yet\n");
|
RSGL_renderScissorEnd();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case CLAY_RENDER_COMMAND_TYPE_CUSTOM:
|
||||||
|
printf("Custom render commands have not been implemented yet\n");
|
||||||
|
break;
|
||||||
default: {
|
default: {
|
||||||
fprintf(stderr, "Error: unhandled render command: %d\n", renderCommand->commandType);
|
fprintf(stderr, "Error: unhandled render command: %d\n", renderCommand->commandType);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user