mirror of
https://github.com/nicbarker/clay.git
synced 2025-05-16 23:38:08 +00:00
Compare commits
7 Commits
4a18440573
...
832930cef9
Author | SHA1 | Date | |
---|---|---|---|
|
832930cef9 | ||
|
5009146c65 | ||
|
cf97539612 | ||
|
c49593f1d3 | ||
|
c7703b7a50 | ||
|
ad363f986c | ||
|
3612431e82 |
@ -1,13 +1,13 @@
|
||||
cp ../../clay.h clay.c;
|
||||
# Intel Mac
|
||||
clang -c -DCLAY_IMPLEMENTATION -o clay.o -ffreestanding -static -target x86_64-apple-darwin clay.c -fPIC && ar r clay-odin/macos/clay.a clay.o;
|
||||
clang -c -DCLAY_IMPLEMENTATION -o clay.o -ffreestanding -static -target x86_64-apple-darwin clay.c -fPIC -O3 && ar r clay-odin/macos/clay.a clay.o;
|
||||
# ARM Mac
|
||||
clang -c -DCLAY_IMPLEMENTATION -g -o clay.o -static clay.c -fPIC && ar r clay-odin/macos-arm64/clay.a clay.o;
|
||||
clang -c -DCLAY_IMPLEMENTATION -g -o clay.o -static clay.c -fPIC -O3 && ar r clay-odin/macos-arm64/clay.a clay.o;
|
||||
# x64 Windows
|
||||
clang -c -DCLAY_IMPLEMENTATION -o clay-odin/windows/clay.lib -ffreestanding -target x86_64-pc-windows-msvc -fuse-ld=llvm-lib -static clay.c;
|
||||
clang -c -DCLAY_IMPLEMENTATION -o clay-odin/windows/clay.lib -ffreestanding -target x86_64-pc-windows-msvc -fuse-ld=llvm-lib -static -O3 clay.c;
|
||||
# Linux
|
||||
clang -c -DCLAY_IMPLEMENTATION -o clay.o -ffreestanding -static -target x86_64-unknown-linux-gnu clay.c -fPIC && ar r clay-odin/linux/clay.a clay.o;
|
||||
clang -c -DCLAY_IMPLEMENTATION -o clay.o -ffreestanding -static -target x86_64-unknown-linux-gnu clay.c -fPIC -O3 && ar r clay-odin/linux/clay.a clay.o;
|
||||
# WASM
|
||||
clang -c -DCLAY_IMPLEMENTATION -o clay-odin/wasm/clay.o -target wasm32 -nostdlib -static clay.c;
|
||||
clang -c -DCLAY_IMPLEMENTATION -o clay-odin/wasm/clay.o -target wasm32 -nostdlib -static -O3 clay.c;
|
||||
rm clay.o;
|
||||
rm clay.c;
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -50,4 +50,6 @@ int main(void) {
|
||||
Clay_Raylib_Render(renderCommands, fonts);
|
||||
EndDrawing();
|
||||
}
|
||||
// This function is new since the video was published
|
||||
Clay_Raylib_Close();
|
||||
}
|
||||
|
@ -72,4 +72,6 @@ int main(void) {
|
||||
Clay_Raylib_Render(renderCommandsBottom, fonts);
|
||||
EndDrawing();
|
||||
}
|
||||
|
||||
Clay_Raylib_Close();
|
||||
}
|
||||
|
@ -250,5 +250,6 @@ int main(void) {
|
||||
}
|
||||
UpdateDrawFrame(fonts);
|
||||
}
|
||||
Clay_Raylib_Close();
|
||||
return 0;
|
||||
}
|
||||
|
@ -125,6 +125,21 @@ void Clay_Raylib_Initialize(int width, int height, const char *title, unsigned i
|
||||
// EnableEventWaiting();
|
||||
}
|
||||
|
||||
// A MALLOC'd buffer, that we keep modifying inorder to save from so many Malloc and Free Calls.
|
||||
// Call Clay_Raylib_Close() to free
|
||||
static char *temp_render_buffer = NULL;
|
||||
static int temp_render_buffer_len = 0;
|
||||
|
||||
// Call after closing the window to clean up the render buffer
|
||||
void Clay_Raylib_Close()
|
||||
{
|
||||
if(temp_render_buffer) free(temp_render_buffer);
|
||||
temp_render_buffer_len = 0;
|
||||
|
||||
CloseWindow();
|
||||
}
|
||||
|
||||
|
||||
void Clay_Raylib_Render(Clay_RenderCommandArray renderCommands, Font* fonts)
|
||||
{
|
||||
for (int j = 0; j < renderCommands.length; j++)
|
||||
@ -134,14 +149,23 @@ void Clay_Raylib_Render(Clay_RenderCommandArray renderCommands, Font* fonts)
|
||||
switch (renderCommand->commandType)
|
||||
{
|
||||
case CLAY_RENDER_COMMAND_TYPE_TEXT: {
|
||||
// Raylib uses standard C strings so isn't compatible with cheap slices, we need to clone the string to append null terminator
|
||||
Clay_TextRenderData *textData = &renderCommand->renderData.text;
|
||||
char *cloned = (char *)malloc(textData->stringContents.length + 1);
|
||||
memcpy(cloned, textData->stringContents.chars, textData->stringContents.length);
|
||||
cloned[textData->stringContents.length] = '\0';
|
||||
Font fontToUse = fonts[textData->fontId];
|
||||
DrawTextEx(fontToUse, cloned, (Vector2){boundingBox.x, boundingBox.y}, (float)textData->fontSize, (float)textData->letterSpacing, CLAY_COLOR_TO_RAYLIB_COLOR(textData->textColor));
|
||||
free(cloned);
|
||||
|
||||
int strlen = textData->stringContents.length + 1;
|
||||
|
||||
if(strlen > temp_render_buffer_len) {
|
||||
// Grow the temp buffer if we need a larger string
|
||||
if(temp_render_buffer) free(temp_render_buffer);
|
||||
temp_render_buffer = malloc(strlen);
|
||||
temp_render_buffer_len = strlen;
|
||||
}
|
||||
|
||||
// Raylib uses standard C strings so isn't compatible with cheap slices, we need to clone the string to append null terminator
|
||||
memcpy(temp_render_buffer, textData->stringContents.chars, textData->stringContents.length);
|
||||
temp_render_buffer[textData->stringContents.length] = '\0';
|
||||
DrawTextEx(fontToUse, temp_render_buffer, (Vector2){boundingBox.x, boundingBox.y}, (float)textData->fontSize, (float)textData->letterSpacing, CLAY_COLOR_TO_RAYLIB_COLOR(textData->textColor));
|
||||
|
||||
break;
|
||||
}
|
||||
case CLAY_RENDER_COMMAND_TYPE_IMAGE: {
|
||||
|
Loading…
Reference in New Issue
Block a user