/nim-opengl-tutorials-by-the-cherno

The Cherno's OpenGL Tutorials written in Nim.

Primary LanguageNim

The Cherno's OpenGL Tutorials (for Nim)

I followed The Cherno's OpenGL tutorial series on YouTube to learn OpenGL for Nim. In his tutorials, he uses C++, but since Nim's OpenGL code is very similar to the C++ code, it was easy to translate his code into Nim. I wanted to create this repo to potential help others who wanted to learn OpenGL for Nim, but were struggling to translate the available C++ tutorial into Nim code. In The Cherno's tutorials, he starts with the basics and gradually builds up a code base. I stored the state of the code at the end of each episode in a separate folder. I skipped creating separate folders for the first 6 episodes since it wasn't until the 7th episode that something was drawn to the screen. So the ep07 folder contains the combined code of working through episodes 1 through 7. Likewise, any other skipped episodes are just ones where there wasn't enough of a change in the code to warrant it having its own folder, so the progress made in that episode will just be combined into the folder for the next episode.

The Videos and the Associated Code

YouTube Video(s) Source Code
1. Welcome to OpenGL
2. Setting up OpenGL and Creating a Window in C++
3. Using Modern OpenGL in C++
4. Vertex Buffers and Drawing a Triangle in OpenGL
5. Vertex Attributes and Layouts in OpenGL
6. How Shaders Work in OpenGL
7. Writing a Shader in OpenGL
ep07
8. How I Deal with Shaders in OpenGL ep08
9. Index Buffers in OpenGL ep09
10. Dealing with Errors in OpenGL ep10
11. Uniforms in OpenGL ep11
12. Vertex Arrays in OpenGL
13. Abstracting OpenGL into Classes
ep13
14. Buffer Layout Abstraction in OpenGL ep14
15. Shader Abstraction in OpenGL ep15
16. Writing a Basic Renderer in OpenGL ep16
17. Textures in OpenGL ep17
18. Blending in OpenGL
19. Maths in OpenGL
ep19
20. Projection Matrices in OpenGL ep20
21. Model View Projection Matrices in OpenGL ep21
22. ImGui in OpenGL ep22
23. Rendering Multiple Objects in OpenGL ep23
24. Setting up a Test Framework for OpenGL ep24
25. Creating Tests in OpenGL ep25
26. Creating a Texture Test in OpenGL ep26
27. How to make your UNIFORMS FASTER in OpenGL
28. Batch Rendering - An Introduction
29. Batch Rendering - Colors
30. Batch Rendering - Textures
31. Batch Rendering - Dynamic Geometry
no code*

* Episodes 27 - 31 don't build upon the same code base from previous episodes, so I didn't write the Nim code for them. But they are still informative episodes to watch and if you wanted to implement them, you will know how to from having gone through the first 26 episodes.

To Run the Code

Each episode directory contains an app.nim file that will run the code for that episode. For example, to run ep07/app.nim, run the following command from the repos root directory:

nim r --gc:orc ep07/app.nim

I specify the ORC garbage collector because I use the `=destroy`() destructor syntax which I don't think gets called with the current default garbage collector.

Episode 22 introduces using ImGui. To get it to work, I put the compiled cimgui file (cimgui.dylib) into my project's root directory. However, I compiled cimgui on my macOS system, so if you are on a different system, you might have to compile your own version of cimgui to get ImGui to work. You can find more info about compiling cimgui here.

Notes

I didn't do everything exactly the same as The Cherno did, for example, I didn't do error checking on every OpenGL call, but instead just created a checkErrors() proc that I could call at different locations to probe for errors when needed. Also, I coded things a little differently than he did is some places, but for the most part it should be clear where my code differs from what is presented in the videos.

Hopefully this code will make it easier for you to learn OpenGL for Nim.

If you have any questions or suggestions, please open an issue.

The Cherno's Patreon

If you would like to support The Cherno for his helpful educational content, you can do so through his Patreon page.