Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

modernize/simplify cmake. Make release take effect #5

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions .gitpod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@ image:
file: Dockerfile
tasks:
- command: >
mkdir --parents build &&
cd build &&
cmake .. &&
make &&
./tinykaboom &&
cmake -Bbuild &&
cmake --build build &&
build/tinykaboom &&
pnmtopng out.ppm > out.png &&
open out.png &&
cd ..
open out.png
45 changes: 21 additions & 24 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,27 +1,24 @@
cmake_minimum_required (VERSION 2.8)
project (tinykaboom)

include(CheckCXXCompilerFlag)

function(enable_cxx_compiler_flag_if_supported flag)
string(FIND "${CMAKE_CXX_FLAGS}" "${flag}" flag_already_set)
if(flag_already_set EQUAL -1)
check_cxx_compiler_flag("${flag}" flag_supported)
if(flag_supported)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${flag}" PARENT_SCOPE)
endif()
unset(flag_supported CACHE)
endif()
endfunction()

enable_cxx_compiler_flag_if_supported("-Wall")
enable_cxx_compiler_flag_if_supported("-Wextra")
enable_cxx_compiler_flag_if_supported("-pedantic")
enable_cxx_compiler_flag_if_supported("-std=c++11")
enable_cxx_compiler_flag_if_supported("-O3")
enable_cxx_compiler_flag_if_supported("-fopenmp")

file(GLOB SOURCES *.h *.cpp)
cmake_minimum_required(VERSION 3.10...3.26)

get_property(is_multi_config GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
if(NOT is_multi_config AND NOT (CMAKE_BUILD_TYPE OR DEFINED ENV{CMAKE_BUILD_TYPE}))
set(CMAKE_BUILD_TYPE Release CACHE STRING "Release default")
endif()

project(tinykaboom LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

if(CMAKE_CXX_COMPILER_ID MATCHES "Clang|GNU|Intel")
add_compile_options(-Wall -Wextra -Wpedantic)
endif()

find_package(OpenMP COMPONENTS CXX)

set(SOURCES tinykaboom.cpp)

add_executable(${PROJECT_NAME} ${SOURCES})
target_link_libraries(${PROJECT_NAME} PRIVATE $<$<BOOL:${OpenMP_CXX_FOUND}>:OpenMP::OpenMP_CXX>)

file(GENERATE OUTPUT .gitignore CONTENT "*")
10 changes: 5 additions & 5 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ In my lectures I tend to avoid third party libraries as long as it is reasonable
![](https://raw.githubusercontent.com/ssloy/tinykaboom/master/out.jpg)

## compilation

```sh
git clone https://github.com/ssloy/tinykaboom.git
cd tinykaboom
mkdir build
cd build
cmake ..
make
cmake -Bbuild
cmake --build build
build/tinykaboom
```

You can open the project in Gitpod, a free online dev evironment for GitHub:
Expand All @@ -27,7 +27,7 @@ On open, the editor will compile & run the program as well as open the resulting
Just change the code in the editor and rerun the script (use the terminal's history) to see updated images.

## Homework
The possibilities are infinte. For example, you can add the environment map and some transparency:
The possibilities are infinte. For example, you can add the environment map and some transparency:
![](https://raw.githubusercontent.com/ssloy/tinykaboom/homework_assignment/envmap1.jpg)

Add other objects and illuminate them:
Expand Down
3 changes: 1 addition & 2 deletions tinykaboom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ int main() {
std::vector<Vec3f> framebuffer(width*height);

#pragma omp parallel for
for (size_t j = 0; j<height; j++) { // actual rendering loop
for (int j = 0; j<height; j++) { // actual rendering loop
for (size_t i = 0; i<width; i++) {
float dir_x = (i + 0.5) - width/2.;
float dir_y = -(j + 0.5) + height/2.; // this flips the image at the same time
Expand Down Expand Up @@ -124,4 +124,3 @@ int main() {

return 0;
}