From c0047b159ab3175fc5402e8c0311f591afb0871d Mon Sep 17 00:00:00 2001 From: jdeokkim Date: Mon, 25 Nov 2024 14:20:36 +0900 Subject: [PATCH 1/3] Add Makefile.emcc --- Makefile | 8 +- Makefile.emcc | 59 ++++++++++ README.md | 278 +++++++++++++++++++++++++------------------- res/html/shell.html | 68 +++++++++++ src/main.c | 126 +++++++++++--------- 5 files changed, 357 insertions(+), 182 deletions(-) create mode 100644 Makefile.emcc create mode 100644 res/html/shell.html diff --git a/Makefile b/Makefile index edd5982..f8ae990 100644 --- a/Makefile +++ b/Makefile @@ -23,7 +23,7 @@ # ============================================================================= .PHONY: all clean rebuild -.SUFFIXES: .c .exe .out +.SUFFIXES: .c .exe .html .out # ============================================================================= @@ -82,7 +82,7 @@ build: ${TARGETS} ${TARGETS}: ${OBJECTS} @mkdir -p ${BINARY_PATH} @printf "${LOG_PREFIX} Linking: ${TARGETS}\n" - @${CC} ${OBJECTS} -o ${TARGETS} ${LDFLAGS} ${LDLIBS} + @${CC} ${OBJECTS} -o ${TARGETS} ${LDFLAGS} ${LDLIBS} ${WEBFLAGS} post-build: @printf "${LOG_PREFIX} Build complete.\n" @@ -95,6 +95,8 @@ rebuild: clean all clean: @printf "${LOG_PREFIX} Cleaning up.\n" - @rm -f ${BINARY_PATH}/*.exe ${BINARY_PATH}/*.out ${SOURCE_PATH}/*.o + @rm -f ${BINARY_PATH}/*.data ${BINARY_PATH}/*.exe ${BINARY_PATH}/*.html \ + ${BINARY_PATH}/*.js ${BINARY_PATH}/*.out ${BINARY_PATH}/*.wasm \ + ${SOURCE_PATH}/*.o # ============================================================================= diff --git a/Makefile.emcc b/Makefile.emcc new file mode 100644 index 0000000..be20675 --- /dev/null +++ b/Makefile.emcc @@ -0,0 +1,59 @@ +# +# Copyright (c) 2024 Jaedeok Kim +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. +# + +# ============================================================================= + +.PHONY: all clean rebuild + +# ============================================================================= + +# TODO: Edit these values to match your raylib installation path! +RAYLIB_INCLUDE_PATH = ../raylib/src +RAYLIB_LIBRARY_PATH = ../raylib/src + +BINARY_PATH = bin +INCLUDE_PATH = include +LIBRARY_PATH = lib +RESOURCE_PATH = res +SOURCE_PATH = src + +TARGET_SUFFIX = html + +# ============================================================================= + +CC = emcc +CFLAGS = -D_DEFAULT_SOURCE -g -I${INCLUDE_PATH} -I${RAYLIB_INCLUDE_PATH} \ + -I${INCLUDE_PATH}/raygui -I${RESOURCE_PATH} -O2 -std=gnu99 +LDFLAGS = -L${RAYLIB_LIBRARY_PATH} +LDLIBS = -lraylib -ldl -lGL -lm -lpthread -lrt -lX11 +WEBFLAGS = -s FORCE_FILESYSTEM -s INITIAL_MEMORY=67108864 -s USE_GLFW=3 \ + --preload-file ${RESOURCE_PATH} --shell-file ${RESOURCE_PATH}/html/shell.html + +CFLAGS += -Wno-limited-postlink-optimizations + +# ============================================================================= + +all clean rebuild: + @${MAKE} TARGET_SUFFIX=${TARGET_SUFFIX} CC=${CC} CFLAGS="${CFLAGS}" \ + LDFLAGS="${LDFLAGS}" LDLIBS="${LDLIBS}" WEBFLAGS="${WEBFLAGS}" $@ + +# ============================================================================= diff --git a/README.md b/README.md index cf2ef87..c72680a 100644 --- a/README.md +++ b/README.md @@ -1,121 +1,157 @@ -# MVP Transform Visualizer - - - -> "The engines don’t move the ship at all. -> -> **The ship stays where it is and the engines move the universe around it.**" -> -> — Futurama - -A [raylib](https://github.com/raysan5/raylib) demo to visualize the Model, View, and Projection (MVP) matrices. - -This project is a C rewrite of [@diskhkme](https://github.com/diskhkme)'s [MVP Transform Visualizer](https://github.com/diskhkme/mvp_transform_visualize) with additional features, for the "Computer Graphics" (1214-3005) course at Chungnam National University. - -https://github.com/user-attachments/assets/a0420cad-6b93-4dd6-bae3-fefab8ae3819 - -## Controls - -- `ALT` + `0`: Draw All Spaces -- `ALT` + `1`: Draw Local Space -- `ALT` + `2`: Draw World Space -- `ALT` + `3`: Draw View Space -- `ALT` + `4`: Draw Clip Space -- `ESC`: Lock/Unlock Observer Camera -- `V`: Show/Hide Player Model Vertices - -## Prerequisites - -- GCC version 11.4.0+ -- Git version 2.34.0+ -- GNU Make version 4.3+ -- raylib 5.0+ - -## Building - -
-Compiling for Windows - -### [w64devkit](https://github.com/skeeto/w64devkit) - -Download the latest release of w64devkit from [here](https://github.com/skeeto/w64devkit/releases), extract the `.zip` file to your working directory, and run `w64devkit.exe`. - -```console -$ cd .. && wget https://github.com/raysan5/raylib/archive/refs/tags/5.0.zip -$ unzip 5.0.zip && mv raylib-5.0 raylib -$ cd raylib/src && make -``` - -```console -$ git clone https://github.com/jdeokkim/mvp-demo -$ cd mvp-demo && make -f Makefile.mingw -``` - -
- -
-Compiling for GNU/Linux - -### Debian / Ubuntu - -```console -$ sudo apt update && sudo apt install libasound2-dev libgl1-mesa-dev \ - libglu1-mesa-dev libx11-dev libxrandr-dev libxi-dev libxcursor-dev \ - libxinerama-dev libxkbcommon-dev -$ git clone https://github.com/raysan5/raylib ~/raylib && cd ~/raylib/src -$ make PLATFORM=PLATFORM_DESKTOP GLFW_LINUX_ENABLE_WAYLAND=OFF && make install -``` - -```console -$ git clone https://github.com/jdeokkim/mvp-demo -$ cd mvp-demo && make -``` - -
- -
-Cross-compiling from GNU/Linux to Windows (WSL2) - -### Debian / Ubuntu - -```console -$ sudo apt install mingw-w64 -$ git clone https://github.com/raysan5/raylib && cd raylib/src -$ make CC=x86_64-w64-mingw32-gcc AR=x86_64-w64-mingw32-ar OS=Windows_NT -``` - -```console -$ git clone https://github.com/jdeokkim/mvp-demo -$ cd mvp-demo && make -f Makefile.mingw -``` - -
- -## License - -MIT License - -``` -Copyright (c) 2024 Jaedeok Kim -Copyright (c) 2024 Minhu Lee - -Copyright (c) 2024 Hyungki Kim - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -``` +# MVP Transform Visualizer + + + +> "The engines don’t move the ship at all. +> +> **The ship stays where it is and the engines move the universe around it.**" +> +> — Futurama + +A [raylib](https://github.com/raysan5/raylib) demo to visualize the Model, View, and Projection (MVP) matrices. + +This project is a C rewrite of [@diskhkme](https://github.com/diskhkme)'s [MVP Transform Visualizer](https://github.com/diskhkme/mvp_transform_visualize) with additional features, for the "Computer Graphics" (1214-3005) course at [Chungnam National University](https://computer.cnu.ac.kr/). + +https://github.com/user-attachments/assets/a0420cad-6b93-4dd6-bae3-fefab8ae3819 + +## Controls + +- `ALT` + `0`: Draw All Spaces +- `ALT` + `1`: Draw Local Space +- `ALT` + `2`: Draw World Space +- `ALT` + `3`: Draw View Space +- `ALT` + `4`: Draw Clip Space +- `ESC`: Lock/Unlock Observer Camera +- `V`: Show/Hide Player Model Vertices + +## Prerequisites + +- GCC version 11.4.0+ +- Git version 2.34.0+ +- GNU Make version 4.3+ +- raylib 5.0+ + +## Building + +
+Compiling for Windows + +### [w64devkit](https://github.com/skeeto/w64devkit) + +Download the latest release of w64devkit from [here](https://github.com/skeeto/w64devkit/releases), extract the `.zip` file to your working directory, and run `w64devkit.exe`. + +```console +$ cd .. && wget https://github.com/raysan5/raylib/archive/refs/tags/5.0.zip +$ unzip 5.0.zip && mv raylib-5.0 raylib +$ cd raylib/src && make +``` + +```console +$ git clone https://github.com/jdeokkim/mvp-demo +$ cd mvp-demo && make -f Makefile.mingw +``` + +
+ + + +
+Compiling for GNU/Linux + +### Debian / Ubuntu + +```console +$ sudo apt update && sudo apt install libasound2-dev libgl1-mesa-dev \ + libglu1-mesa-dev libx11-dev libxrandr-dev libxi-dev libxcursor-dev \ + libxinerama-dev libxkbcommon-dev +$ git clone https://github.com/raysan5/raylib ~/raylib && cd ~/raylib/src +$ make PLATFORM=PLATFORM_DESKTOP GLFW_LINUX_ENABLE_WAYLAND=OFF && make install +``` + +```console +$ git clone https://github.com/jdeokkim/mvp-demo +$ cd mvp-demo && make +``` + +
+ + + +
+Compiling for the Web (LLVM-to-WebAssembly) + +Compiling for the Web requires installation of the [Emscripten SDK](https://emscripten.org/docs/getting_started/downloads.html). + +### Debian / Ubuntu + +```console +$ git clone git clone https://github.com/emscripten-core/emsdk && cd emsdk +$ ./emsdk install latest +$ ./emsdk activate latest +$ source ./emsdk_env.sh +``` + +Then, you must recompile raylib for the Web: + +```console +$ git clone https://github.com/raysan5/raylib && cd raylib/src +$ make -j`nproc` PLATFORM=PLATFORM_WEB -B +``` + +Finally, in order to build this project, do: + +``` +$ git clone https://github.com/jdeokkim/mvp-demo +$ cd mvp-demo && make -f Makefile.emcc +``` + +
+ + + +
+Cross-compiling from GNU/Linux to Windows (WSL2) + +### Debian / Ubuntu + +```console +$ sudo apt install mingw-w64 +$ git clone https://github.com/raysan5/raylib && cd raylib/src +$ make CC=x86_64-w64-mingw32-gcc AR=x86_64-w64-mingw32-ar OS=Windows_NT +``` + +```console +$ git clone https://github.com/jdeokkim/mvp-demo +$ cd mvp-demo && make -f Makefile.mingw +``` + +
+ +## License + +MIT License + +``` +Copyright (c) 2024 Jaedeok Kim +Copyright (c) 2024 Minhu Lee + +Copyright (c) 2024 Hyungki Kim + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +``` diff --git a/res/html/shell.html b/res/html/shell.html new file mode 100644 index 0000000..993a391 --- /dev/null +++ b/res/html/shell.html @@ -0,0 +1,68 @@ + + + + + + + jdeokkim/mvp-demo: A raylib demo to visualize the Model, View, and Projection (MVP) matrices + + + + + + + + + + +

+ + + + {{{ SCRIPT }}} + + \ No newline at end of file diff --git a/src/main.c b/src/main.c index c81e3e9..d59e94d 100644 --- a/src/main.c +++ b/src/main.c @@ -1,59 +1,69 @@ -/* - Copyright (c) 2024 Jaedeok Kim - Copyright (c) 2024 Minhu Lee - - Copyright (c) 2024 Jaedeok Kim - - Permission is hereby granted, free of charge, to any person obtaining a - copy of this software and associated documentation files (the "Software"), - to deal in the Software without restriction, including without limitation - the rights to use, copy, modify, merge, publish, distribute, sublicense, - and/or sell copies of the Software, and to permit persons to whom the - Software is furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included - in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - DEALINGS IN THE SOFTWARE. -*/ - -/* Includes ================================================================ */ - -#include "mvp-demo.h" - -/* Public Functions ======================================================== */ - -int main(void) { - // MSAA 4x 안티-에일리어싱 (anti-aliasing) 기능 활성화 - SetConfigFlags(FLAG_MSAA_4X_HINT); - - // 게임 창 생성 및 OpenGL 컨텍스트 (context) 초기화 - InitWindow(SCREEN_WIDTH, SCREEN_HEIGHT, WINDOW_TITLE); - - // 종료 키 설정 (비활성화) - SetExitKey(KEY_NULL); - - // 게임의 최대 FPS 설정 - SetTargetFPS(TARGET_FPS); - - { - InitGameScreen(); - - // 게임 창의 '닫기' 버튼 또는 'ESC' 키가 눌리기 전까지... - while (!WindowShouldClose()) - UpdateGameScreen(); - - DeinitGameScreen(); - } - - // 게임 창 제거 및 OpenGL 컨텍스트에 할당된 메모리 해제 - CloseWindow(); - - return 0; +/* + Copyright (c) 2024 Jaedeok Kim + Copyright (c) 2024 Minhu Lee + + Copyright (c) 2024 Jaedeok Kim + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. +*/ + +/* Includes ================================================================ */ + +#include "mvp-demo.h" + +#ifdef PLATFORM_WEB + #include +#endif + +/* Public Functions ======================================================== */ + +int main(void) { + // MSAA 4x 안티-에일리어싱 (anti-aliasing) 기능 활성화 + SetConfigFlags(FLAG_MSAA_4X_HINT); + + // 게임 창 생성 및 OpenGL 컨텍스트 (context) 초기화 + InitWindow(SCREEN_WIDTH, SCREEN_HEIGHT, WINDOW_TITLE); + + // 종료 키 설정 (비활성화) + SetExitKey(KEY_NULL); + + // 게임의 최대 FPS 설정 + SetTargetFPS(TARGET_FPS); + + { + InitGameScreen(); + +#ifdef PLATFORM_WEB + emscripten_set_main_loop(UpdateGameScreen, 0, 1); +#else + SetTargetFPS(TARGET_FPS); + + // 게임 창의 '닫기' 버튼 또는 'ESC' 키가 눌리기 전까지... + while (!WindowShouldClose()) + UpdateGameScreen(); +#endif + + DeinitGameScreen(); + } + + // 게임 창 제거 및 OpenGL 컨텍스트에 할당된 메모리 해제 + CloseWindow(); + + return 0; } \ No newline at end of file From ddf5a7a51f91ed79c9a26bd1d31218ef77252470 Mon Sep 17 00:00:00 2001 From: jdeokkim Date: Tue, 3 Dec 2024 15:19:51 +0900 Subject: [PATCH 2/3] Update Makefile.* --- Makefile | 4 ++-- Makefile.emcc | 4 ++-- Makefile.mingw | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index f8ae990..ebecd14 100644 --- a/Makefile +++ b/Makefile @@ -8,8 +8,8 @@ # copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # -# The above copyright notice and this permission notice shall be included in all -# copies or substantial portions of the Software. +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, diff --git a/Makefile.emcc b/Makefile.emcc index be20675..8bec50d 100644 --- a/Makefile.emcc +++ b/Makefile.emcc @@ -8,8 +8,8 @@ # copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # -# The above copyright notice and this permission notice shall be included in all -# copies or substantial portions of the Software. +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, diff --git a/Makefile.mingw b/Makefile.mingw index 4134db5..bc988c8 100644 --- a/Makefile.mingw +++ b/Makefile.mingw @@ -8,8 +8,8 @@ # copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # -# The above copyright notice and this permission notice shall be included in all -# copies or substantial portions of the Software. +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, From 3e814a7974334f7c8f5790b65be94174dcac361b Mon Sep 17 00:00:00 2001 From: jdeokkim Date: Sat, 21 Dec 2024 21:09:21 +0900 Subject: [PATCH 3/3] Update shaders for OpenGL ES 3.0 --- .gitignore | 1 + Makefile.emcc | 10 +++-- README.md | 4 +- include/mvp-demo.h | 5 +++ include/raygui/raygui.h | 71 ++++++++++++++++++----------------- res/shaders/preload_shaders.h | 49 +++++++++++++++--------- src/utils.c | 37 +++++++++++++++++- 7 files changed, 117 insertions(+), 60 deletions(-) diff --git a/.gitignore b/.gitignore index 19505e4..5146a04 100644 --- a/.gitignore +++ b/.gitignore @@ -25,6 +25,7 @@ # 설정 파일 *.manifest +**/bin/ **/.vs/ **/.vscode/ diff --git a/Makefile.emcc b/Makefile.emcc index 8bec50d..c289c53 100644 --- a/Makefile.emcc +++ b/Makefile.emcc @@ -41,12 +41,14 @@ TARGET_SUFFIX = html # ============================================================================= CC = emcc -CFLAGS = -D_DEFAULT_SOURCE -g -I${INCLUDE_PATH} -I${RAYLIB_INCLUDE_PATH} \ - -I${INCLUDE_PATH}/raygui -I${RESOURCE_PATH} -O2 -std=gnu99 +CFLAGS = -D_DEFAULT_SOURCE -DPLATFORM_WEB -g -I${INCLUDE_PATH} \ + -I${RAYLIB_INCLUDE_PATH} -I${INCLUDE_PATH}/raygui -I${RESOURCE_PATH} \ + -O2 -std=gnu99 LDFLAGS = -L${RAYLIB_LIBRARY_PATH} LDLIBS = -lraylib -ldl -lGL -lm -lpthread -lrt -lX11 -WEBFLAGS = -s FORCE_FILESYSTEM -s INITIAL_MEMORY=67108864 -s USE_GLFW=3 \ - --preload-file ${RESOURCE_PATH} --shell-file ${RESOURCE_PATH}/html/shell.html +WEBFLAGS = -s FORCE_FILESYSTEM -s FULL_ES3 -s INITIAL_MEMORY=67108864 \ + -s USE_GLFW=3 --preload-file ${RESOURCE_PATH} \ + --shell-file ${RESOURCE_PATH}/html/shell.html CFLAGS += -Wno-limited-postlink-optimizations diff --git a/README.md b/README.md index 3f10dca..de64dee 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,7 @@ https://github.com/user-attachments/assets/4b7cda17-2f32-4651-9297-7070fb274da0 - GCC version 11.4.0+ - Git version 2.34.0+ - GNU Make version 4.3+ -- raylib 5.0+ +- raylib 5.5+ ## Building @@ -89,7 +89,7 @@ Then, you must recompile raylib for the Web: ```console $ git clone https://github.com/raysan5/raylib && cd raylib/src -$ make -j`nproc` PLATFORM=PLATFORM_WEB -B +$ make -j`nproc` PLATFORM=PLATFORM_WEB GRAPHICS=GRAPHICS_API_OPENGL_ES3 -B ``` Finally, in order to build this project, do: diff --git a/include/mvp-demo.h b/include/mvp-demo.h index 6d57303..d6c4cda 100644 --- a/include/mvp-demo.h +++ b/include/mvp-demo.h @@ -62,6 +62,11 @@ extern "C" { /* 게임 세계에 추가할 물체의 개수 */ #define GAME_OBJECT_COUNT 3 +/* 격자의 간격, 칸 개수와 각 선의 두께 */ +#define GRID_SPACING_VALUE 1.0f +#define GRID_SLICES_VALUE 256 +#define GRID_THICK_VALUE 0.03f + /* 레이블에 들어갈 문자열의 최대 길이 */ #define LABEL_TEXT_LENGTH 32 diff --git a/include/raygui/raygui.h b/include/raygui/raygui.h index a62487a..4985302 100644 --- a/include/raygui/raygui.h +++ b/include/raygui/raygui.h @@ -1469,6 +1469,7 @@ static bool CheckCollisionPointRec(Vector2 point, Rectangle rec); // Check if static const char *TextFormat(const char *text, ...); // Formatting of text with variables to 'embed' static const char **TextSplit(const char *text, char delimiter, int *count); // Split text into multiple strings static int TextToInteger(const char *text); // Get integer value from text +static float TextToFloat(const char *text); // Get float value from text static int GetCodepointNext(const char *text, int *codepointSize); // Get next codepoint in a UTF-8 encoded text static const char *CodepointToUTF8(int codepoint, int *byteSize); // Encode codepoint into UTF-8 text (char array size returned as parameter) @@ -1481,8 +1482,6 @@ static void DrawRectangleGradientV(int posX, int posY, int width, int height, Co //---------------------------------------------------------------------------------- // Module specific Functions Declaration //---------------------------------------------------------------------------------- -static float TextToFloat(const char *text); // Get float value from text - static void GuiLoadStyleFromMemory(const unsigned char *fileData, int dataSize); // Load style from memory (binary only) static int GetTextWidth(const char *text); // Gui get text width using gui font and style @@ -2150,7 +2149,9 @@ int GuiToggleSlider(Rectangle bounds, const char *text, int *active) // Get substrings items from text (items pointers) int itemCount = 0; - const char **items = GuiTextSplit(text, ';', &itemCount, NULL); + const char **items = NULL; + + if (text != NULL) items = GuiTextSplit(text, ';', &itemCount, NULL); Rectangle slider = { 0, // Calculated later depending on the active toggle @@ -2641,7 +2642,7 @@ int GuiTextBox(Rectangle bounds, char *text, int textSize, bool editMode) // Make sure text last character is EOL text[textLength] = '\0'; - } + } else if ((textLength > 0) && (IsKeyPressed(KEY_BACKSPACE) || (IsKeyDown(KEY_BACKSPACE) && (autoCursorCooldownCounter >= RAYGUI_TEXTBOX_AUTO_CURSOR_COOLDOWN)))) { autoCursorDelayCounter++; @@ -5521,37 +5522,6 @@ static Color GuiFade(Color color, float alpha) return result; } -// Get float value from text -// NOTE: This function replaces atof() [stdlib.h] -// WARNING: Only '.' character is understood as decimal point -static float TextToFloat(const char *text) -{ - float value = 0.0f; - float sign = 1.0f; - - if ((text[0] == '+') || (text[0] == '-')) - { - if (text[0] == '-') sign = -1.0f; - text++; - } - - int i = 0; - for (; ((text[i] >= '0') && (text[i] <= '9')); i++) value = value*10.0f + (float)(text[i] - '0'); - - if (text[i++] != '.') value *= sign; - else - { - float divisor = 10.0f; - for (; ((text[i] >= '0') && (text[i] <= '9')); i++) - { - value += ((float)(text[i] - '0'))/divisor; - divisor = divisor*10.0f; - } - } - - return value; -} - #if defined(RAYGUI_STANDALONE) // Returns a Color struct from hexadecimal value static Color GetColor(int hexValue) @@ -5673,6 +5643,37 @@ static int TextToInteger(const char *text) return value*sign; } +// Get float value from text +// NOTE: This function replaces atof() [stdlib.h] +// WARNING: Only '.' character is understood as decimal point +static float TextToFloat(const char *text) +{ + float value = 0.0f; + float sign = 1.0f; + + if ((text[0] == '+') || (text[0] == '-')) + { + if (text[0] == '-') sign = -1.0f; + text++; + } + + int i = 0; + for (; ((text[i] >= '0') && (text[i] <= '9')); i++) value = value*10.0f + (float)(text[i] - '0'); + + if (text[i++] != '.') value *= sign; + else + { + float divisor = 10.0f; + for (; ((text[i] >= '0') && (text[i] <= '9')); i++) + { + value += ((float)(text[i] - '0'))/divisor; + divisor = divisor*10.0f; + } + } + + return value; +} + // Encode codepoint into UTF-8 text (char array size returned as parameter) static const char *CodepointToUTF8(int codepoint, int *byteSize) { diff --git a/res/shaders/preload_shaders.h b/res/shaders/preload_shaders.h index 1873151..a06e97a 100644 --- a/res/shaders/preload_shaders.h +++ b/res/shaders/preload_shaders.h @@ -23,10 +23,17 @@ /* REF: https://dev.to/javiersalcedopuyo/simple-infinite-grid-shader-5fah */ /* 정점 셰이더 코드 */ -char resShadersCommonVsVert[] = "\n" -"/* Compilation Settings ================================================ */\n" +const char resShadersCommonVsVert[] = "" + +#ifdef PLATFORM_WEB +"#version 300 es\n" "\n" +"precision mediump float;\n" +"precision mediump int;\n" +#else "#version 330\n" +#endif + "\n" "/* Input Variables ===================================================== */\n" "\n" @@ -53,10 +60,10 @@ char resShadersCommonVsVert[] = "\n" "\n" "uniform vec3 cameraPosition;\n" "\n" -"uniform float spacing = 1.0;\n" -"uniform float thick = 0.03;\n" +"uniform float spacing;\n" +"uniform float thick;\n" "\n" -"uniform int slices = 1000;\n" +"uniform mediump int slices;\n" "\n" "/* Output Variables ==================================================== */\n" "\n" @@ -68,7 +75,7 @@ char resShadersCommonVsVert[] = "\n" "\n" "/* [variables assigned by raylib] =====================================> */\n" "\n" -"/* Constants ==========================================================> */\n" +"/* Private Variables ==================================================> */\n" "\n" "vec3 planeVertexPositions[] = vec3[](\n" " vec3(-0.5, 0.0, 0.5),\n" @@ -81,7 +88,8 @@ char resShadersCommonVsVert[] = "\n" "\n" "void main() {\n" " vec3 planeVertexPosition = planeVertexPositions[gl_VertexID];\n" -" vec3 newVertexPosition = (planeVertexPosition * spacing) * slices;\n" +" vec3 newVertexPosition = (planeVertexPosition * spacing)" +" * float(slices);\n" "\n" " newVertexPosition.xz += cameraPosition.xz;\n" "\n" @@ -93,10 +101,17 @@ char resShadersCommonVsVert[] = "\n" "}\n"; /* 프래그먼트 셰이더 코드 */ -char resShadersCommonFsFrag[] = "\n" -"/* Compilation Settings ================================================ */\n" +const char resShadersCommonFsFrag[] = "" + +#ifdef PLATFORM_WEB +"#version 300 es\n" "\n" +"precision mediump float;\n" +"precision mediump int;\n" +#else "#version 330\n" +#endif + "\n" "/* Input Variables ===================================================== */\n" "\n" @@ -140,14 +155,7 @@ char resShadersCommonFsFrag[] = "\n" "const vec3 redColor = vec3(0.90, 0.16, 0.21);\n" "const vec3 blueColor = vec3(0.0, 0.47, 0.94);\n" "\n" -"/* Private Variables ==================================================> */\n" -"\n" -"float halfThick = 0.5 * thick;\n" -"\n" -"float minFadeDistance = 0.01 * slices;\n" -"float maxFadeDistance = 0.32 * slices;\n" -"\n" -"float heightToFadeDistanceRatio = 36.0;\n" +"const float heightToFadeDistanceRatio = 36.0;\n" "\n" "/* GLSL Functions ====================================================== */\n" "\n" @@ -155,6 +163,9 @@ char resShadersCommonFsFrag[] = "\n" " float cameraDistance = distance(cameraPosition.xz, fragPosition.xz);\n" " float fadeDistance = heightToFadeDistanceRatio * abs(cameraPosition.y);\n" "\n" +" float minFadeDistance = 0.01 * float(slices);\n" +" float maxFadeDistance = 0.32 * float(slices);\n" +"\n" " fadeDistance = clamp(fadeDistance, minFadeDistance, maxFadeDistance);\n" "\n" " return 0.9 - smoothstep(0.0, 0.9, cameraDistance / fadeDistance);\n" @@ -168,13 +179,15 @@ char resShadersCommonFsFrag[] = "\n" " float cellX = fract(fragPosition.x * inverseSpacing);\n" " float cellZ = fract(fragPosition.z * inverseSpacing);\n" "\n" +" float halfThick = 0.5 * thick;\n" +"\n" " finalColor.xyz = innerColor;\n" "\n" " if ((fragPosition.x < halfThick) && (fragPosition.x > -halfThick))\n" " finalColor.xyz = blueColor;\n" " else if ((fragPosition.z < halfThick) && (fragPosition.z > -halfThick))\n" " finalColor.xyz = redColor;\n" -" else if (cellX < halfThick || cellX > (spacing - halfThick)\n" +" else if (cellX < halfThick || cellX > (spacing - halfThick)\n" " || cellZ < halfThick || cellZ > (spacing - halfThick))\n" " finalColor.xyz = outerColor;\n" "\n" diff --git a/src/utils.c b/src/utils.c index c7061f3..d55f336 100644 --- a/src/utils.c +++ b/src/utils.c @@ -396,5 +396,40 @@ void DrawViewFrustum(MvpRenderMode renderMode, Color color) { /* 공용 셰이더 프로그램을 반환하는 함수 */ Shader LoadCommonShader(void) { // 셰이더 소스 파일을 컴파일 및 링크하여 셰이더 프로그램 생성 - return LoadShaderFromMemory(resShadersCommonVsVert, resShadersCommonFsFrag); + Shader shaderProgram = LoadShaderFromMemory( + resShadersCommonVsVert, resShadersCommonFsFrag + ); + + float gridSpacingValue = GRID_SPACING_VALUE; + float gridThickValue = GRID_THICK_VALUE; + + int gridSlicesValue = GRID_SLICES_VALUE; + + int spacingLoc = GetShaderLocation(shaderProgram, "spacing"); + int thickLoc = GetShaderLocation(shaderProgram, "thick"); + + int slicesLoc = GetShaderLocation(shaderProgram, "slices"); + + SetShaderValue( + shaderProgram, + spacingLoc, + &gridSpacingValue, + SHADER_UNIFORM_FLOAT + ); + + SetShaderValue( + shaderProgram, + thickLoc, + &gridThickValue, + SHADER_UNIFORM_FLOAT + ); + + SetShaderValue( + shaderProgram, + slicesLoc, + &gridSlicesValue, + SHADER_UNIFORM_INT + ); + + return shaderProgram; }