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(-) (limited to 'Makefile') 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(-) (limited to 'Makefile') 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