Skip to content
This repository has been archived by the owner on Jan 20, 2024. It is now read-only.

Commit

Permalink
new: partial HTML5 support
Browse files Browse the repository at this point in the history
  • Loading branch information
r-lyeh committed Apr 29, 2022
1 parent 1c39be6 commit 290c55a
Show file tree
Hide file tree
Showing 111 changed files with 5,760 additions and 302,375 deletions.
2 changes: 2 additions & 0 deletions MAKE.bat
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ if [ "$(uname)" != "Darwin" ]; then
chmod +x editor/tools/ffmpeg.linux
chmod +x editor/tools/cuttlefish.linux
chmod +x editor/tools/PVRTexToolCLI.linux
chmod +x editor/tools/cook.linux

# framework (as dynamic library)
if [ "$1" = "dll" ]; then
Expand Down Expand Up @@ -104,6 +105,7 @@ if [ "$(uname)" = "Darwin" ]; then
chmod +x editor/tools/ffmpeg.osx
chmod +x editor/tools/cuttlefish.osx
chmod +x editor/tools/PVRTexToolCLI.osx
chmod +x editor/tools/cook.osx

# framework (as dynamic library)
if [ "$1" = "dll" ]; then
Expand Down
38 changes: 26 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
## Features ᕦ(ᐛ)ᕤ
- [x] Pipeline: configurable and integrated [asset pipeline](fwk.ini).
- [x] Embedded: single-file, all dependencies included.
- [x] Compiler: MSVC, MINGW64, TCC, GCC and clang.
- [x] Platform: Windows, Linux and OSX.
- [x] Compiler: MSVC, MINGW64, TCC, GCC, clang and emscripten.
- [x] Platform: Windows, Linux and OSX. Partial HTML5/Web support.
- [x] DS: hash, sort, array/vector, map, set.
- [x] Math: rand, noise, ease, vec2/3/4, mat33/34/44, quat.
- [x] Geometry: ray, line, plane, aabb, sphere, capsule, triangle, poly and frustum.
Expand All @@ -31,7 +31,7 @@
- [x] Texture: KTX/2, PVR, DDS, ASTC, BASIS, HDR, TGA.
- [x] Texel: Depth, R, RG, RGB, RGBA, BC1/2/3/4/5/6/7, PVRI/II, ETC1/2, ASTC.
- [x] Audio: WAV/FLAC, OGG/MP1/MP3, MOD/XM/S3M/IT, SFXR and MID.
- [x] Video: MP4, MPG, OGV, MKV, WMV and AVI.
- [x] Video: MP4, MPG, OGV, MKV, WMV and AVI. Also, MP4 recording with MPEG-1 fallback.
- [x] Model: IQM/E, GLTF/2, GLB, FBX, OBJ, DAE, BLEND, MD3/5, MS3D, SMD, X, 3DS, BVH, DXF, LWO.
- [x] Render: PBR (metallic-roughness) workflow. <!-- @todo: merge demo_pbr.c rendering code into fwk_render.c -->
- [x] Render: Cubemaps, panoramas and spherical harmonics. Rayleigh/Mie scattering.
Expand Down Expand Up @@ -64,7 +64,7 @@
- [ ] Maybe: AI/Logic pass.
- [ ] Maybe: Animation pass.
- [ ] Maybe: VM/Replication pass.
- [ ] Maybe: Mobile/WASM pass.
- [ ] Maybe: Mobile/WASM/HTML5✱ pass.
- [ ] Maybe: Lighting pass.
- [ ] Maybe: Node/Graph editor. <!-- reused into materials, animgraphs and blueprints -->
- [ ] Maybe: Tiled maps and 2D spines. Sprite parallaxs.
Expand Down Expand Up @@ -185,10 +185,10 @@ R. Documentation pass: API, functions, samples, examples, pipeline. #5
// proj matrix: float b = (-znear * zfar) / (zfar - znear); -> float b = (znear * zfar) / (zfar - znear);
// }
char* os_exec(...) -> int rc = popen(...); [...] return va("%8d,%s", rc, output);
char *result = os_exec("dir *.f")
int rc = atoi(result);
char *log = result+9;
char* os_exec(...) -> int rc = popen(...); [...] return va("%8d,%s", rc, output);
char *result = os_exec("dir *.f")
int rc = atoi(result);
char *log = result+9;
-->

Expand All @@ -211,10 +211,10 @@ R. Documentation pass: API, functions, samples, examples, pipeline. #5
## Hello FWK
```C
#include "fwk.h" // Minimal C sample
int main(int argc, char **argv) {
int main() {
window_create(75.0, 0); // 75% size, no extra flags
while( window_swap() && !input(KEY_ESC) ) { // game loop
puts("hello fwk");
puts("hello fwk! from C");
}
}
```
Expand All @@ -223,10 +223,23 @@ int main(int argc, char **argv) {
local fwk = require("fwk") -- Minimal Lua sample
fwk.window_create(75.0,0) -- 75% size, no extra flags
while fwk.window_swap() and fwk.input(fwk.KEY_ESC) == 0 do -- game loop
print("hello fwk")
print("hello fwk! from Lua")
end
```

```C
#include "fwk.h" // Minimal HTML5 sample
void render(void *arg) {
if( window_swap() && !input(KEY_ESC) ) {
puts("hello fwk! from HTML5");
}
}
int main() {
window_create(75.0, 0); // 75% size, no extra flags
window_loop(render, NULL); // game loop
}
```
## Build (as static library)
Type `MAKE.bat` (Win) or `sh MAKE.bat` (Linux/OSX) to build everything. Alternatively,
Expand Down Expand Up @@ -299,6 +312,7 @@ Any contribution to this repository is implicitly subjected to the same release
- [Imagination](https://developer.imaginationtech.com/pvrtextool/), for pvrtextoolcli (ITL).
- [Krzysztof Gabis](https://github.com/kgabis/ape), for split.py/join.py (MIT).
- [Lee Salzman](https://github.com/lsalzman/iqm/tree/5882b8c32fa622eba3861a621bb715d693573420/demo), for iqm.cpp (PD).
- [Martín Lucas Golini](https://github.com/SpartanJ/eepp/commit/8552941da19380d7a629c4da80a976aec5d39e5c), for emscripten-fs.html (CC0).
- [Mattias Gustavsson](https://github.com/mattiasgustavsson/libs), for mid.h (PD).
- [Michael Schmoock](http://github.com/willsteel/lcpp), for lcpp (MIT).
- [Morgan McGuire](https://casual-effects.com/markdeep/), for markdeep (BSD2).
Expand Down Expand Up @@ -326,7 +340,7 @@ Any contribution to this repository is implicitly subjected to the same release
- [Libtomcrypt](https://github.com/libtom/libtomcrypt), for libtomcrypt (Unlicense).
- [Lua authors](https://www.lua.org/), for Lua language (MIT).
- [Mattias Gustavsson](https://github.com/mattiasgustavsson/libs), for thread.h and https.h (PD).
- [Micha Mettke](https://github.com/vurtun/nuklear), for nuklear (PD).
- [Micha Mettke, Chris Willcocks, Dmitry Hrabrov](https://github.com/vurtun/nuklear), for nuklear (PD).
- [Omar Cornut, vaiorabbit](https://github.com/ocornut/imgui/pull/3627), for tables of unicode ranges (MIT-0).
- [Rich Geldreich](https://github.com/richgel999/miniz), for miniz (PD).
- [Ross Williams](http://ross.net/compression/lzrw3a.html) for lzrw3a (PD).
Expand Down
2 changes: 1 addition & 1 deletion demo.c
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ int main() {
skybox_push_state(&sky, cam.proj, cam.view);
glEnable(GL_DEPTH_TEST);
mesh_render(&sky.geometry);
skybox_pop_state(&sky);
skybox_pop_state();
}

profile("Editor") {
Expand Down
86 changes: 86 additions & 0 deletions demos/art/fonts/fontawesome-webfont.license
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
-----------------------------------------------------------
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
-----------------------------------------------------------

PREAMBLE
The goals of the Open Font License (OFL) are to stimulate worldwide
development of collaborative font projects, to support the font creation
efforts of academic and linguistic communities, and to provide a free and
open framework in which fonts may be shared and improved in partnership
with others.

The OFL allows the licensed fonts to be used, studied, modified and
redistributed freely as long as they are not sold by themselves. The
fonts, including any derivative works, can be bundled, embedded,
redistributed and/or sold with any software provided that any reserved
names are not used by derivative works. The fonts and derivatives,
however, cannot be released under any other type of license. The
requirement for fonts to remain under this license does not apply
to any document created using the fonts or their derivatives.

DEFINITIONS
"Font Software" refers to the set of files released by the Copyright
Holder(s) under this license and clearly marked as such. This may
include source files, build scripts and documentation.

"Reserved Font Name" refers to any names specified as such after the
copyright statement(s).

"Original Version" refers to the collection of Font Software components as
distributed by the Copyright Holder(s).

"Modified Version" refers to any derivative made by adding to, deleting,
or substituting -- in part or in whole -- any of the components of the
Original Version, by changing formats or by porting the Font Software to a
new environment.

"Author" refers to any designer, engineer, programmer, technical
writer or other person who contributed to the Font Software.

PERMISSION & CONDITIONS
Permission is hereby granted, free of charge, to any person obtaining
a copy of the Font Software, to use, study, copy, merge, embed, modify,
redistribute, and sell modified and unmodified copies of the Font
Software, subject to the following conditions:

1) Neither the Font Software nor any of its individual components,
in Original or Modified Versions, may be sold by itself.

2) Original or Modified Versions of the Font Software may be bundled,
redistributed and/or sold with any software, provided that each copy
contains the above copyright notice and this license. These can be
included either as stand-alone text files, human-readable headers or
in the appropriate machine-readable metadata fields within text or
binary files as long as those fields can be easily viewed by the user.

3) No Modified Version of the Font Software may use the Reserved Font
Name(s) unless explicit written permission is granted by the corresponding
Copyright Holder. This restriction only applies to the primary font name as
presented to the users.

4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
Software shall not be used to promote, endorse or advertise any
Modified Version, except to acknowledge the contribution(s) of the
Copyright Holder(s) and the Author(s) or with their explicit written
permission.

5) The Font Software, modified or unmodified, in part or in whole,
must be distributed entirely under this license, and must not be
distributed under any other license. The requirement for fonts to
remain under this license does not apply to any document created
using the Font Software.

TERMINATION
This license becomes null and void if any of the above conditions are
not met.

DISCLAIMER
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
OTHER DEALINGS IN THE FONT SOFTWARE.
Binary file added demos/art/fonts/fontawesome-webfont.ttf
Binary file not shown.
2 changes: 1 addition & 1 deletion demos/demo_collide.c
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ int main(void) {
ddraw_color(RED);
else ddraw_color(WHITE);

ddraw_pyramid(vec3(x,y-0.5f,z), 1/*vec3(x,y+1,z)*/, 0.8f);
ddraw_pyramid(vec3(x,y-0.5f,z), 1/*vec3(x,y+1,z)*/, 1/*0.8f*/);
ddraw_diamond(vec3(-20.5f,-0.5f,-15.5f), vec3(-20.5f,1.0f,-15.5f), 0.5f);

poly_free(&dmd);
Expand Down
48 changes: 48 additions & 0 deletions demos/html5/MAKE.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/bin/bash 2>nul || goto :windows

if [ "$1" = "" ]; then
sh MAKE.bat demo_collide.c
exit
fi

## clone emscripten sdk
git clone https://github.com/emscripten-core/emsdk ../../../emsdk
pushd ../../../emsdk
./emsdk install 3.0.0 ## latest
./emsdk activate 3.0.0 ## latest
source ./emsdk_env.sh
popd

## cook art
if [ "$(uname)" = "Darwin" ]; then
chmod +x ../../editor/tools/cook.osx
../../editor/tools/cook.osx
else
chmod +x ../../editor/tools/cook.linux
../../editor/tools/cook.linux
fi

## host webserver, compile and launch
python -m http.server --bind 127.0.0.1 8000 1> /dev/null 2> /dev/null &
emcc $@ -g ../../fwk.c -I../.. -o index.html -s FULL_ES3 -s USE_GLFW=3 -s SINGLE_FILE=1 -s PRECISE_F32=1 -s TOTAL_MEMORY=256mb -s ENVIRONMENT=worker,web --shell-file template.html -Wfatal-errors --preload-file .art[0].zip -s ALLOW_MEMORY_GROWTH=1 -lidbfs.js && xdg-open http://localhost:8000/index.html

exit

:windows

if "%1"=="" MAKE.bat demo_collide.c

rem clone emscripten sdk
git clone https://github.com/emscripten-core/emsdk ..\..\..\emsdk
pushd ..\..\..\emsdk
call emsdk install 3.0.0 && rem latest
call emsdk activate 3.0.0 && rem latest
call emsdk_env.bat
popd

rem cook art
..\..\editor\tools\cook.exe

rem host webserver, compile and launch
start python -m http.server --bind 127.0.0.1 8000
emcc %* -g ..\..\fwk.c -I..\.. -o index.html -s FULL_ES3 -s USE_GLFW=3 -s SINGLE_FILE=1 -s PRECISE_F32=1 -s TOTAL_MEMORY=256mb -s ENVIRONMENT=worker,web --shell-file template.html -Wfatal-errors --preload-file .art[0].zip -s ALLOW_MEMORY_GROWTH=1 -lidbfs.js && start http://localhost:8000/index.html
19 changes: 19 additions & 0 deletions demos/html5/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
## Known HTML5 issues:
- [x] Game loop is event based (fixed: see `window_loop()`).
- [x] No automated emsdk installation (fixed: see `demos/html5/MAKE.bat`).
- [x] Art must be cooked beforehand (fixed: see `demos/html5/MAKE.bat`).
- [x] No VFS loading (fixed).
- [x] No UI rendering (fixed).
- [x] No cooker (fixed: win,osx,linux).
- [ ] No audio.
- [ ] No input.
- [ ] No file writing.
- [ ] No glTexture1D().
- [ ] No network.
- [ ] No fbos.
- [ ] No callstacks.
- [ ] No pbos.
- [ ] No gamepads.
- [ ] Shaders require (automated?) GL->GLES translation (No postfxs, models, skyboxes, pbrs, ...) (@todo: embed Spir-v/glslcross tools?)
- [ ] Shaders: `vec2 iResolution = vec2(iWidth, iHeight); // ERROR: '=' : global variable initializers must be constant expressions`
- [ ] Shaders: `uniform float var = 1.0f; // ERROR: 'uniform' : cannot initialize this type of qualifier`
Loading

0 comments on commit 290c55a

Please sign in to comment.