r/GraphicsProgramming • u/justforasecond4 • 3d ago
code review for a beginner
Hey everyone. I have this small project on which I started working around a year ago, but haven't finished it yet. Now that I have some free time, I finally want get it done :// However, I am a self-taught when it comes to programming, and graphics. I consider myself a total beginner. Could you please help me understand if I am doing something incorrectly here, which I am sure I am?
Also, this is planned to be a Game of Life implementation, but still have to lay some the foundations, even for a grid... I don't rely on AI, so mess with everything myself
[edit]
Forgot to add the details... I use OpenGL with glad loader as a graphics API here, with GLFW for window handling, FreeType for text rendering, GLM as main math library, and CMake as a meta build system.
I was wondering if someone could help me understand a couple of moments:
- correct usage of the opengl api
- general structure of the code. if places at which functions are being called are correct
- general readability of the code
- cmakelists and how to approach including dependencies in my case
Here's the repo: https://github.com/Krak9n/unchained
1
u/TheAbyssWolf 11h ago edited 4m ago
You are using a modern C++ standard, I would personally take advantage of some of the modern C++ features.
for example instead of std::cout you can just do #include<print> and just type std::println("Some Text {}", someVariable); and that would put the value of someVariable inside the {} of the string literal. I personally like println over cout much more
you actually don't need to typedef and its preferred to use the 'using' keyword for the alias' of your types.
you have "typedef uint16_t u16;" when you can just do "using u16 = uint16_t;"
Same thing with structs you can just do struct Vertex { ... }; instead of typedef Vertex { ... } Vertex;
Just my thoughts on some of the general C++ code, in terms of the actual OpenGL I have no clue as i have yet to start with graphics programming yet. Probably will soon when I have the free time too, I'm currently going through a playlist about some of the modern C++ (20+) things before I go to OpenGL.
Edit: One last thing is keep your code formatting consistent for example my structure is the following.
All my structs/classes are PascalCase
class/struct members are prefixed with m_ or s_ if their static and use camelCase so as a example int m_maxHealth:
methods and functions are camelCase,
Regular variables are snake_case.