Skip to content

Commit b48b09c

Browse files
Merge branch 'floordemo'
* Don't force WASM -- use it only if your EmSDK defaults to it * Force-enable C++17 on Emscripten (it supports it)
2 parents 60816e0 + feeb4f5 commit b48b09c

File tree

8 files changed

+614
-157
lines changed

8 files changed

+614
-157
lines changed

CMakeLists.txt

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,41 @@ target_compile_options(main
3838
$<$<CXX_COMPILER_ID:MSVC>:/W4>
3939
)
4040

41-
#Default to C++14 -- no effect on C code (emscripten is limited to C++14 for now)
42-
target_compile_features(main PUBLIC cxx_std_14)
41+
#Default to C++17 -- no effect on C code
42+
target_compile_features(main PUBLIC cxx_std_17)
4343

4444
#Special: handle emscripten for running in web browser
4545
if ("${CMAKE_SYSTEM_NAME}" MATCHES "Emscripten")
46+
47+
#Ensure Release builds have full optimization enabled
48+
string(REPLACE "O2" "O3" CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}")
49+
string(REPLACE "O2" "O3" CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}")
50+
51+
string(REPLACE "O2" "O3" CMAKE_C_FLAGS_RELWITHDEBINFO
52+
"${CMAKE_C_FLAGS_RELWITHDEBINFO}")
53+
string(REPLACE "O2" "O3" CMAKE_CXX_FLAGS_RELWITHDEBINFO
54+
"${CMAKE_CXX_FLAGS_RELWITHDEBINFO}")
55+
56+
string(REPLACE "O2" "O3" CMAKE_EXE_LINKER_FLAGS_RELEASE
57+
"${CMAKE_EXE_LINKER_FLAGS_RELEASE}")
58+
string(REPLACE "O2" "O3" CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO "${CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO}")
59+
60+
string(REPLACE "O2" "O3" CMAKE_SHARED_LINKER_FLAGS_RELEASE
61+
"${CMAKE_SHARED_LINKER_FLAGS_RELEASE}")
62+
string(REPLACE "O2" "O3" CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO
63+
"${CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO}")
64+
65+
string(REPLACE "O2" "O3" CMAKE_MODULE_LINKER_FLAGS_RELEASE
66+
"${CMAKE_MODULE_LINKER_FLAGS_RELEASE}")
67+
string(REPLACE "O2" "O3" CMAKE_MODULE_LINKER_FLAGS_RELWITHDEBINFO
68+
"${CMAKE_MODULE_LINKER_FLAGS_RELWITHDEBINFO}")
69+
70+
#Emscripten supports C++17, but upstream doesn't have the configuration added
71+
#TODO: make pull request upstream to Emscripten.cmake to add this
72+
set(CMAKE_CXX17_COMPILE_FEATURES "cxx_std_17")
73+
4674
set(CMAKE_EXECUTABLE_SUFFIX ".html")
47-
set(ECXXFLAGS "-s USE_SDL=2 -s USE_SDL_TTF=2 -s WASM=1 -s EXIT_RUNTIME=1 --preload-file iosevka-regular.ttf")
75+
set(ECXXFLAGS "-s USE_SDL=2 -s USE_SDL_TTF=2 -s EXIT_RUNTIME=1 --preload-file iosevka-regular.ttf --preload-file sky.bmp --preload-file floor.bmp")
4876
set_target_properties(main PROPERTIES LINK_FLAGS "${ECXXFLAGS} --emrun")
4977
set_target_properties(main PROPERTIES COMPILE_FLAGS "${ECXXFLAGS}")
5078
else ()

README.md

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
UWindsor COMP-3520 SDL2 Project Template (CMake version)
22
===
33

4-
*** NEW: For a live demo of the floordemo branch, [click here](https://inbetweennames.github.io/SDL2TemplateCMake/) ***
4+
** For a live demo of this code, [click here](https://inbetweennames.github.io/SDL2TemplateCMake/) **
55

66
This template is intended for students in the COMP-3520 Introduction to Computer Graphics course
77
at the University of Windsor, however it should serve as a useful template for anyone interested in
@@ -23,6 +23,30 @@ On Arch Linux, look for the packages `sdl2` and `sdl2_ttf`.
2323
Mac users should be able to use Homebrew or a similar package manager to install the needed dependencies.
2424
If you need help, just send me an email.
2525

26+
Demo
27+
---
28+
29+
This repository contains source code for some 2.5D rendering functions written
30+
for software rendering. The code needs a bit of cleaning up, but otherwise
31+
should work fine. Pull requests are welcome to improve the code.
32+
33+
The code is written in mostly C such that students without a C++ background
34+
can more easily understand it. More C++ parts may be added over time.
35+
There are some parts that need to be overhauled,
36+
like the conversion from floating point coordinates to integer coordinates.
37+
However, the basic ideas should be evident. In class, we'll discuss how
38+
this would have been implemented using fixed-point arithmetic.
39+
40+
A live demo compiled using Emscripten and WebAssembly is available [here](https://inbetweennames.github.io/SDL2TemplateCMake/)
41+
42+
Controls:
43+
---
44+
45+
Mouse - look left/right
46+
W, A, S, D - move forwards, backwards, upwards, downwards
47+
T, G -- raise and lower height
48+
Y, H -- adjust focal distance (distance to screen plane)
49+
2650
Setup
2751
---
2852

build-wasm/build-with-emscripten.sh

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,4 @@ if [[ -z $(which emcmake) ]]; then
77
exit 1
88
fi
99

10-
emcmake cmake ..
11-
cmake --build .
12-
emrun main.html
10+
emcmake cmake .. && cmake --build . && emrun main.html

build-wasm/floor.bmp

12.1 KB
Binary file not shown.

build-wasm/sky.bmp

96.1 KB
Binary file not shown.

build/floor.bmp

12.1 KB
Binary file not shown.

build/sky.bmp

96.1 KB
Binary file not shown.

0 commit comments

Comments
 (0)