Skip to content

Commit

Permalink
build tutorials using CMake instead of premake
Browse files Browse the repository at this point in the history
  • Loading branch information
paroj committed Mar 16, 2022
1 parent 8dc9762 commit 2f38531
Show file tree
Hide file tree
Showing 54 changed files with 154 additions and 841 deletions.
93 changes: 93 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
cmake_minimum_required(VERSION 3.12)
project(AllTutorials)

set(OpenGL_GL_PREFERENCE GLVND)
find_package(OpenGL REQUIRED)

add_subdirectory(glsdk)
add_subdirectory(framework)

function(add_tutorial base_dir tgt_name)
set(sources ${ARGN})
list(TRANSFORM sources PREPEND "${base_dir}/")
add_executable(${tgt_name} ${sources})
target_link_libraries(${tgt_name} PRIVATE framework)
endfunction()

## copy all data files to the build directory
file(COPY "data" DESTINATION "${CMAKE_BINARY_DIR}")
file(GLOB data_dirs "Tut*/data")
foreach(data_dir ${data_dirs})
file(COPY "${data_dir}" DESTINATION "${CMAKE_BINARY_DIR}")
endforeach()

## Tutorials
add_tutorial("Tut 01 Hello Triangle" "Tut01" "Tut1.cpp")

add_tutorial("Tut 02 Playing with Colors" "Tut02FragPosition" "FragPosition.cpp")
add_tutorial("Tut 02 Playing with Colors" "Tut02VertexColors" "VertexColors.cpp")

add_tutorial("Tut 03 OpenGLs Moving Triangle" "Tut03CPUPositionOffset" "CPUPositionOffset.cpp")
add_tutorial("Tut 03 OpenGLs Moving Triangle" "Tut03ShaderPositionOffset" "VertPositionOffset.cpp")
add_tutorial("Tut 03 OpenGLs Moving Triangle" "Tut03ShaderCalcOffset" "VertCalcOffset.cpp")
add_tutorial("Tut 03 OpenGLs Moving Triangle" "Tut03FragmentChangeColor" "FragChangeColor.cpp")

add_tutorial("Tut 04 Objects at Rest" "Tut04OrthographicCube" "OrthoCube.cpp")
add_tutorial("Tut 04 Objects at Rest" "Tut04ShaderPerspective" "ShaderPerspective.cpp")
add_tutorial("Tut 04 Objects at Rest" "Tut04MatrixPerspective" "MatrixPerspective.cpp")
add_tutorial("Tut 04 Objects at Rest" "Tut04AspectRatio" "AspectRatio.cpp")

add_tutorial("Tut 05 Objects in Depth" "Tut05OverlapNoDepth" "OverlapNoDepth.cpp")
add_tutorial("Tut 05 Objects in Depth" "Tut05BaseVertexWithOverlap" "BaseVertexOverlap.cpp")
add_tutorial("Tut 05 Objects in Depth" "Tut05DepthBuffering" "DepthBuffer.cpp")
add_tutorial("Tut 05 Objects in Depth" "Tut05VertexClipping" "VertexClipping.cpp")
add_tutorial("Tut 05 Objects in Depth" "Tut05DepthClamping" "DepthClamping.cpp")
add_tutorial("Tut 05 Objects in Depth" "Tut05DepthFighting" "DepthFighting.cpp")

add_tutorial("Tut 06 Objects in Motion" "Tut06Translation" "Translation.cpp")
add_tutorial("Tut 06 Objects in Motion" "Tut06Scale" "Scale.cpp")
add_tutorial("Tut 06 Objects in Motion" "Tut06Rotations" "Rotations.cpp")
add_tutorial("Tut 06 Objects in Motion" "Tut06Hierarchy" "Hierarchy.cpp")

add_tutorial("Tut 07 World in Motion" "Tut07WorldScene" "WorldScene.cpp")
add_tutorial("Tut 07 World in Motion" "Tut07WorldWithUBO" "WorldWithUBO.cpp")

add_tutorial("Tut 08 Getting Oriented" "Tut08GimbalLock" "GimbalLock.cpp")
add_tutorial("Tut 08 Getting Oriented" "Tut08QuaternionYPR" "QuaternionYPR.cpp")
add_tutorial("Tut 08 Getting Oriented" "Tut08CameraRelative" "CameraRelative.cpp")
add_tutorial("Tut 08 Getting Oriented" "Tut08Interpolation" "Interpolation.cpp")

add_tutorial("Tut 09 Lights on" "Tut09BasicLighting" "BasicLighting.cpp")
add_tutorial("Tut 09 Lights on" "Tut09ScaleAndLighting" "ScaleAndLighting.cpp")
add_tutorial("Tut 09 Lights on" "Tut09AmbientLighting" "AmbientLighting.cpp")

add_tutorial("Tut 10 Plane Lights" "Tut10VertexPointLighting" "VertexPointLighting.cpp")
add_tutorial("Tut 10 Plane Lights" "Tut10FragmentPointLighting" "FragmentPointLighting.cpp")
add_tutorial("Tut 10 Plane Lights" "Tut10FragmentAttenuation" "FragmentAttenuation.cpp")

add_tutorial("Tut 11 Shinies" "Tut11PhongLighting" "PhongLighting.cpp")
add_tutorial("Tut 11 Shinies" "Tut11BlinnVsPhongLighting" "BlinnVsPhongLighting.cpp")
add_tutorial("Tut 11 Shinies" "Tut11GaussianSpecularLighting" "GaussianSpecularLighting.cpp")

add_tutorial("Tut 12 Dynamic Range" "Tut12SceneLighting" "SceneLighting.cpp" "Lights.cpp" "Scene.cpp")
add_tutorial("Tut 12 Dynamic Range" "Tut12HDRLighting" "HDRLighting.cpp" "Lights.cpp" "Scene.cpp")
add_tutorial("Tut 12 Dynamic Range" "Tut12GammaCorrection" "GammaCorrection.cpp" "Lights.cpp" "Scene.cpp")

add_tutorial("Tut 13 Impostors" "Tut13BasicImpostor" "BasicImpostor.cpp")
add_tutorial("Tut 13 Impostors" "Tut13GeometryImpostor" "GeomImpostor.cpp")

add_tutorial("Tut 14 Textures Are Not Pictures" "Tut14BasicTexture" "BasicTexture.cpp")
add_tutorial("Tut 14 Textures Are Not Pictures" "Tut14PerspectiveInterpolation" "PerspectiveInterpolation.cpp")
add_tutorial("Tut 14 Textures Are Not Pictures" "Tut14MaterialTexture" "MaterialTexture.cpp")

add_tutorial("Tut 15 Many Images" "Tut15ManyImages" "ManyImages.cpp")

add_tutorial("Tut 16 Gamma and Textures" "Tut16GammaRamp" "GammaRamp.cpp")
add_tutorial("Tut 16 Gamma and Textures" "Tut16GammaCheckers" "GammaCheckers.cpp")
add_tutorial("Tut 16 Gamma and Textures" "Tut16GammaLandscape" "GammaLandscape.cpp" "LightEnv.cpp")

add_tutorial("Tut 17 Spotlight on Textures" "Tut17DoubleProjection" "DoubleProjection.cpp")
add_tutorial("Tut 17 Spotlight on Textures" "Tut17ProjectedLight" "ProjectedLight.cpp")
add_tutorial("Tut 17 Spotlight on Textures" "Tut17CubePointLight" "CubePointLight.cpp")

add_tutorial("Tut 18 Bumpy Textures" "Tut18BumpySquare" "BumpySquare.cpp")
53 changes: 15 additions & 38 deletions Documents/Building the Tutorials.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,8 @@

the tutorials are bundled as part of the distribution, so this is the only source code
download you will need.</para>
<para>You will also need to download the <link xlink:href="http://industriousone.com/premake"
>Premake 4</link> utility for your platform of choice. Place the executable somewhere in
your command path.</para>
<para>You will also need to download and install the <link xlink:href="https://cmake.org/"
>CMake</link> utility for your platform of choice.</para>
<para>You will need minimal familiarity with using the command line in order to build these
tutorials. Also, any mention of directories is always relative to where you unzipped this
distribution.</para>
Expand All @@ -43,19 +42,14 @@
<para>The other directories either contain libraries used by the tutorials or data files that
the tutorials load.</para>
<formalpara>
<title>Premake 4</title>
<para>Premake is a utility like <link xlink:href="http://www.cmake.org/">CMake</link>: it
generates build files for a specific platform. Unlike CMake, Premake is strictly a
command-line utility. Premake's build scripts are written in the <link
xlink:href="http://www.lua.org/home.html">Lua language</link>, unlike CMake's build
scripts that use their own language.</para>
<title>CMake</title>
<para>CMake generates build files for a specific platform. CMake's build scripts use their own language.</para>
</formalpara>
<para>Note that Premake only generates build files; once the build files are created, you can
<para>Note that CMake only generates build files; once the build files are created, you can
use them as normal. It can generate project files for Visual Studio, <link
xlink:href="http://www.codeblocks.org/">Code::Blocks</link>, as well as GNU Makefiles.
And unless you want to modify one of the tutorials, you only need to run Premake once for
each tutorial.</para>
<para>The Premake download comes as a pre-built executable for all platforms of interest,
And unless you want to modify one of the tutorials, you only need to run CMake once.</para>
<para>The CMake download comes as a pre-built executable for all platforms of interest,
including Linux.</para>
<formalpara>
<title>Unofficial OpenGL SDK</title>
Expand All @@ -65,39 +59,22 @@
not need to download it; a version of the SDK is part of the tutorial distribution. The
copy that comes with these tutorials does not contain the documentation or GLFW.</para>
</formalpara>
<para>The SDK library uses Premake to generate its build files. So, with
<command>premake4.exe</command> in your path, open your command prompt and go to the
<filename>glsdk</filename> directory. Type <userinput>premake4
<replaceable>plat</replaceable></userinput>, where <replaceable>plat</replaceable>
is the name of the platform of choice. For Visual Studio 2008, this would be
<quote>vs2008</quote>; for VS2010, this would be <quote>vs2010.</quote> This will
generate Visual Studio projects and solution files for that particular version.</para>
<para>For GNU and makefile-based builds, this is <quote>gmake</quote>. This will generate a
makefile. To build for debug, use <userinput>make config=debug</userinput>; similarly, to
build for release, use <userinput>make config=release</userinput>.</para>
<para>Using the generated build files, compile for both debug and release. You should build the
entire solution; the tutorials use all of the libraries provided. Do not attempt to run the
SDK from your IDE; it's just a set of libraries. All you have to do is compile them for
debug and release.</para>
<para>That there is also no need to execute <userinput>make install</userinput> or similar
commands after building the SDK. The SDK is designed to be used where it is; it does not
<para>The SDK libraries are built using CMake as well. The tutorial-build is aware of the SDK
and will take care of building it, when you build the tutorials as described below.</para>
<para>There is no need to execute <userinput>make install</userinput> or similar
commands when building the SDK. The SDK is designed to be used where it is; it does not
install itself to any system directories on your machine. Incidentally, neither do these
tutorials.</para>
<formalpara>
<title>Tutorial Building and Running</title>
</formalpara>
<para>Each tutorial directory has a <filename>premake4.lua</filename> file; this file is used by
Premake to generate the build files for that tutorial. Therefore, to build any tutorial, you
need only go to that directory and type <userinput>premake4
<replaceable>plat</replaceable></userinput>, then use those build files to build the
tutorial.</para>
<para>All of the tutorials are built at once; go to the root directory of the
distribution and use CMake on the <filename>CMakeLists.txt</filename> file in that
directory. It will put all of the tutorials into a single project that you can
build them all.</para>
<para>Each tutorial will generally have more than one source file and generate multiple
executables. Each executable represents a different section of the tutorial, as explained in
that tutorial's documentation.</para>
<para>If you want to build all of the tutorials at once, go to the root directory of the
distribution and use Premake on the <filename>premake4.lua</filename> file in that
directory. It will put all of the tutorials into one giant project that you can
build.</para>
<para>If you look at any of the tutorial source files, you will not find the
<function>main</function> function defined anywhere. This function is defined in
<filename>framework/framework.cpp</filename>; it and all of the other source files in
Expand Down
10 changes: 4 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,10 @@ In case you prefer Java to C++, Giuseppe Barbieri [created a Java port here](htt

## Building the tutorials

- `apt-get install premake4`
- build glsdk
- inside glsdk run `premake4 gmake`
- inside glsdk run `make config=release`
- `premake4 gmake`
- `make config=release`
- `apt-get install cmake`
- `mkdir build && cd build`
- `cmake ..`
- `cmake --build . --config Release`

## Rebuilding the HTML Documentation

Expand Down
5 changes: 0 additions & 5 deletions Tut 01 Hello Triangle/premake4.lua

This file was deleted.

2 changes: 0 additions & 2 deletions Tut 01 Hello Triangle/tutorials.lua

This file was deleted.

5 changes: 0 additions & 5 deletions Tut 02 Playing with Colors/premake4.lua

This file was deleted.

6 changes: 0 additions & 6 deletions Tut 02 Playing with Colors/tutorials.lua

This file was deleted.

5 changes: 0 additions & 5 deletions Tut 03 OpenGLs Moving Triangle/premake4.lua

This file was deleted.

5 changes: 0 additions & 5 deletions Tut 03 OpenGLs Moving Triangle/tutorials.lua

This file was deleted.

5 changes: 0 additions & 5 deletions Tut 04 Objects at Rest/premake4.lua

This file was deleted.

9 changes: 0 additions & 9 deletions Tut 04 Objects at Rest/tutorials.lua

This file was deleted.

5 changes: 0 additions & 5 deletions Tut 05 Objects in Depth/premake4.lua

This file was deleted.

13 changes: 0 additions & 13 deletions Tut 05 Objects in Depth/tutorials.lua

This file was deleted.

6 changes: 0 additions & 6 deletions Tut 06 Objects in Motion/premake4.lua

This file was deleted.

9 changes: 0 additions & 9 deletions Tut 06 Objects in Motion/tutorials.lua

This file was deleted.

6 changes: 0 additions & 6 deletions Tut 07 World in Motion/premake4.lua

This file was deleted.

15 changes: 0 additions & 15 deletions Tut 07 World in Motion/tutorials.lua

This file was deleted.

6 changes: 0 additions & 6 deletions Tut 08 Getting Oriented/premake4.lua

This file was deleted.

13 changes: 0 additions & 13 deletions Tut 08 Getting Oriented/tutorials.lua

This file was deleted.

6 changes: 0 additions & 6 deletions Tut 09 Lights on/premake4.lua

This file was deleted.

18 changes: 0 additions & 18 deletions Tut 09 Lights on/tutorials.lua

This file was deleted.

6 changes: 0 additions & 6 deletions Tut 10 Plane Lights/premake4.lua

This file was deleted.

21 changes: 0 additions & 21 deletions Tut 10 Plane Lights/tutorials.lua

This file was deleted.

6 changes: 0 additions & 6 deletions Tut 11 Shinies/premake4.lua

This file was deleted.

Loading

0 comments on commit 2f38531

Please sign in to comment.