Skip to content

Cross-platform restoration of TheCherno's OpenGL series with perfect commit history (link to YouTube playlist below)

Notifications You must be signed in to change notification settings

Challanger524/ChernoOpenGL-CMake

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ChernoOpenGL-CMake

CMake-based implementation of TheCherno's OpenGL series with minimal code deviance according to videos.

Features

  • C++ 17
  • CMake - cross-platform build system
    • cross-platform dependencies handling
    • tested on:
      • Windows 10 - Visual Studio 2022, VS Code v1.86: MSVC 19.34, Clang 17.0.4, GCC 13.2 (Rev2, Built by MSYS2 project)
      • Linux Mint 20 - VS Code v1.75: GCC 9.4, Clang 10.0
      • MacOS (Mac Mini M2) - VS Code: GCC, Apple-Clang
  • perfect commits - reached through git-history rewriting
    • pros: clean diffs between commits (best for learn-repositories)
    • pros: no typo/logic fixing or improving separate commits
    • cons: unstable (ever changing) commit hashes and timestamps
    • commands:
      • rebase -i <commit>~/rebase -i --root; (then follow status hints)
      • git rm <submodule_path> # the only way to change submodule <name> field
      • git filter-repo --refs <branch> --replace-text <(echo 'regex:Dependencies/==>deps/')
      • git filter-repo --refs <branch> --replace-text <(echo 'regex:^\xEF\xBB\xBF==>') # strip BOM
      • see doc/note.sh for other commands and use cases
  • git submodules - each dependency present as a submodule
    • much clear dependency-introduction commits
    • up-to-date source of dependencies' repositories
    • no need for additional downloads during the install stage

Differences

  • header-only due to my laziness :) - more compact codebase 👍
  • error-logging - debug output with GL_KHR_debug:glDebugMessageCallback() (if possible):
    • debugging stuff moved from Renderer.hpp to new Utility.hpp
    • detailed GPU-vendor error description with debug output:
      • can be implemented in OpenGL versions prior to 4.3 (by GPU-vendor)
      • worked on OpenGL 4.0 (Intel CPU) (on old tiny laptop)
  • imgui docking branch - allows moving imgui-windows outside and to dock them to each other
  • batch rendering episodes - adopted with last 4 commits
    • The Cherno explained with non-related source code (repository)
  • some stl::type_traits related bragging 😎 (Utility.hpp: GLASSERT(<gl_(un)signed_int_ret>) macro)

Debatable

  • headers-definitions (without sources), single .cpp file with int main()
    • maybe allows to switch easier to the C++20 modules

All concerns can be expressed via GitHub Project's Issues (one issue per concern)

Clone

git clone --recurse --shallow-submodules "https://github.com/Challanger524/ChernoOpenGL-CMake.git"

Prerequisites

  • CMake - cross-platform build automation system
  • Ninja - small build system with a focus on speed
  • C++ compiler (any): MSVC / GCC / Clang
  • on GNU Linux:
    • install dev libs listed below and/or google CMake log for other required
    • sudo apt-get install: libxi-dev libxrandr-dev libxcursor-dev libxinerama-dev libopengl-dev

Build

Visual Studio

Official documentation: CMake projects in Visual Studio

C++ CMake tools for Windows module must be installed (see docs Installation part)

  1. open the project folder with Visual Studio (and enable CMake via dialog prompt, if any)
  2. in the upper toolbar choose MSVC configuration
  3. Project->Configure ChernoOpenGL
  4. Build->Build All
  5. set CMakeLists.txt as Startup Item via Solution Explorer (or see Debugging CMake projects part)
  6. Debug->Start Debugging

VS Code

Official documentation: Get started with CMake Tools on Linux (less suitable article then as for Visual Studio)

1.C/C++ and 2.CMake Tools extensions (by Microsoft) must be installed (see docs Prerequisites part)

Note: on Windows...

when building with msvc preset, to rid off unconfigured preset messages - you need to run VS Code from a Developer Command Prompt for Visual Studio

I created a shorcut to launch VS Code with next Target:

%comspec% /C "C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\Tools\VsDevCmd.bat" & code

with /C option it should close itself automatically, but sometimes it is not - so just close it manually after VS Code launched.

  1. open the project folder
  2. configure from preset via dialog (CMake) prompt, or:
    • select preset - open Command Palette (Ctrl+Shift+P) and type CMake: Select Configure Preset then choose suitable
    • configure - open Command Palette (Ctrl+Shift+P) and type CMake: Configure (if not started automatically)
  3. build - open Command Palette (Ctrl+Shift+P) and type CMake: Build (or press a build (:radio_button:) button in the bottom toolbar)
  4. run:
    • debug - open Command Palette (Ctrl+Shift+P) and type CMake: Debug (or press F5) (or press a debug 🐛 (near ▶️) in the bottom toolbar)
    • launch (if debug is unavailable) - Menu Bar->Run->Run Without Debugging (or Ctrl+F5) (or ▶️ button in the bottom toolbar)

Command Line

Presets were introduced in CMake 3.19

  1. cmake --list-presets
  2. cmake --preset <preset>
  3. ninja -C out/build/<preset>
  4. ./ChernoOpenGL (or ./ChernoOpenGL.exe on shWindows)

Showcase

Console output examples:

MS Windows 10 (NVIDIA GTX 1060)
Info: Context: Debug - active (supported)
Info: GL: Extension: GL_KHR_debug - OK

Info: GLFW version: 3.4.0 Win32 WGL Null EGL OSMesa MinGW-w64
Info: GLEW version: 2.2.0
Info: GL   version: 3.3.0 NVIDIA 537.34
Info: GLSL version: 3.30 NVIDIA via Cg compiler
Info: GPU  vendor : NVIDIA Corporation
Info: Renderer    : NVIDIA GeForce GTX 1060 3GB/PCIe/SSE2
Info: ImGui version: 1.90.4 +docking +viewport

Trace: Registering test: Clear Color
Trace: Registering test: Texture 2D
Trace: Registering test: Batching
Trace: Registering test: Batching Textures
Trace: Registering test: Batching Textures (dynamic)
Apple Mac Mini M2
Info: Context: Debug - inactive (or unsupported)

Info: GLFW version: 3.4.0 Cocoa NSGL Null EGL OSMesa monotonic
Info: GLEW version: 2.2.0
Info: GL   version: 4.1 Metal - 88
Info: GLSL version: 4.10
Info: GPU  vendor : Apple
Info: Renderer    : Apple M2
Info: ImGui version: 1.90.4 +docking +viewport

Trace: Registering test: Clear Color
Trace: Registering test: Texture 2D
Trace: Registering test: Batching
Trace: Registering test: Batching Textures

Screenshots:

test_menu
Test Menu

test-clear_color
Clear Color

test-texture_2d
Texture 2D

test-batching
Batching

test-batching_textures
Batching Textures

test-batching_textures_dynamic
Batching Textures (dynamic)

Moral Ownership

  • Cherno Hazel logos and Educational aspect of the source code - belongs to Yan Chernikov TheCherno the way YouTube OpenGL series does
  • restoration polishing fixing (over)correcting (for_perfectiest_solution) researhing (folder) structuring/renaming dependency managing perfect git-history keeping doc/ -umenting CMake -ing readme.md composing .editorconfig -ing .gitignore -ing cross-platform -ing codestyling - was done (outprocrastinated and overthinked) by Daniil Semenenko Challanger524
  • other tools sources materials are not hided or appropriated (at least not intentionally) and are provided with links to the original sources whenever possible
  • additional thanks to speauty's ChernoOpenGL implementation for working and mostly accurate code, that was used as a reference for clarification of certain moments and typos, that greatly saved some of my time.

Changelog: doc/changelog.md

Misc

  • It took a bit more than a month to finish this project and half a day to port on Linux (and a week to polish all warnings and complete documentation)
  • And it took years to polish it all 😐🚬
  • This project helped me to cure 👨‍⚕️ my 👩‍💻git- and cmake-anxiety ;)
  • Cherno is the only and the best C++ teacher, see also his C++ playlist.
  • Motto: "in case of anything - stay ironically-cynic and/or cynically-ironic ¯\_(ツ)_/¯🃏"

About

Cross-platform restoration of TheCherno's OpenGL series with perfect commit history (link to YouTube playlist below)

Topics

Resources

Stars

Watchers

Forks