From 7ce483f69719ffe4a121cbfc716210fea9c4b2db Mon Sep 17 00:00:00 2001 From: Peter0x44 Date: Thu, 20 Jun 2024 22:43:19 +0100 Subject: Bump raygui and raylib to latest --- raygui | 2 +- raylib | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/raygui b/raygui index 9c826f2..0f832e6 160000 --- a/raygui +++ b/raygui @@ -1 +1 @@ -Subproject commit 9c826f213f5b287159a0b0e1a0670a27c09dcc7e +Subproject commit 0f832e6a6edfa77a93c327617468b15755cb05ce diff --git a/raylib b/raylib index 3ebfee5..52f2a10 160000 --- a/raylib +++ b/raylib @@ -1 +1 @@ -Subproject commit 3ebfee5dbc1d0de5555105f4989954cd4547bafd +Subproject commit 52f2a10db610d0e9f619fd7c521db08a876547d0 -- cgit v1.2.3 From 88dc4235569c19dd60650f78b9502c6826e23225 Mon Sep 17 00:00:00 2001 From: Peter0x44 Date: Thu, 20 Jun 2024 22:59:07 +0100 Subject: Fix compilation with latest raygui --- main.c | 48 ++++++++++++++++++++++++------------------------ 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/main.c b/main.c index ca0a70d..fe26730 100644 --- a/main.c +++ b/main.c @@ -91,8 +91,8 @@ Vector2 dtpOrigin = { .x = 0, .y = 0 }; -int predtpRotation; -int dtpRotation = 0; +float predtpRotation; +float dtpRotation = 0; const int gridSize = 20; const int gridCenter = 120; @@ -330,7 +330,7 @@ void DrawUI() { ); sprintf(buffer, "%d", (int)dtpSource.x), - dtpSource.x = GuiSlider( + GuiSlider( (Rectangle) { .x = elementSliders.x + xOffset, .y = elementSliders.y + yOffset, @@ -339,12 +339,12 @@ void DrawUI() { }, "x", buffer, - dtpSource.x, + &dtpSource.x, -192, 192 ); sprintf(buffer, "%d", (int)dtpSource.y), - dtpSource.y = GuiSlider( + GuiSlider( (Rectangle) { .x = elementSliders.x + xOffset, .y = elementSliders.y + yOffset + sliderHeight + sliderSpacing, @@ -353,12 +353,12 @@ void DrawUI() { }, "y", buffer, - dtpSource.y, + &dtpSource.y, -192, 192 ); sprintf(buffer, "%d", (int)dtpSource.width), - dtpSource.width = GuiSlider( + GuiSlider( (Rectangle) { .x = elementSliders.x + xOffset, .y = elementSliders.y + yOffset + ((sliderHeight + sliderSpacing) * 2), @@ -367,12 +367,12 @@ void DrawUI() { }, "Width", buffer, - dtpSource.width, + &dtpSource.width, -192, 192 ); sprintf(buffer, "%d", (int)dtpSource.height), - dtpSource.height = GuiSlider( + GuiSlider( (Rectangle) { .x = elementSliders.x + xOffset, .y = elementSliders.y + yOffset + ((sliderHeight + sliderSpacing) * 3), @@ -381,7 +381,7 @@ void DrawUI() { }, "Height", buffer, - dtpSource.height, + &dtpSource.height, -192, 192 ); @@ -398,7 +398,7 @@ void DrawUI() { "Dest" ); sprintf(buffer, "%d", (int)dtpDest.x), - dtpDest.x = GuiSlider( + GuiSlider( (Rectangle) { .x = elementSliders.x + xOffset, .y = elementSliders.y + yOffset, @@ -407,12 +407,12 @@ void DrawUI() { }, "x", buffer, - dtpDest.x, + &dtpDest.x, -192, 192 ); sprintf(buffer, "%d", (int)dtpDest.y), - dtpDest.y = GuiSlider( + GuiSlider( (Rectangle) { .x = elementSliders.x + xOffset, .y = elementSliders.y + yOffset + sliderHeight + sliderSpacing, @@ -421,12 +421,12 @@ void DrawUI() { }, "y", buffer, - dtpDest.y, + &dtpDest.y, -192, 192 ); sprintf(buffer, "%d", (int)dtpDest.width), - dtpDest.width = GuiSlider( + GuiSlider( (Rectangle) { .x = elementSliders.x + xOffset, .y = elementSliders.y + yOffset + ((sliderHeight + sliderSpacing) * 2), @@ -435,12 +435,12 @@ void DrawUI() { }, "Width", buffer, - dtpDest.width, + &dtpDest.width, -192, 192 ); sprintf(buffer, "%d", (int)dtpDest.height), - dtpDest.height = GuiSlider( + GuiSlider( (Rectangle) { .x = elementSliders.x + xOffset, .y = elementSliders.y + yOffset + ((sliderHeight + sliderSpacing) * 3), @@ -449,7 +449,7 @@ void DrawUI() { }, "Height", buffer, - dtpDest.height, + &dtpDest.height, -192, 192 ); @@ -465,7 +465,7 @@ void DrawUI() { "Origin" ); sprintf(buffer, "%d", (int)dtpOrigin.x), - dtpOrigin.x = GuiSlider( + GuiSlider( (Rectangle) { .x = elementSliders.x + xOffset, .y = elementSliders.y + yOffset, @@ -474,12 +474,12 @@ void DrawUI() { }, "x", buffer, - dtpOrigin.x, + &dtpOrigin.x, -192, 192 ); sprintf(buffer, "%d", (int)dtpOrigin.y), - dtpOrigin.y = GuiSlider( + GuiSlider( (Rectangle) { .x = elementSliders.x + xOffset, .y = elementSliders.y + yOffset + sliderHeight + sliderSpacing, @@ -488,7 +488,7 @@ void DrawUI() { }, "y", buffer, - dtpOrigin.y, + &dtpOrigin.y, -192, 192 ); @@ -505,7 +505,7 @@ void DrawUI() { "Rotation" ); sprintf(buffer, "%d", (int)dtpRotation), - dtpRotation = GuiSlider( + GuiSlider( (Rectangle) { .x = elementSliders.x + xOffset, .y = elementSliders.y + yOffset, @@ -514,7 +514,7 @@ void DrawUI() { }, "", buffer, - dtpRotation, + &dtpRotation, -360, 360 ); -- cgit v1.2.3 From 640693705326544bc05437c9788e8d3ef8f4f254 Mon Sep 17 00:00:00 2001 From: Peter0x44 Date: Thu, 20 Jun 2024 23:36:20 +0100 Subject: Make GUI look the same as it did before I'm not sure why, but setting the font and spacing in the rgs wasn't working. Just do it in code. --- assets/lavanda.rgs | Bin 4541 -> 0 bytes assets/style_lavanda.rgs | Bin 0 -> 4322 bytes main.c | 4 +++- 3 files changed, 3 insertions(+), 1 deletion(-) delete mode 100644 assets/lavanda.rgs create mode 100644 assets/style_lavanda.rgs diff --git a/assets/lavanda.rgs b/assets/lavanda.rgs deleted file mode 100644 index 3aa3e6f..0000000 Binary files a/assets/lavanda.rgs and /dev/null differ diff --git a/assets/style_lavanda.rgs b/assets/style_lavanda.rgs new file mode 100644 index 0000000..4b18673 Binary files /dev/null and b/assets/style_lavanda.rgs differ diff --git a/main.c b/main.c index fe26730..2b1677c 100644 --- a/main.c +++ b/main.c @@ -116,12 +116,14 @@ int main() { InitWindow(screenWidth, screenHeight, "DrawTexturePro Example"); SetTargetFPS(60); - GuiLoadStyle("assets/lavanda.rgs"); + GuiLoadStyle("assets/style_lavanda.rgs"); sampleSprite = LoadTexture("assets/kenney.png"); sourceCodeFont = LoadFontEx("assets/LiberationMono-Regular.ttf", fontSize, 0, 250); GuiSetFont(sourceCodeFont); + GuiSetStyle(DEFAULT, TEXT_SIZE, fontSize); + GuiSetStyle(DEFAULT, TEXT_SPACING, fontSpacing); for(i = 0; i < 21; i += 1) { codePreviewHighlight[i] = BEIGE; -- cgit v1.2.3 From 8ed354f7fb32b064b5f082adc127011cca078077 Mon Sep 17 00:00:00 2001 From: Peter0x44 Date: Thu, 20 Jun 2024 23:38:43 +0100 Subject: Use OpenGL ES3 for GL_REPEAT Specifying a larger source rectangle than the texture only works if GL_REPEAT does, and GL_REPEAT only works on OpenGL ES3 Raylib must be built with GRAPHICS=GRAPHICS_API_OPENGL_ES3 for this to work on web. --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index aec7883..e673e5f 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ desktop: zig cc -target native main.c -o game -lGL -lm -lpthread -ldl -lrt -lX11 -Iraylib/src -Iraygui/src lib/tux/libraylib.a && ./game web: - emcc -Os -Wall main.c -o game -Iraylib/src -Iraygui/src lib/web/libraylib.a -o output/index.html -s USE_GLFW=3 -DPLATFORM_WEB --shell-file raylib/src/minshell.html -s TOTAL_MEMORY=268435456 -s ASYNCIFY --preload-file ./assets + emcc -Os -Wall main.c -o game -Iraylib/src -Iraygui/src lib/web/libraylib.a -o output/index.html -s USE_GLFW=3 -s FULL_ES3 -DPLATFORM_WEB --shell-file raylib/src/minshell.html -s TOTAL_MEMORY=268435456 -s ASYNCIFY --preload-file ./assets -- cgit v1.2.3 From 7703f2a74122c771070f19259fc40eb2167df9ac Mon Sep 17 00:00:00 2001 From: Peter0x44 Date: Fri, 21 Jun 2024 00:05:07 +0100 Subject: Refactor code to use emscripten_set_main_loop Supposed to give better perf, better to leave frame control to the browser. --- Makefile | 2 +- main.c | 42 +++++++++++++++++++++++++++--------------- 2 files changed, 28 insertions(+), 16 deletions(-) diff --git a/Makefile b/Makefile index e673e5f..2444ff5 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ desktop: zig cc -target native main.c -o game -lGL -lm -lpthread -ldl -lrt -lX11 -Iraylib/src -Iraygui/src lib/tux/libraylib.a && ./game web: - emcc -Os -Wall main.c -o game -Iraylib/src -Iraygui/src lib/web/libraylib.a -o output/index.html -s USE_GLFW=3 -s FULL_ES3 -DPLATFORM_WEB --shell-file raylib/src/minshell.html -s TOTAL_MEMORY=268435456 -s ASYNCIFY --preload-file ./assets + emcc -Os -Wall main.c -o game -Iraylib/src -Iraygui/src lib/web/libraylib.a -o output/index.html -s USE_GLFW=3 -s FULL_ES3 -DPLATFORM_WEB --shell-file raylib/src/minshell.html -s TOTAL_MEMORY=268435456 --preload-file ./assets diff --git a/main.c b/main.c index 2b1677c..9d65338 100644 --- a/main.c +++ b/main.c @@ -8,6 +8,10 @@ #include "raylib.h" #include +#ifdef __EMSCRIPTEN__ +#include +#endif + #define RAYGUI_IMPLEMENTATION #include "raygui.h" @@ -112,6 +116,24 @@ void DrawOutput(); void HandleDroppedFiles(); +void UpdateDrawFrame() +{ + HandleDroppedFiles(); + + BeginDrawing(); + ClearBackground(RAYWHITE); + + DrawElementBorders(); + SetupDifference(); + DrawUI(); + ResolveMouseState(); + DrawCodeDisplay(); + CheckDifference(); + DrawOutput(); + + EndDrawing(); +} + int main() { InitWindow(screenWidth, screenHeight, "DrawTexturePro Example"); @@ -139,24 +161,14 @@ int main() elementRender.height - 20 ); - +#ifdef __EMSCRIPTEN__ + emscripten_set_main_loop(UpdateDrawFrame, 0, 1); +#else while (!WindowShouldClose()) { - HandleDroppedFiles(); - - BeginDrawing(); - ClearBackground(RAYWHITE); - - DrawElementBorders(); - SetupDifference(); - DrawUI(); - ResolveMouseState(); - DrawCodeDisplay(); - CheckDifference(); - DrawOutput(); - - EndDrawing(); + UpdateDrawFrame(); } +#endif CloseWindow(); return 0; -- cgit v1.2.3