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.
* 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.
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.
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.
If you would like to support The Cherno for his helpful educational content, you can do so through his Patreon page.