My Journey Of Building Graphics Rendering Engine Using Vulkan SDK | Week 1
Vulkan is a comparatively new 3D Graphics Rendering API which is used to develop high performance 3D Graphics Applications. It’s free, Cross-Platform, supports wide range of devices and is now ready to make it’s footmark in cloud gaming with upcoming “Google Stadia” game streaming service.
Hi Everyone! Last couple of weeks ago, I posted on social media about my new project, Cross-Platform Graphics Rendering Engine and its development plan. This Personal Programming Project is being developed as a part of Programming-III curriculum for my Master’s in Interactive Entertainment ( Video Games Development ). The Reason I decided to do this because I want to foray myself into Graphics Programming Sector which is unknown territory for me and It’s challenging. Also, it’s so much satisfying to see your code manipulating 3D objects on screen. ( Remember old school days of using Graphics.h in Turbo C IDE ? 🙂 Current generation 3D API’s are much more powerful and sophisticated than that. ) During spring break, I contacted some alumni and asked their advice & suggestions about my topic. I’m going to follow their feedback during this entire development cycle.
As summer semester commenced, In the first week, we all programmers presented our desired topics. This was my presentation.
My professors Dr. Varcholik and Dr. Carbone gave me feedback that I’ve over-scoped my project as this semester is only 3 months long and I might not be able to finish all modules considering I am new to graphics programming. So I decided to drop cross-platform support and make this project target Microsoft Windows only. My revised development plan is still the same with some minor changes ( Splitting 2nd week task & Adding buffer week ). Here’s my revised schedule for this project.
For this entire project, I am going follow Real-Time Rendering book written by my Professor Dr. Varcholik. Its excellent and I highly recommend it if and wish to foray into graphics programming regardless of your skill level. I will be also following couple of online tutorials and documentation provided by Khronos ( Who maintains Vulkan API ).
( All links & Setup Instructions are available on this project’s GitHub repository ).
So, lets look into what I’ve achieved in this first week. My goal was to create a basic solution with main rendering loop to display window which will be connected to timer. Feel free to visit my GitHub repository to checkout my project and download code files.
Link to This Project’s GitHub Repository
These are the important parts of Implementation for this week.
- Learning CMake Build System and Create CMake Solution in Visual Studio 2019.
- Using Vcpkg ( Microsoft’s Package Manager ) to handle C++ dependencies for CMake Project.
- Install Vulkan SDK and Integrate it with CMake.
- Use GLFW 3.3 library for window creation and create main rendering loop ( Initializing basic dependencies ).
- Create a batch file for hassle free building project for naive users.
You can go to “releases” section on my GitHub repo and download zip file under tag “Week_I_Progress“. So You can look into the code which I’m referencing here.
I’ve tried to use latest and up to date versions for all dependencies I am using in this project. CMakeLists.txt file is configuration file for CMake. Where, I’ve set the Compiler flags to Enable Level 4 Warnings and Treat Linker Warnings as errors ( /W4 /WX ). We are also using C++17 standard for our project. Next, we find required dependencies and Include directories for the same. At the end, executable is created with all source files and linked with required libraries.
Linking Dependencies is very important thing and hence we’re using Vcpkg for the same. Its great package manager with integrates seamlessly with Visual Studio. If you’re using Visual Studio 2019, then VS will automatically refer to CMake buildsystem file in your Vcpkg directory. You don’t even need to add any explicit reference.
To download Vulkan SDK, You need to Visit LunarG website and download latest SDK. Install it to any directory. It will automatically set any required Environment Variables. If not, you can manually target Path to target Vulkan library directory.
At this point you’re ready to run the project ( considering you’ve followed steps defined on the GitHub repository ). There are 4 targets targeting Debug and Release Builds for 32-Bit and 64-Bit Windows. I’ve provided CMakeSettings.json file which will configure with visual studio to create 4 different target build folders. There won’t be any build directly at first but when you open this project folder in visual studio, VS will automatically generate CMake Cache during with build directories for desired target will be created.
Once you run the project, All you will see is a blank window. That’s the expected behavior as we haven’t added any functionality to our project yet apart from creating window. Now lets look into source files.
Here we have main.cpp which is the starting point of our Engine. It’s coupled with Renderer class in Renderer(.h & .cpp) who does all Initialization & rendering work. main() method simply Instantiate our Renderer and call Run() method on it.
Looking into Renderer class, currently, 3 methods have important implementations.
- We Initialize Window first by calling glfwCreateWindow() function inside InitializeWindow() method.
- We are using Vulkan-hpp ( C++ Wrapper ) to call underlying C functionality. Vulkan Uses Structs to store data and hence we will deal more with structs than passing parameters through function. In CreateVulcanInstance() method, we are defining 2 structs viz., ApplicationInfo and CreateInstanceInfo. Then we are creating Unique Instance which we don’t need to destroy on finishing work as It’ll be automatically destroyed after going out of scope.
- In Run() method, we are running our main loop. where glfwPollEvents() processes all pending events. Run() also calls Update() and Draw() methods. These method will be used in the future implementations.
So, getting started with Vulkan is pretty straightforward and we’re now moving to Implementing Triangle on the screen. I have split this bigger task as I want to write all boilerplate code to understand core basics.
I hope that you’ve found this dev diary informative and useful. Feel free to comment down below on what do you think and also if you have any questions or requests, You’re most welcome!
Thanks for visiting. Have a great day ahead.. 🙂