├── .github └── FUNDING.yml ├── .gitignore ├── .media └── cpp3dgame_banner.jpg ├── DX3D ├── Include │ └── DX3D │ │ ├── All.h │ │ ├── Core │ │ ├── Base.h │ │ ├── Common.h │ │ ├── Core.h │ │ └── Logger.h │ │ ├── Game │ │ ├── Display.h │ │ └── Game.h │ │ ├── Math │ │ ├── Rect.h │ │ ├── Vec3.h │ │ └── Vec4.h │ │ └── Window │ │ └── Window.h └── Source │ └── DX3D │ ├── Core │ ├── Base.cpp │ └── Logger.cpp │ ├── Game │ ├── Display.cpp │ ├── Game.cpp │ └── Win32 │ │ └── Win32Game.cpp │ ├── Graphics │ ├── DeviceContext.cpp │ ├── DeviceContext.h │ ├── GraphicsDevice.cpp │ ├── GraphicsDevice.h │ ├── GraphicsEngine.cpp │ ├── GraphicsEngine.h │ ├── GraphicsLogUtils.h │ ├── GraphicsPipelineState.cpp │ ├── GraphicsPipelineState.h │ ├── GraphicsResource.h │ ├── GraphicsUtils.h │ ├── ShaderBinary.cpp │ ├── ShaderBinary.h │ ├── SwapChain.cpp │ ├── SwapChain.h │ ├── VertexBuffer.cpp │ └── VertexBuffer.h │ └── Window │ └── Win32 │ └── Win32Window.cpp ├── DirectXGame.sln ├── DirectXGame.vcxproj ├── DirectXGame.vcxproj.user ├── Game └── main.cpp ├── LICENSE └── README.md /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | patreon: pardcode 2 | custom: ["https://www.pardcode.com/donate"] 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # User-specific files 2 | *.userosscache 3 | *.suo 4 | *.userprefs 5 | 6 | # User-specific files for Visual Studio for Mac 7 | .vscode/ 8 | 9 | # Build results 10 | [Dd]ebug/ 11 | [Dd]ebugPublic/ 12 | [Dd]Release/ 13 | [Dd]ReleasePublic/ 14 | x64/ 15 | x86/ 16 | ARM/ 17 | arm64/ 18 | *.obj 19 | *.exe 20 | *.dll 21 | *.pdb 22 | *.idb 23 | *.ipdb 24 | *.iobj 25 | *.so 26 | *.lib 27 | *.a 28 | *.app 29 | *.dSYM/ 30 | 31 | # Uncomment if you have CMakeLists.txt 32 | # CMake specific files 33 | CMakeFiles/ 34 | CMakeCache.txt 35 | *.cmake 36 | *.dir 37 | 38 | # Windows Installer files 39 | *.cab 40 | *.msi 41 | *.msm 42 | *.msp 43 | 44 | # Windows Installer files (if you're using a setup project) 45 | *.wixpdb 46 | 47 | # Windows Store app package directory 48 | AppPackages/ 49 | 50 | # Windows Store app build output 51 | Packages/ 52 | 53 | # Windows User-specific files 54 | Thumbs.db 55 | Desktop.ini 56 | 57 | # JetBrains Rider / IntelliJ IDEA 58 | .idea/ 59 | 60 | # VS for Mac 61 | .vscode/ 62 | 63 | # VS Code specific files 64 | .vscode/ 65 | 66 | # NPM package directory for node-based build tools (such as Gulp, Grunt) 67 | node_modules/ 68 | 69 | # VS2019 files 70 | .vs2019/ 71 | 72 | # ASP.NET Core files (can be useful if you use this in a mixed C++/ASP.NET environment) 73 | wwwroot/ 74 | 75 | # Temporary folders used by Visual Studio 76 | .vs/ 77 | 78 | # Backup files 79 | *.bak 80 | *.swp -------------------------------------------------------------------------------- /.media/cpp3dgame_banner.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PardCode/CPP-3D-Game-Tutorial-Series/95423482a7a4f50e644ad69f1137212ab34977c8/.media/cpp3dgame_banner.jpg -------------------------------------------------------------------------------- /DX3D/Include/DX3D/All.h: -------------------------------------------------------------------------------- 1 | /*MIT License 2 | 3 | C++ 3D Game Tutorial Series (https://github.com/PardCode/CPP-3D-Game-Tutorial-Series) 4 | 5 | Copyright (c) 2019-2025, PardCode 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in all 15 | copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | SOFTWARE.*/ 24 | 25 | #pragma once 26 | 27 | #include -------------------------------------------------------------------------------- /DX3D/Include/DX3D/Core/Base.h: -------------------------------------------------------------------------------- 1 | /*MIT License 2 | 3 | C++ 3D Game Tutorial Series (https://github.com/PardCode/CPP-3D-Game-Tutorial-Series) 4 | 5 | Copyright (c) 2019-2025, PardCode 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in all 15 | copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | SOFTWARE.*/ 24 | 25 | #pragma once 26 | #include 27 | 28 | 29 | namespace dx3d 30 | { 31 | class Base 32 | { 33 | public: 34 | explicit Base(const BaseDesc& desc); 35 | virtual ~Base(); 36 | virtual Logger& getLogger() noexcept final; 37 | 38 | protected: 39 | Base(const Base&) = delete; 40 | Base(Base&&) = delete; 41 | Base& operator = (const Base&) = delete; 42 | Base& operator=(Base&&) = delete; 43 | 44 | protected: 45 | Logger& m_logger; 46 | }; 47 | } 48 | 49 | #define DX3DLogInfo(message)\ 50 | DX3DLog(getLogger(), Logger::LogLevel::Info, message) 51 | 52 | #define DX3DLogWarning(message)\ 53 | DX3DLog(getLogger(), Logger::LogLevel::Warning, message) 54 | 55 | #define DX3DLogError(message)\ 56 | DX3DLog(getLogger(), Logger::LogLevel::Error, message) 57 | 58 | #define DX3DLogThrowError(message)\ 59 | DX3DLogThrow(getLogger(), std::runtime_error, Logger::LogLevel::Error, message) 60 | 61 | #define DX3DLogThrowInvalidArg(message)\ 62 | DX3DLogThrow(getLogger(), std::invalid_argument, Logger::LogLevel::Error, message) 63 | 64 | -------------------------------------------------------------------------------- /DX3D/Include/DX3D/Core/Common.h: -------------------------------------------------------------------------------- 1 | /*MIT License 2 | 3 | C++ 3D Game Tutorial Series (https://github.com/PardCode/CPP-3D-Game-Tutorial-Series) 4 | 5 | Copyright (c) 2019-2025, PardCode 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in all 15 | copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | SOFTWARE.*/ 24 | 25 | #pragma once 26 | #include 27 | #include 28 | #include 29 | 30 | namespace dx3d 31 | { 32 | struct BaseDesc 33 | { 34 | Logger& logger; 35 | }; 36 | 37 | struct WindowDesc 38 | { 39 | BaseDesc base; 40 | Rect size{}; 41 | }; 42 | 43 | struct DisplayDesc 44 | { 45 | WindowDesc window; 46 | GraphicsDevice& graphicsDevice; 47 | }; 48 | 49 | struct GraphicsEngineDesc 50 | { 51 | BaseDesc base; 52 | }; 53 | 54 | struct GraphicsDeviceDesc 55 | { 56 | BaseDesc base; 57 | }; 58 | 59 | struct SwapChainDesc 60 | { 61 | void* winHandle{}; 62 | Rect winSize{}; 63 | }; 64 | 65 | enum class ShaderType 66 | { 67 | VertexShader = 0, 68 | PixelShader 69 | }; 70 | 71 | struct ShaderCompileDesc 72 | { 73 | const char* shaderSourceName{}; 74 | const void* shaderSourceCode{}; 75 | size_t shaderSourceCodeSize{}; 76 | const char* shaderEntryPoint{}; 77 | ShaderType shaderType{}; 78 | }; 79 | 80 | struct ShaderBinaryData 81 | { 82 | const void* data{}; 83 | size_t dataSize{}; 84 | }; 85 | 86 | struct GraphicsPipelineStateDesc 87 | { 88 | const ShaderBinary& vs; 89 | const ShaderBinary& ps; 90 | }; 91 | 92 | struct VertexBufferDesc 93 | { 94 | const void* vertexList{}; 95 | ui32 vertexListSize{}; 96 | ui32 vertexSize{}; 97 | }; 98 | 99 | 100 | struct GameDesc 101 | { 102 | Rect windowSize{ 1280,720 }; 103 | Logger::LogLevel logLevel = Logger::LogLevel::Error; 104 | }; 105 | } -------------------------------------------------------------------------------- /DX3D/Include/DX3D/Core/Core.h: -------------------------------------------------------------------------------- 1 | /*MIT License 2 | 3 | C++ 3D Game Tutorial Series (https://github.com/PardCode/CPP-3D-Game-Tutorial-Series) 4 | 5 | Copyright (c) 2019-2025, PardCode 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in all 15 | copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | SOFTWARE.*/ 24 | 25 | #pragma once 26 | #include 27 | #include 28 | 29 | namespace dx3d 30 | { 31 | class Base; 32 | class Window; 33 | class Game; 34 | class GraphicsEngine; 35 | class GraphicsDevice; 36 | class Logger; 37 | class SwapChain; 38 | class Display; 39 | class DeviceContext; 40 | class ShaderBinary; 41 | class GraphicsPipelineState; 42 | class VertexBuffer; 43 | 44 | using i32 = int; 45 | using ui32 = unsigned int; 46 | using f32 = float; 47 | using d64 = double; 48 | 49 | 50 | using SwapChainPtr = std::shared_ptr; 51 | using DeviceContextPtr = std::shared_ptr; 52 | using ShaderBinaryPtr = std::shared_ptr; 53 | using GraphicsPipelineStatePtr = std::shared_ptr; 54 | using VertexBufferPtr = std::shared_ptr; 55 | } -------------------------------------------------------------------------------- /DX3D/Include/DX3D/Core/Logger.h: -------------------------------------------------------------------------------- 1 | /*MIT License 2 | 3 | C++ 3D Game Tutorial Series (https://github.com/PardCode/CPP-3D-Game-Tutorial-Series) 4 | 5 | Copyright (c) 2019-2025, PardCode 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in all 15 | copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | SOFTWARE.*/ 24 | 25 | #pragma once 26 | 27 | 28 | 29 | 30 | namespace dx3d 31 | { 32 | class Logger final 33 | { 34 | public: 35 | enum class LogLevel 36 | { 37 | Error = 0, 38 | Warning, 39 | Info 40 | }; 41 | 42 | explicit Logger(LogLevel logLevel = LogLevel::Error); 43 | ~Logger(); 44 | 45 | void log(LogLevel level, const char* message); 46 | 47 | protected: 48 | Logger(const Logger&) = delete; 49 | Logger(Logger&&) = delete; 50 | Logger& operator = (const Logger&) = delete; 51 | Logger& operator=(Logger&&) = delete; 52 | 53 | private: 54 | LogLevel m_logLevel = LogLevel::Error; 55 | }; 56 | } 57 | 58 | 59 | #define DX3DLog(logger, type, message)\ 60 | logger.log((type), message) 61 | 62 | #define DX3DLogThrow(logger, exception, type, message)\ 63 | {\ 64 | DX3DLog(logger,type,message);\ 65 | throw exception(message);\ 66 | } -------------------------------------------------------------------------------- /DX3D/Include/DX3D/Game/Display.h: -------------------------------------------------------------------------------- 1 | /*MIT License 2 | 3 | C++ 3D Game Tutorial Series (https://github.com/PardCode/CPP-3D-Game-Tutorial-Series) 4 | 5 | Copyright (c) 2019-2025, PardCode 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in all 15 | copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | SOFTWARE.*/ 24 | 25 | #pragma once 26 | #include 27 | 28 | namespace dx3d 29 | { 30 | class Display final: public Window 31 | { 32 | public: 33 | explicit Display(const DisplayDesc& desc); 34 | 35 | SwapChain& getSwapChain() noexcept; 36 | private: 37 | SwapChainPtr m_swapChain{}; 38 | }; 39 | } 40 | 41 | -------------------------------------------------------------------------------- /DX3D/Include/DX3D/Game/Game.h: -------------------------------------------------------------------------------- 1 | /*MIT License 2 | 3 | C++ 3D Game Tutorial Series (https://github.com/PardCode/CPP-3D-Game-Tutorial-Series) 4 | 5 | Copyright (c) 2019-2025, PardCode 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in all 15 | copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | SOFTWARE.*/ 24 | 25 | #pragma once 26 | #include 27 | #include 28 | 29 | 30 | namespace dx3d 31 | { 32 | class Game: public Base 33 | { 34 | public: 35 | explicit Game(const GameDesc& desc); 36 | virtual ~Game() override; 37 | 38 | virtual void run() final; 39 | private: 40 | void onInternalUpdate(); 41 | private: 42 | std::unique_ptr m_loggerPtr{}; 43 | std::unique_ptr m_graphicsEngine{}; 44 | std::unique_ptr m_display{}; 45 | bool m_isRunning{ true }; 46 | }; 47 | } 48 | -------------------------------------------------------------------------------- /DX3D/Include/DX3D/Math/Rect.h: -------------------------------------------------------------------------------- 1 | /*MIT License 2 | 3 | C++ 3D Game Tutorial Series (https://github.com/PardCode/CPP-3D-Game-Tutorial-Series) 4 | 5 | Copyright (c) 2019-2025, PardCode 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in all 15 | copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | SOFTWARE.*/ 24 | 25 | #pragma once 26 | #include 27 | 28 | 29 | 30 | namespace dx3d 31 | { 32 | class Rect 33 | { 34 | public: 35 | Rect() = default; 36 | Rect(i32 width, i32 height) : left(0), top(0), width(width), height(height) {} 37 | Rect(i32 left, i32 top, i32 width, i32 height) : left(left), top(top), width(width), height(height) {} 38 | public: 39 | i32 left{}, top{}, width{}, height{}; 40 | }; 41 | 42 | 43 | 44 | } -------------------------------------------------------------------------------- /DX3D/Include/DX3D/Math/Vec3.h: -------------------------------------------------------------------------------- 1 | /*MIT License 2 | 3 | C++ 3D Game Tutorial Series (https://github.com/PardCode/CPP-3D-Game-Tutorial-Series) 4 | 5 | Copyright (c) 2019-2025, PardCode 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in all 15 | copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | SOFTWARE.*/ 24 | 25 | #pragma once 26 | #include 27 | 28 | 29 | namespace dx3d 30 | { 31 | class Vec3 32 | { 33 | public: 34 | Vec3() = default; 35 | Vec3(f32 x, f32 y, f32 z) : x(x), y(y), z(z) {} 36 | public: 37 | f32 x{}, y{}, z{}; 38 | }; 39 | } -------------------------------------------------------------------------------- /DX3D/Include/DX3D/Math/Vec4.h: -------------------------------------------------------------------------------- 1 | /*MIT License 2 | 3 | C++ 3D Game Tutorial Series (https://github.com/PardCode/CPP-3D-Game-Tutorial-Series) 4 | 5 | Copyright (c) 2019-2025, PardCode 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in all 15 | copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | SOFTWARE.*/ 24 | 25 | #pragma once 26 | #include 27 | 28 | namespace dx3d 29 | { 30 | class Vec4 31 | { 32 | public: 33 | Vec4() = default; 34 | Vec4(f32 x, f32 y, f32 z, f32 w) : x(x), y(y), z(z), w(w) {} 35 | public: 36 | f32 x{}, y{}, z{}, w{}; 37 | }; 38 | } -------------------------------------------------------------------------------- /DX3D/Include/DX3D/Window/Window.h: -------------------------------------------------------------------------------- 1 | /*MIT License 2 | 3 | C++ 3D Game Tutorial Series (https://github.com/PardCode/CPP-3D-Game-Tutorial-Series) 4 | 5 | Copyright (c) 2019-2025, PardCode 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in all 15 | copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | SOFTWARE.*/ 24 | 25 | #pragma once 26 | #include 27 | #include 28 | 29 | 30 | namespace dx3d 31 | { 32 | class Window: public Base 33 | { 34 | public: 35 | explicit Window(const WindowDesc& desc); 36 | virtual ~Window() override; 37 | 38 | protected: 39 | void* m_handle{}; 40 | Rect m_size{}; 41 | }; 42 | } 43 | 44 | -------------------------------------------------------------------------------- /DX3D/Source/DX3D/Core/Base.cpp: -------------------------------------------------------------------------------- 1 | /*MIT License 2 | 3 | C++ 3D Game Tutorial Series (https://github.com/PardCode/CPP-3D-Game-Tutorial-Series) 4 | 5 | Copyright (c) 2019-2025, PardCode 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in all 15 | copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | SOFTWARE.*/ 24 | 25 | #include 26 | using namespace dx3d; 27 | 28 | dx3d::Base::Base(const BaseDesc& desc): m_logger(desc.logger) 29 | { 30 | } 31 | 32 | dx3d::Base::~Base() 33 | { 34 | } 35 | 36 | Logger& dx3d::Base::getLogger() noexcept 37 | { 38 | return m_logger; 39 | } 40 | -------------------------------------------------------------------------------- /DX3D/Source/DX3D/Core/Logger.cpp: -------------------------------------------------------------------------------- 1 | /*MIT License 2 | 3 | C++ 3D Game Tutorial Series (https://github.com/PardCode/CPP-3D-Game-Tutorial-Series) 4 | 5 | Copyright (c) 2019-2025, PardCode 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in all 15 | copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | SOFTWARE.*/ 24 | 25 | #include 26 | #include 27 | 28 | dx3d::Logger::Logger(LogLevel logLevel): m_logLevel(logLevel) 29 | { 30 | std::clog << "PardCode | C++ 3D Game Tutorial Series" << "\n"; 31 | std::clog << "--------------------------------------" << "\n"; 32 | } 33 | 34 | dx3d::Logger::~Logger() 35 | { 36 | } 37 | 38 | void dx3d::Logger::log(LogLevel level, const char* message) 39 | { 40 | auto logLevelToString = [](LogLevel level) { 41 | switch (level) 42 | { 43 | case LogLevel::Info: return "Info"; 44 | case LogLevel::Warning: return "Warning"; 45 | case LogLevel::Error: return "Error"; 46 | default: return "Unknown"; 47 | } 48 | }; 49 | 50 | if (level > m_logLevel) return; 51 | std::clog << "[DX3D " << logLevelToString(level) << "]: " << message << "\n"; 52 | } 53 | -------------------------------------------------------------------------------- /DX3D/Source/DX3D/Game/Display.cpp: -------------------------------------------------------------------------------- 1 | /*MIT License 2 | 3 | C++ 3D Game Tutorial Series (https://github.com/PardCode/CPP-3D-Game-Tutorial-Series) 4 | 5 | Copyright (c) 2019-2025, PardCode 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in all 15 | copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | SOFTWARE.*/ 24 | 25 | #include 26 | #include 27 | 28 | dx3d::Display::Display(const DisplayDesc& desc): Window(desc.window) 29 | { 30 | m_swapChain = desc.graphicsDevice.createSwapChain({ m_handle, m_size }); 31 | } 32 | 33 | dx3d::SwapChain& dx3d::Display::getSwapChain() noexcept 34 | { 35 | return *m_swapChain; 36 | } 37 | -------------------------------------------------------------------------------- /DX3D/Source/DX3D/Game/Game.cpp: -------------------------------------------------------------------------------- 1 | /*MIT License 2 | 3 | C++ 3D Game Tutorial Series (https://github.com/PardCode/CPP-3D-Game-Tutorial-Series) 4 | 5 | Copyright (c) 2019-2025, PardCode 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in all 15 | copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | SOFTWARE.*/ 24 | 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | 31 | dx3d::Game::Game(const GameDesc& desc) : 32 | Base({*std::make_unique(desc.logLevel).release()}), 33 | m_loggerPtr(&m_logger) 34 | { 35 | m_graphicsEngine = std::make_unique(GraphicsEngineDesc{m_logger}); 36 | m_display = std::make_unique(DisplayDesc{ {m_logger,desc.windowSize},m_graphicsEngine->getGraphicsDevice()}); 37 | 38 | DX3DLogInfo("Game initialized."); 39 | } 40 | 41 | dx3d::Game::~Game() 42 | { 43 | DX3DLogInfo("Game is shutting down..."); 44 | } 45 | 46 | void dx3d::Game::onInternalUpdate() 47 | { 48 | m_graphicsEngine->render(m_display->getSwapChain()); 49 | } 50 | -------------------------------------------------------------------------------- /DX3D/Source/DX3D/Game/Win32/Win32Game.cpp: -------------------------------------------------------------------------------- 1 | /*MIT License 2 | 3 | C++ 3D Game Tutorial Series (https://github.com/PardCode/CPP-3D-Game-Tutorial-Series) 4 | 5 | Copyright (c) 2019-2025, PardCode 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in all 15 | copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | SOFTWARE.*/ 24 | 25 | #include 26 | #include 27 | 28 | 29 | void dx3d::Game::run() 30 | { 31 | MSG msg{}; 32 | while (m_isRunning) 33 | { 34 | while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) 35 | { 36 | if (msg.message == WM_QUIT) 37 | { 38 | m_isRunning = false; 39 | break; 40 | } 41 | 42 | TranslateMessage(&msg); 43 | DispatchMessage(&msg); 44 | } 45 | onInternalUpdate(); 46 | } 47 | 48 | } 49 | 50 | 51 | -------------------------------------------------------------------------------- /DX3D/Source/DX3D/Graphics/DeviceContext.cpp: -------------------------------------------------------------------------------- 1 | /*MIT License 2 | 3 | C++ 3D Game Tutorial Series (https://github.com/PardCode/CPP-3D-Game-Tutorial-Series) 4 | 5 | Copyright (c) 2019-2025, PardCode 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in all 15 | copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | SOFTWARE.*/ 24 | 25 | #include 26 | #include 27 | #include 28 | #include 29 | 30 | dx3d::DeviceContext::DeviceContext(const GraphicsResourceDesc& gDesc): GraphicsResource(gDesc) 31 | { 32 | DX3DGraphicsLogThrowOnFail(m_device.CreateDeferredContext(0, &m_context), 33 | "CreateDeferredContext failed."); 34 | } 35 | 36 | void dx3d::DeviceContext::clearAndSetBackBuffer(const SwapChain& swapChain, const Vec4& color) 37 | { 38 | f32 fColor[] = { color.x,color.y,color.z,color.w }; 39 | auto rtv = swapChain.m_rtv.Get(); 40 | m_context->ClearRenderTargetView(rtv, fColor); 41 | m_context->OMSetRenderTargets(1, &rtv, nullptr); 42 | } 43 | 44 | void dx3d::DeviceContext::setGraphicsPipelineState(const GraphicsPipelineState& pipeline) 45 | { 46 | m_context->IASetInputLayout(pipeline.m_layout.Get()); 47 | m_context->VSSetShader(pipeline.m_vs.Get(), nullptr, 0); 48 | m_context->PSSetShader(pipeline.m_ps.Get(), nullptr, 0); 49 | } 50 | 51 | void dx3d::DeviceContext::setVertexBuffer(const VertexBuffer& buffer) 52 | { 53 | auto stride = buffer.m_vertexSize; 54 | auto buf = buffer.m_buffer.Get(); 55 | auto offset = 0u; 56 | m_context->IASetVertexBuffers(0, 1, &buf, &stride, &offset); 57 | } 58 | 59 | void dx3d::DeviceContext::setViewportSize(const Rect& size) 60 | { 61 | D3D11_VIEWPORT vp{}; 62 | vp.Width = static_cast(size.width); 63 | vp.Height = static_cast(size.height); 64 | vp.MinDepth = 0.0f; 65 | vp.MaxDepth = 1.0f; 66 | m_context->RSSetViewports(1, &vp); 67 | } 68 | 69 | void dx3d::DeviceContext::drawTriangleList(ui32 vertexCount, ui32 startVertexLocation) 70 | { 71 | m_context->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST); 72 | m_context->Draw(vertexCount, startVertexLocation); 73 | } 74 | -------------------------------------------------------------------------------- /DX3D/Source/DX3D/Graphics/DeviceContext.h: -------------------------------------------------------------------------------- 1 | /*MIT License 2 | 3 | C++ 3D Game Tutorial Series (https://github.com/PardCode/CPP-3D-Game-Tutorial-Series) 4 | 5 | Copyright (c) 2019-2025, PardCode 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in all 15 | copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | SOFTWARE.*/ 24 | 25 | #pragma once 26 | #include 27 | #include 28 | 29 | namespace dx3d 30 | { 31 | class DeviceContext final: public GraphicsResource 32 | { 33 | public: 34 | explicit DeviceContext(const GraphicsResourceDesc& gDesc); 35 | void clearAndSetBackBuffer(const SwapChain& swapChain, const Vec4& color); 36 | void setGraphicsPipelineState(const GraphicsPipelineState& pipeline); 37 | void setVertexBuffer(const VertexBuffer& buffer); 38 | void setViewportSize(const Rect& size); 39 | void drawTriangleList(ui32 vertexCount, ui32 startVertexLocation); 40 | private: 41 | Microsoft::WRL::ComPtr m_context{}; 42 | 43 | friend class GraphicsDevice; 44 | }; 45 | } 46 | 47 | -------------------------------------------------------------------------------- /DX3D/Source/DX3D/Graphics/GraphicsDevice.cpp: -------------------------------------------------------------------------------- 1 | /*MIT License 2 | 3 | C++ 3D Game Tutorial Series (https://github.com/PardCode/CPP-3D-Game-Tutorial-Series) 4 | 5 | Copyright (c) 2019-2025, PardCode 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in all 15 | copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | SOFTWARE.*/ 24 | 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | using namespace dx3d; 33 | 34 | 35 | dx3d::GraphicsDevice::GraphicsDevice(const GraphicsDeviceDesc& desc): Base(desc.base) 36 | { 37 | D3D_FEATURE_LEVEL featureLevel{}; 38 | UINT createDeviceFlags{}; 39 | 40 | #ifdef _DEBUG 41 | createDeviceFlags |= D3D11_CREATE_DEVICE_DEBUG; 42 | #endif 43 | 44 | DX3DGraphicsLogThrowOnFail(D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, createDeviceFlags, 45 | NULL, 0, D3D11_SDK_VERSION, 46 | &m_d3dDevice, &featureLevel, &m_d3dContext), 47 | "Direct3D11 initialization failed."); 48 | 49 | DX3DGraphicsLogThrowOnFail(m_d3dDevice->QueryInterface(IID_PPV_ARGS(&m_dxgiDevice)), 50 | "QueryInterface failed to retrieve IDXGIDevice."); 51 | 52 | DX3DGraphicsLogThrowOnFail(m_dxgiDevice->GetParent(IID_PPV_ARGS(&m_dxgiAdapter)), 53 | "GetParent failed to retrieve IDXGIAdapter."); 54 | 55 | DX3DGraphicsLogThrowOnFail(m_dxgiAdapter->GetParent(IID_PPV_ARGS(&m_dxgiFactory)), 56 | "GetParent failed to retrieve IDXGIFactory."); 57 | 58 | } 59 | 60 | dx3d::GraphicsDevice::~GraphicsDevice() 61 | { 62 | } 63 | 64 | SwapChainPtr dx3d::GraphicsDevice::createSwapChain(const SwapChainDesc& desc) 65 | { 66 | return std::make_shared(desc, getGraphicsResourceDesc()); 67 | } 68 | 69 | DeviceContextPtr dx3d::GraphicsDevice::createDeviceContext() 70 | { 71 | return std::make_shared(getGraphicsResourceDesc()); 72 | } 73 | 74 | ShaderBinaryPtr dx3d::GraphicsDevice::compileShader(const ShaderCompileDesc& desc) 75 | { 76 | return std::make_shared(desc, getGraphicsResourceDesc()); 77 | } 78 | 79 | GraphicsPipelineStatePtr dx3d::GraphicsDevice::createGraphicsPipelineState(const GraphicsPipelineStateDesc& desc) 80 | { 81 | return std::make_shared(desc, getGraphicsResourceDesc()); 82 | } 83 | 84 | VertexBufferPtr dx3d::GraphicsDevice::createVertexBuffer(const VertexBufferDesc& desc) 85 | { 86 | return std::make_shared(desc, getGraphicsResourceDesc()); 87 | } 88 | 89 | void dx3d::GraphicsDevice::executeCommandList(DeviceContext& context) 90 | { 91 | Microsoft::WRL::ComPtr list{}; 92 | DX3DGraphicsLogThrowOnFail(context.m_context->FinishCommandList(false, &list), 93 | "FinishCommandList failed."); 94 | m_d3dContext->ExecuteCommandList(list.Get(), false); 95 | } 96 | 97 | GraphicsResourceDesc dx3d::GraphicsDevice::getGraphicsResourceDesc() const noexcept 98 | { 99 | return { {m_logger}, shared_from_this(), *m_d3dDevice.Get(), *m_dxgiFactory.Get() }; 100 | } 101 | -------------------------------------------------------------------------------- /DX3D/Source/DX3D/Graphics/GraphicsDevice.h: -------------------------------------------------------------------------------- 1 | /*MIT License 2 | 3 | C++ 3D Game Tutorial Series (https://github.com/PardCode/CPP-3D-Game-Tutorial-Series) 4 | 5 | Copyright (c) 2019-2025, PardCode 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in all 15 | copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | SOFTWARE.*/ 24 | 25 | #pragma once 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | 32 | namespace dx3d 33 | { 34 | class GraphicsDevice final: public Base, public std::enable_shared_from_this 35 | { 36 | public: 37 | explicit GraphicsDevice(const GraphicsDeviceDesc& desc); 38 | virtual ~GraphicsDevice() override; 39 | 40 | SwapChainPtr createSwapChain(const SwapChainDesc& desc); 41 | DeviceContextPtr createDeviceContext(); 42 | ShaderBinaryPtr compileShader(const ShaderCompileDesc& desc); 43 | GraphicsPipelineStatePtr createGraphicsPipelineState(const GraphicsPipelineStateDesc& desc); 44 | VertexBufferPtr createVertexBuffer(const VertexBufferDesc& desc); 45 | 46 | void executeCommandList(DeviceContext& context); 47 | private: 48 | GraphicsResourceDesc getGraphicsResourceDesc() const noexcept; 49 | private: 50 | Microsoft::WRL::ComPtr m_d3dDevice{}; 51 | Microsoft::WRL::ComPtr m_d3dContext{}; 52 | Microsoft::WRL::ComPtr m_dxgiDevice{}; 53 | Microsoft::WRL::ComPtr m_dxgiAdapter{}; 54 | Microsoft::WRL::ComPtr m_dxgiFactory{}; 55 | }; 56 | } 57 | 58 | -------------------------------------------------------------------------------- /DX3D/Source/DX3D/Graphics/GraphicsEngine.cpp: -------------------------------------------------------------------------------- 1 | /*MIT License 2 | 3 | C++ 3D Game Tutorial Series (https://github.com/PardCode/CPP-3D-Game-Tutorial-Series) 4 | 5 | Copyright (c) 2019-2025, PardCode 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in all 15 | copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | SOFTWARE.*/ 24 | 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | 32 | using namespace dx3d; 33 | 34 | dx3d::GraphicsEngine::GraphicsEngine(const GraphicsEngineDesc& desc): Base(desc.base) 35 | { 36 | m_graphicsDevice = std::make_shared(GraphicsDeviceDesc{m_logger}); 37 | 38 | auto& device = *m_graphicsDevice; 39 | m_deviceContext = device.createDeviceContext(); 40 | 41 | constexpr char shaderSourceCode[] = 42 | R"( 43 | float4 VSMain(float3 pos: POSITION): SV_Position 44 | { 45 | return float4(pos.xyz, 1.0); 46 | } 47 | float4 PSMain(): SV_Target 48 | { 49 | return float4(1.0, 1.0, 1.0, 1.0); 50 | } 51 | )"; 52 | constexpr char shaderSourceName[] = "Basic"; 53 | constexpr auto shaderSourceCodeSize = std::size(shaderSourceCode); 54 | 55 | auto vs = device.compileShader({shaderSourceName, shaderSourceCode, shaderSourceCodeSize, 56 | "VSMain", ShaderType::VertexShader}); 57 | auto ps = device.compileShader({ shaderSourceName, shaderSourceCode, shaderSourceCodeSize, 58 | "PSMain", ShaderType::PixelShader }); 59 | 60 | m_pipeline = device.createGraphicsPipelineState({ *vs,*ps }); 61 | 62 | const Vec3 vertexList[] = 63 | { 64 | {-0.5f, -0.5f, 0.0f}, 65 | {0.0f, 0.5f, 0.0f}, 66 | {0.5f, -0.5f, 0.0f} 67 | }; 68 | 69 | m_vb = device.createVertexBuffer({vertexList, std::size(vertexList), sizeof(Vec3)}); 70 | } 71 | 72 | dx3d::GraphicsEngine::~GraphicsEngine() 73 | { 74 | } 75 | 76 | GraphicsDevice& dx3d::GraphicsEngine::getGraphicsDevice() noexcept 77 | { 78 | return *m_graphicsDevice; 79 | } 80 | 81 | void dx3d::GraphicsEngine::render(SwapChain& swapChain) 82 | { 83 | auto& context = *m_deviceContext; 84 | context.clearAndSetBackBuffer(swapChain, { 1,0,0,1 }); 85 | context.setGraphicsPipelineState(*m_pipeline); 86 | 87 | context.setViewportSize(swapChain.getSize()); 88 | 89 | auto& vb = *m_vb; 90 | context.setVertexBuffer(vb); 91 | context.drawTriangleList(vb.getVertexListSize(), 0u); 92 | 93 | auto& device = *m_graphicsDevice; 94 | device.executeCommandList(context); 95 | swapChain.present(); 96 | } 97 | -------------------------------------------------------------------------------- /DX3D/Source/DX3D/Graphics/GraphicsEngine.h: -------------------------------------------------------------------------------- 1 | /*MIT License 2 | 3 | C++ 3D Game Tutorial Series (https://github.com/PardCode/CPP-3D-Game-Tutorial-Series) 4 | 5 | Copyright (c) 2019-2025, PardCode 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in all 15 | copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | SOFTWARE.*/ 24 | 25 | #pragma once 26 | #include 27 | #include 28 | 29 | namespace dx3d 30 | { 31 | class GraphicsEngine final: public Base 32 | { 33 | public: 34 | explicit GraphicsEngine(const GraphicsEngineDesc& desc); 35 | virtual ~GraphicsEngine() override; 36 | 37 | 38 | GraphicsDevice& getGraphicsDevice() noexcept; 39 | 40 | void render(SwapChain& swapChain); 41 | private: 42 | std::shared_ptr m_graphicsDevice{}; 43 | DeviceContextPtr m_deviceContext{}; 44 | GraphicsPipelineStatePtr m_pipeline{}; 45 | VertexBufferPtr m_vb{}; 46 | }; 47 | } 48 | 49 | -------------------------------------------------------------------------------- /DX3D/Source/DX3D/Graphics/GraphicsLogUtils.h: -------------------------------------------------------------------------------- 1 | /*MIT License 2 | 3 | C++ 3D Game Tutorial Series (https://github.com/PardCode/CPP-3D-Game-Tutorial-Series) 4 | 5 | Copyright (c) 2019-2025, PardCode 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in all 15 | copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | SOFTWARE.*/ 24 | 25 | #pragma once 26 | #include 27 | #include 28 | 29 | namespace dx3d 30 | { 31 | namespace GraphicsLogUtils 32 | { 33 | inline void CheckShaderCompile(Logger& logger, HRESULT hr, ID3DBlob* errorBlob) 34 | { 35 | auto errorMsg = errorBlob ? static_cast(errorBlob->GetBufferPointer()) : nullptr; 36 | 37 | if (FAILED(hr)) 38 | DX3DLogThrow(logger, std::runtime_error, Logger::LogLevel::Error, errorMsg ? errorMsg : 39 | "Shader compilation failed."); 40 | if (errorMsg) 41 | DX3DLog(logger, Logger::LogLevel::Warning, errorMsg); 42 | } 43 | 44 | } 45 | } 46 | 47 | #define DX3DGraphicsLogThrowOnFail(hr,message)\ 48 | {\ 49 | auto res = (hr);\ 50 | if (FAILED(res))\ 51 | DX3DLogThrowError(message);\ 52 | } 53 | 54 | 55 | #define DX3DGraphicsCheckShaderCompile(hr, errorBlob)\ 56 | {\ 57 | auto res = (hr);\ 58 | dx3d::GraphicsLogUtils::CheckShaderCompile(getLogger(), res, errorBlob);\ 59 | } -------------------------------------------------------------------------------- /DX3D/Source/DX3D/Graphics/GraphicsPipelineState.cpp: -------------------------------------------------------------------------------- 1 | /*MIT License 2 | 3 | C++ 3D Game Tutorial Series (https://github.com/PardCode/CPP-3D-Game-Tutorial-Series) 4 | 5 | Copyright (c) 2019-2025, PardCode 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in all 15 | copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | SOFTWARE.*/ 24 | 25 | #include 26 | #include 27 | 28 | dx3d::GraphicsPipelineState::GraphicsPipelineState(const GraphicsPipelineStateDesc& desc, 29 | const GraphicsResourceDesc& gDesc): 30 | GraphicsResource(gDesc) 31 | { 32 | if (desc.vs.getType() != ShaderType::VertexShader) 33 | DX3DLogThrowInvalidArg("The 'vs' member is not a valid vertex shader binary."); 34 | if (desc.ps.getType() != ShaderType::PixelShader) 35 | DX3DLogThrowInvalidArg("The 'ps' member is not a valid pixel shader binary."); 36 | 37 | auto vs = desc.vs.getData(); 38 | auto ps = desc.ps.getData(); 39 | 40 | constexpr D3D11_INPUT_ELEMENT_DESC elements[] = 41 | { 42 | {"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0} 43 | }; 44 | 45 | DX3DGraphicsLogThrowOnFail( 46 | m_device.CreateInputLayout(elements, std::size(elements), vs.data, vs.dataSize, &m_layout), 47 | "CreateInputLayout failed."); 48 | 49 | DX3DGraphicsLogThrowOnFail( 50 | m_device.CreateVertexShader(vs.data, vs.dataSize, nullptr, &m_vs), 51 | "CreateVertexShader failed."); 52 | 53 | DX3DGraphicsLogThrowOnFail( 54 | m_device.CreatePixelShader(ps.data, ps.dataSize, nullptr, &m_ps), 55 | "CreatePixelShader failed."); 56 | 57 | } 58 | -------------------------------------------------------------------------------- /DX3D/Source/DX3D/Graphics/GraphicsPipelineState.h: -------------------------------------------------------------------------------- 1 | /*MIT License 2 | 3 | C++ 3D Game Tutorial Series (https://github.com/PardCode/CPP-3D-Game-Tutorial-Series) 4 | 5 | Copyright (c) 2019-2025, PardCode 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in all 15 | copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | SOFTWARE.*/ 24 | 25 | #pragma once 26 | #include 27 | 28 | namespace dx3d 29 | { 30 | class GraphicsPipelineState final: public GraphicsResource 31 | { 32 | public: 33 | GraphicsPipelineState(const GraphicsPipelineStateDesc& desc, const GraphicsResourceDesc& gDesc); 34 | private: 35 | Microsoft::WRL::ComPtr m_vs{}; 36 | Microsoft::WRL::ComPtr m_ps{}; 37 | Microsoft::WRL::ComPtr m_layout{}; 38 | friend class DeviceContext; 39 | }; 40 | } 41 | 42 | -------------------------------------------------------------------------------- /DX3D/Source/DX3D/Graphics/GraphicsResource.h: -------------------------------------------------------------------------------- 1 | /*MIT License 2 | 3 | C++ 3D Game Tutorial Series (https://github.com/PardCode/CPP-3D-Game-Tutorial-Series) 4 | 5 | Copyright (c) 2019-2025, PardCode 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in all 15 | copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | SOFTWARE.*/ 24 | 25 | #pragma once 26 | #include 27 | #include 28 | #include 29 | 30 | #include 31 | #include 32 | 33 | namespace dx3d 34 | { 35 | struct GraphicsResourceDesc 36 | { 37 | BaseDesc base; 38 | std::shared_ptr graphicsDevice; 39 | ID3D11Device& device; 40 | IDXGIFactory& factory; 41 | }; 42 | 43 | class GraphicsResource : public Base 44 | { 45 | public: 46 | explicit GraphicsResource(const GraphicsResourceDesc& desc): 47 | Base(desc.base), 48 | m_graphicsDevice(desc.graphicsDevice), 49 | m_device(desc.device), 50 | m_factory(desc.factory) 51 | { 52 | } 53 | 54 | protected: 55 | std::shared_ptr m_graphicsDevice; 56 | ID3D11Device& m_device; 57 | IDXGIFactory& m_factory; 58 | }; 59 | } -------------------------------------------------------------------------------- /DX3D/Source/DX3D/Graphics/GraphicsUtils.h: -------------------------------------------------------------------------------- 1 | /*MIT License 2 | 3 | C++ 3D Game Tutorial Series (https://github.com/PardCode/CPP-3D-Game-Tutorial-Series) 4 | 5 | Copyright (c) 2019-2025, PardCode 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in all 15 | copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | SOFTWARE.*/ 24 | 25 | #pragma once 26 | #include 27 | 28 | namespace dx3d 29 | { 30 | namespace GraphicsUtils 31 | { 32 | inline const char* GetShaderModelTarget(ShaderType type) 33 | { 34 | switch (type) 35 | { 36 | case ShaderType::VertexShader: return "vs_5_0"; 37 | case ShaderType::PixelShader: return "ps_5_0"; 38 | default: return ""; 39 | } 40 | } 41 | } 42 | } -------------------------------------------------------------------------------- /DX3D/Source/DX3D/Graphics/ShaderBinary.cpp: -------------------------------------------------------------------------------- 1 | /*MIT License 2 | 3 | C++ 3D Game Tutorial Series (https://github.com/PardCode/CPP-3D-Game-Tutorial-Series) 4 | 5 | Copyright (c) 2019-2025, PardCode 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in all 15 | copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | SOFTWARE.*/ 24 | 25 | #include 26 | #include 27 | #include 28 | 29 | dx3d::ShaderBinary::ShaderBinary(const ShaderCompileDesc& desc, const GraphicsResourceDesc& gDesc): 30 | GraphicsResource(gDesc), m_type(desc.shaderType) 31 | { 32 | if (!desc.shaderSourceName) DX3DLogThrowInvalidArg("No shader source name provided."); 33 | if (!desc.shaderSourceCode) DX3DLogThrowInvalidArg("No shader source code provided."); 34 | if (!desc.shaderSourceCodeSize) DX3DLogThrowInvalidArg("No shader source code size provided."); 35 | if (!desc.shaderEntryPoint) DX3DLogThrowInvalidArg("No shader entry point provided."); 36 | 37 | UINT compileFlags{}; 38 | 39 | #ifdef _DEBUG 40 | compileFlags |= D3DCOMPILE_DEBUG; 41 | #endif 42 | 43 | Microsoft::WRL::ComPtr errorBlob{}; 44 | DX3DGraphicsCheckShaderCompile( 45 | D3DCompile( 46 | desc.shaderSourceCode, 47 | desc.shaderSourceCodeSize, 48 | desc.shaderSourceName, 49 | nullptr, 50 | nullptr, 51 | desc.shaderEntryPoint, 52 | dx3d::GraphicsUtils::GetShaderModelTarget(desc.shaderType), 53 | compileFlags, 54 | 0, 55 | &m_blob, 56 | &errorBlob 57 | ), 58 | errorBlob.Get() 59 | ); 60 | 61 | 62 | } 63 | 64 | dx3d::ShaderBinaryData dx3d::ShaderBinary::getData() const noexcept 65 | { 66 | return 67 | { 68 | m_blob->GetBufferPointer(), 69 | m_blob->GetBufferSize() 70 | }; 71 | } 72 | 73 | dx3d::ShaderType dx3d::ShaderBinary::getType() const noexcept 74 | { 75 | return m_type; 76 | } 77 | -------------------------------------------------------------------------------- /DX3D/Source/DX3D/Graphics/ShaderBinary.h: -------------------------------------------------------------------------------- 1 | /*MIT License 2 | 3 | C++ 3D Game Tutorial Series (https://github.com/PardCode/CPP-3D-Game-Tutorial-Series) 4 | 5 | Copyright (c) 2019-2025, PardCode 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in all 15 | copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | SOFTWARE.*/ 24 | 25 | #pragma once 26 | #include 27 | 28 | namespace dx3d 29 | { 30 | class ShaderBinary final: public GraphicsResource 31 | { 32 | public: 33 | ShaderBinary(const ShaderCompileDesc& desc, const GraphicsResourceDesc& gDesc); 34 | ShaderBinaryData getData() const noexcept; 35 | ShaderType getType() const noexcept; 36 | private: 37 | Microsoft::WRL::ComPtr m_blob{}; 38 | ShaderType m_type{}; 39 | }; 40 | } 41 | 42 | -------------------------------------------------------------------------------- /DX3D/Source/DX3D/Graphics/SwapChain.cpp: -------------------------------------------------------------------------------- 1 | /*MIT License 2 | 3 | C++ 3D Game Tutorial Series (https://github.com/PardCode/CPP-3D-Game-Tutorial-Series) 4 | 5 | Copyright (c) 2019-2025, PardCode 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in all 15 | copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | SOFTWARE.*/ 24 | 25 | #include 26 | 27 | dx3d::SwapChain::SwapChain(const SwapChainDesc& desc, const GraphicsResourceDesc& gDesc) : 28 | GraphicsResource(gDesc), m_size(desc.winSize) 29 | { 30 | if (!desc.winHandle) DX3DLogThrowInvalidArg("No window handle provided."); 31 | 32 | DXGI_SWAP_CHAIN_DESC dxgiDesc{}; 33 | 34 | dxgiDesc.BufferDesc.Width = std::max(1, desc.winSize.width); 35 | dxgiDesc.BufferDesc.Height = std::max(1, desc.winSize.height); 36 | dxgiDesc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; 37 | dxgiDesc.BufferCount = 2; 38 | dxgiDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; 39 | 40 | dxgiDesc.OutputWindow = static_cast(desc.winHandle); 41 | dxgiDesc.SampleDesc.Count = 1; 42 | dxgiDesc.SwapEffect = DXGI_SWAP_EFFECT_FLIP_DISCARD; 43 | dxgiDesc.Windowed = TRUE; 44 | 45 | DX3DGraphicsLogThrowOnFail(m_factory.CreateSwapChain(&m_device, &dxgiDesc, &m_swapChain), 46 | "CreateSwapChain failed."); 47 | 48 | reloadBuffers(); 49 | } 50 | 51 | dx3d::Rect dx3d::SwapChain::getSize() const noexcept 52 | { 53 | return m_size; 54 | } 55 | 56 | void dx3d::SwapChain::present(bool vsync) 57 | { 58 | DX3DGraphicsLogThrowOnFail(m_swapChain->Present(vsync, 0), 59 | "Present failed."); 60 | } 61 | 62 | void dx3d::SwapChain::reloadBuffers() 63 | { 64 | Microsoft::WRL::ComPtr buffer{}; 65 | DX3DGraphicsLogThrowOnFail(m_swapChain->GetBuffer(0, IID_PPV_ARGS(&buffer)), 66 | "GetBuffer failed."); 67 | DX3DGraphicsLogThrowOnFail(m_device.CreateRenderTargetView(buffer.Get(), nullptr, &m_rtv), 68 | "CreateRenderTargetView failed."); 69 | } 70 | 71 | -------------------------------------------------------------------------------- /DX3D/Source/DX3D/Graphics/SwapChain.h: -------------------------------------------------------------------------------- 1 | /*MIT License 2 | 3 | C++ 3D Game Tutorial Series (https://github.com/PardCode/CPP-3D-Game-Tutorial-Series) 4 | 5 | Copyright (c) 2019-2025, PardCode 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in all 15 | copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | SOFTWARE.*/ 24 | 25 | #pragma once 26 | #include 27 | 28 | namespace dx3d 29 | { 30 | class SwapChain final: public GraphicsResource 31 | { 32 | public: 33 | SwapChain(const SwapChainDesc& desc, const GraphicsResourceDesc& gDesc); 34 | Rect getSize() const noexcept; 35 | 36 | void present(bool vsync = false); 37 | private: 38 | void reloadBuffers(); 39 | private: 40 | Microsoft::WRL::ComPtr m_swapChain{}; 41 | Microsoft::WRL::ComPtr m_rtv{}; 42 | Rect m_size{}; 43 | 44 | friend class DeviceContext; 45 | }; 46 | } 47 | 48 | -------------------------------------------------------------------------------- /DX3D/Source/DX3D/Graphics/VertexBuffer.cpp: -------------------------------------------------------------------------------- 1 | /*MIT License 2 | 3 | C++ 3D Game Tutorial Series (https://github.com/PardCode/CPP-3D-Game-Tutorial-Series) 4 | 5 | Copyright (c) 2019-2025, PardCode 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in all 15 | copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | SOFTWARE.*/ 24 | 25 | #include 26 | 27 | dx3d::VertexBuffer::VertexBuffer(const VertexBufferDesc& desc, const GraphicsResourceDesc& gDesc): 28 | GraphicsResource(gDesc), m_vertexSize(desc.vertexSize), m_vertexListSize(desc.vertexListSize) 29 | { 30 | if (!desc.vertexList) DX3DLogThrowInvalidArg("No vertex list provided."); 31 | if (!desc.vertexListSize) DX3DLogThrowInvalidArg("Vertex list size must be non-zero."); 32 | if (!desc.vertexSize) DX3DLogThrowInvalidArg("Vertex size must be non-zero."); 33 | 34 | D3D11_BUFFER_DESC buffDesc{}; 35 | buffDesc.ByteWidth = desc.vertexListSize * desc.vertexSize; 36 | buffDesc.BindFlags = D3D11_BIND_VERTEX_BUFFER; 37 | 38 | D3D11_SUBRESOURCE_DATA initData{}; 39 | initData.pSysMem = desc.vertexList; 40 | 41 | DX3DGraphicsLogThrowOnFail( 42 | m_device.CreateBuffer(&buffDesc, &initData, &m_buffer), 43 | "CreateBuffer failed."); 44 | } 45 | 46 | dx3d::ui32 dx3d::VertexBuffer::getVertexListSize() const noexcept 47 | { 48 | return m_vertexListSize; 49 | } 50 | -------------------------------------------------------------------------------- /DX3D/Source/DX3D/Graphics/VertexBuffer.h: -------------------------------------------------------------------------------- 1 | /*MIT License 2 | 3 | C++ 3D Game Tutorial Series (https://github.com/PardCode/CPP-3D-Game-Tutorial-Series) 4 | 5 | Copyright (c) 2019-2025, PardCode 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in all 15 | copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | SOFTWARE.*/ 24 | 25 | #pragma once 26 | #include 27 | 28 | namespace dx3d 29 | { 30 | class VertexBuffer final: public GraphicsResource 31 | { 32 | public: 33 | VertexBuffer(const VertexBufferDesc& desc, const GraphicsResourceDesc& gDesc); 34 | ui32 getVertexListSize() const noexcept; 35 | private: 36 | Microsoft::WRL::ComPtr m_buffer{}; 37 | ui32 m_vertexSize{}; 38 | ui32 m_vertexListSize{}; 39 | 40 | friend class DeviceContext; 41 | }; 42 | } 43 | 44 | -------------------------------------------------------------------------------- /DX3D/Source/DX3D/Window/Win32/Win32Window.cpp: -------------------------------------------------------------------------------- 1 | /*MIT License 2 | 3 | C++ 3D Game Tutorial Series (https://github.com/PardCode/CPP-3D-Game-Tutorial-Series) 4 | 5 | Copyright (c) 2019-2025, PardCode 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in all 15 | copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | SOFTWARE.*/ 24 | 25 | #include 26 | #include 27 | #include 28 | 29 | static LRESULT CALLBACK WindowProcedure(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) 30 | { 31 | switch (msg) 32 | { 33 | case WM_CLOSE: 34 | { 35 | PostQuitMessage(0); 36 | break; 37 | } 38 | default: 39 | return DefWindowProc(hwnd, msg, wparam, lparam); 40 | } 41 | return 0; 42 | } 43 | 44 | 45 | 46 | 47 | 48 | 49 | dx3d::Window::Window(const WindowDesc& desc) : Base(desc.base), m_size(desc.size) 50 | { 51 | auto registerWindowClassFunction = []() 52 | { 53 | WNDCLASSEX wc{}; 54 | wc.cbSize = sizeof(WNDCLASSEX); 55 | wc.lpszClassName = L"DX3DWindow"; 56 | wc.lpfnWndProc = &WindowProcedure; 57 | return RegisterClassEx(&wc); 58 | }; 59 | 60 | 61 | static const auto windowClassId = std::invoke(registerWindowClassFunction); 62 | 63 | 64 | if (!windowClassId) 65 | DX3DLogThrowError("RegisterClassEx failed."); 66 | 67 | RECT rc{ 0,0,m_size.width, m_size.height }; 68 | AdjustWindowRect(&rc, WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU, false); 69 | 70 | m_handle = CreateWindowEx(NULL, MAKEINTATOM(windowClassId), L"PardCode | C++ 3D Game Tutorial Series", 71 | WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU, CW_USEDEFAULT, CW_USEDEFAULT, 72 | rc.right - rc.left, rc.bottom - rc.top, 73 | NULL, NULL, NULL, NULL); 74 | 75 | if (!m_handle) 76 | DX3DLogThrowError("CreateWindowEx failed."); 77 | 78 | ShowWindow(static_cast(m_handle), SW_SHOW); 79 | } 80 | 81 | 82 | dx3d::Window::~Window() 83 | { 84 | DestroyWindow(static_cast(m_handle)); 85 | } 86 | -------------------------------------------------------------------------------- /DirectXGame.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.11.35303.130 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "DirectXGame", "DirectXGame.vcxproj", "{98E7AFFC-3DA9-4678-9714-A2008D65BE20}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|x64 = Debug|x64 11 | Debug|x86 = Debug|x86 12 | Release|x64 = Release|x64 13 | Release|x86 = Release|x86 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {98E7AFFC-3DA9-4678-9714-A2008D65BE20}.Debug|x64.ActiveCfg = Debug|x64 17 | {98E7AFFC-3DA9-4678-9714-A2008D65BE20}.Debug|x64.Build.0 = Debug|x64 18 | {98E7AFFC-3DA9-4678-9714-A2008D65BE20}.Debug|x86.ActiveCfg = Debug|Win32 19 | {98E7AFFC-3DA9-4678-9714-A2008D65BE20}.Debug|x86.Build.0 = Debug|Win32 20 | {98E7AFFC-3DA9-4678-9714-A2008D65BE20}.Release|x64.ActiveCfg = Release|x64 21 | {98E7AFFC-3DA9-4678-9714-A2008D65BE20}.Release|x64.Build.0 = Release|x64 22 | {98E7AFFC-3DA9-4678-9714-A2008D65BE20}.Release|x86.ActiveCfg = Release|Win32 23 | {98E7AFFC-3DA9-4678-9714-A2008D65BE20}.Release|x86.Build.0 = Release|Win32 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | GlobalSection(ExtensibilityGlobals) = postSolution 29 | SolutionGuid = {7D4E1F90-BE4E-4EA1-A2F2-384E191BAF40} 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /DirectXGame.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | Debug 14 | x64 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | 17.0 23 | Win32Proj 24 | {98e7affc-3da9-4678-9714-a2008d65be20} 25 | DirectXGame 26 | 10.0 27 | 28 | 29 | 30 | Application 31 | true 32 | v143 33 | Unicode 34 | 35 | 36 | Application 37 | false 38 | v143 39 | true 40 | Unicode 41 | 42 | 43 | Application 44 | true 45 | v143 46 | Unicode 47 | 48 | 49 | Application 50 | false 51 | v143 52 | true 53 | Unicode 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | Bin\$(Platform)\$(Configuration)\ 75 | Intermediate\$(Platform)\$(Configuration)\ 76 | DX3D/Include;DX3D/Source;$(IncludePath) 77 | 78 | 79 | 80 | Level3 81 | true 82 | WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) 83 | true 84 | 85 | 86 | Console 87 | true 88 | 89 | 90 | 91 | 92 | Level3 93 | true 94 | true 95 | true 96 | WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 97 | true 98 | 99 | 100 | Console 101 | true 102 | true 103 | true 104 | 105 | 106 | 107 | 108 | Level3 109 | true 110 | _DEBUG;_CONSOLE;NOMINMAX;%(PreprocessorDefinitions) 111 | true 112 | stdcpp20 113 | true 114 | 115 | 116 | Console 117 | true 118 | d3d11.lib;d3dcompiler.lib;%(AdditionalDependencies) 119 | 120 | 121 | 122 | 123 | Level3 124 | true 125 | true 126 | true 127 | NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 128 | true 129 | 130 | 131 | Console 132 | true 133 | true 134 | true 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | -------------------------------------------------------------------------------- /DirectXGame.vcxproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | true 5 | 6 | -------------------------------------------------------------------------------- /Game/main.cpp: -------------------------------------------------------------------------------- 1 | /*MIT License 2 | 3 | C++ 3D Game Tutorial Series (https://github.com/PardCode/CPP-3D-Game-Tutorial-Series) 4 | 5 | Copyright (c) 2019-2025, PardCode 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in all 15 | copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | SOFTWARE.*/ 24 | 25 | #include 26 | 27 | 28 | int main() 29 | { 30 | try 31 | { 32 | dx3d::Game game({ {1280,720},dx3d::Logger::LogLevel::Info }); 33 | game.run(); 34 | } 35 | catch (const std::runtime_error&) 36 | { 37 | return EXIT_FAILURE; 38 | } 39 | catch (const std::invalid_argument&) 40 | { 41 | return EXIT_FAILURE; 42 | } 43 | catch (const std::exception&) 44 | { 45 | return EXIT_FAILURE; 46 | } 47 | catch (...) 48 | { 49 | return EXIT_FAILURE; 50 | } 51 | 52 | 53 | 54 | return EXIT_SUCCESS; 55 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | C++ 3D Game Tutorial Series (https://github.com/PardCode/CPP-3D-Game-Tutorial-Series) 4 | 5 | Copyright (c) 2019-2025, PardCode 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in all 15 | copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | SOFTWARE. 24 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ![C++ 3D Game Tutorial Series](.media/cpp3dgame_banner.jpg) 2 | 3 | [![CPP20](https://img.shields.io/badge/C++-20-blue)]() 4 | [![Discord channel](https://img.shields.io/discord/622797245368238082?logo=discord)](https://discord.gg/RymBzwKPyZ) 5 | [![Patreon](https://img.shields.io/badge/Donate-Patreon-orange)](https://www.patreon.com/pardcode) 6 | [![YouTube](https://img.shields.io/badge/Watch-YouTube-red)](https://www.youtube.com/playlist?list=PLv8DnRaQOs5-ST_VDqgbbMRtzMtpK36Hy) 7 | [![Code](https://img.shields.io/badge/Tutorial-List-blue)](https://github.com/PardCode/CPP-3D-Game-Tutorial-Series/tags) 8 | 9 | ## C++ 3D Game Tutorial Series 10 | `C++ 3D Game Tutorial Series` is a tutorial series designed to help developers of all levels—from novice to expert—take their first steps into game development from scratch using C++. 11 | This series will teach you how to create a 3D game sample, 12 | starting with creating a window using the Win32 API and progressing to building a game engine that enables the development of a functional 3D game. 13 | Specifically, the series covers the development of: 14 | * DX3D Game Engine (composed by the following sub-systems) 15 | * DirectX 11 3D Graphics Engine 16 | * Win32 Windowing System 17 | * Input System 18 | * Entity-Component System 19 | * Game Sample 20 | 21 | The aim of this series is to provide developers with the foundational knowledge needed to have full control over game development, 22 | starting from low-level systems (such as the Graphics Engine, Input Manager, Entity System etc.) 23 | all the way to high-level concepts (e.g. Entities). 24 | 25 | This repository contains: 26 | * The `master` branch, which contains the source code of the entire project developed in the tutorial series. 27 | * The `DX3D` folder, which contains both the public API and the source code of the DX3D engine, that will be implemented and used to create the game sample. 28 | * The `Game` folder, which contains the source code of the game sample itself. 29 | 30 | It is possible to access the source code of each tutorial by checking the [`Tags`](https://github.com/PardCode/CPP-3D-Game-Tutorial-Series/tags) list. 31 | 32 | Additionally, the repository includes branches such as `AssetsAndLibs`, which are related to the previous version of the C++ 3D Game Tutorial Series. 33 | 34 | The license of this repository is available [here](#license). 35 | 36 | 37 | ## Quick Guide to build the 3D Game Sample 38 | 39 | ### Prerequisites: 40 | * Visual Studio 2022. 41 | * Windows 10 or later. 42 | 43 | Open `DirectXGame.sln` project, available under the project root folder.
44 | In Visual Studio, press the `Local Windows Debugger` button available in the toolbar. 45 | 46 | ## Public discussion forum 47 | [The Discord Server](https://discord.gg/RymBzwKPyZ) is the go-to place for news about the tutorial series, discussions on the latest developments, 48 | and any questions you may have about the `C++ 3D Game Tutorial Series`. 49 | 50 | [![Discord channel](https://img.shields.io/discord/622797245368238082?logo=discord)](https://discord.gg/RymBzwKPyZ) 51 | 52 | ## Support 53 | This project is offered under the free and permissive MIT license, but it requires financial support to continue its development.
54 | If the `C++ 3D Game Tutorial Series` has been helpful to you, consider supporting it through [`Patreon`](https://www.patreon.com/pardcode).
55 | Every contribution makes the difference, no matter the amount.
56 | A big thank you to all the patrons who have supported me so far!
57 | 58 | [![Patreon](https://img.shields.io/badge/Donate-Patreon-orange)](https://www.patreon.com/pardcode) 59 | 60 | ## License 61 | 62 | The license for this project is based on the modified MIT License. 63 | 64 | This means you are free to use, modify, and distribute the code from this repository. However, there are two conditions you must follow: 65 | 66 | * Include the license text in your product (e.g., in the "About" window of a GUI application or the "About/Credits" section of a 2D/3D video game). 67 | * Include the license text in all source code files (copy and paste the license text at the top of each source code file you obtain from this repository, even if you have made partial modifications). 68 | 69 | If you wish to modify and redistribute the source code files, you may optionally add your own copyright notice alongside the license text, as follows: 70 | 71 | ``` 72 | ... 73 | C++ 3D Game Tutorial Series (https://github.com/PardCode/CPP-3D-Game-Tutorial-Series) 74 | , 75 | 76 | Copyright (c) 2019-2025, PardCode 77 | Copyright (c) , 78 | ... 79 | ``` 80 | 81 | The license text is available in the [`LICENSE`](LICENSE) file. 82 | 83 | 84 | --------------------------------------------------------------------------------