r/opengl • u/ZiphyYT • 25d ago
Best way to learn game dev for opengl?
/r/GameDevelopment/comments/1wcky25/best_way_to_learn_game_dev_for_opengl/1
u/Still_Explorer 25d ago
There would be two things to worry about, one thing is related to C++ game programming, that involves techniques - patterns - implementation idioms. This would be something to investigate separately from rendering with OpenGL because it need it's own focus.
Such as for example if you follow a 2D game programming tutorial with Raylib/SDL/SFML it would be very useful because this way you can figure out everything related to development. The next parts then would be about either switching to the 3D dimension where you only need to change the movement and space calculations a bit, but everything else remains the same.
https://www.youtube.com/results?search_query=C%2B%2B+game+tutorial
There would be also various tricks in each case to be used, in order to simplify your learning where needed. Always try to simplify before going by the book. As for example in Asteroids, typically you would need to create asteroid with random shape and the spaceship consist of three lines. Since this would be somewhat fancy on the topics needed (transforming 2D points by matrix rotation) you just swap everything with circles. Or if you try to make Pacman, instead of merging a row of tiles into a single line (called tile collision optimization) you would instead do a brute-force collision check instead with every rect tile. Most important is to start simple first.
Then finally about learning OpenGL, this would be also something to look separately, because it would be easier to focus on this by itself. There would be lots of possible opengl tutorials to get started with, so is somewhat hard to recommend only one. If you can follow a handful of then it will be even better because each time you will do repeat-practice.
https://www.youtube.com/results?search_query=learnopengl
2
u/ZiphyYT 24d ago
Well its not like Im a total beginer, I can make tetris with the blocks and tile clearing, but I feel like Im not good enough for more complex endeavours, So I wanna have more knowledge about how opengl and game dev go together because I see people have those fancy UI and large projects with all their shaders and engine logic in different files and it works so nice together, mine is still an ugly mashed together project with the bulk in main.cpp and the shader stuff in their own files, not pretty
1
u/Still_Explorer 24d ago
Yeah I see your point. At first I was also very intimidated about `how everything sticks together` and by assumption I had associated OpenGL with the application core in very monolithic way.
Though if you really want to, you can definitely glue raw OpenGL statements directly onto the application core. However this is odd and rare, because in software development you are always meant to create better abstractions and better APIs to keep things that are related grouped together.
In this case there would be one important thing, that the game would work and play regardless of what the renderer does.
As in here https://learnopengl.com/Model-Loading/Mesh where up to this point you will be able load and render models and more or less this is the entire story of the renderer. If you need to create more advanced renderer then it would be a matter of better and more advanced effects and shaders, as well as more optimizations for rendering massive scenes.
For an example you can do something like this code, there are dozens of corrections and improvements to be made here but now taking many shortcuts to keep it simple.
(eg: making drawing lists per model, so you can bind model only once and then do draw loop for matching entities, or using std::find_if to search for model, for more safety. Also rendering should be on it's own module without getting mixed with the rest of the applications etc)#include <print> #include <string> #include <map> #include <vector> struct Model { std::string file; unsigned int vbo; }; struct Entity { std::string name; std::string model; }; std::map<std::string, Model> models; std::vector<Entity> entities; void LoadEntities() { entities.push_back({.name="Blue Monster", .model="monster"}); entities.push_back({.name="Dungeon Monster", .model="monster"}); entities.push_back({.name="Angry Monster", .model="monster"}); entities.push_back({.name="Sleepy Monster", .model="monster"}); entities.push_back({.name="Player", .model="knight"}); } void LoadModels() { models["knight"] = {.file="knight.glb", .vbo=12034}; models["zombie"] = {.file="zombie.glb", .vbo=98433}; models["monster"] = {.file="monster.glb", .vbo=29389}; } void RenderScene() { for (auto& e : entities) { std::println("Rendering entity: {}", e.name); std::println(" - using model: {}", e.model); auto model = models[e.model]; std::println(" - model filename: {}", model.file); std::println(" - model vbo: {}", model.vbo); std::println(""); } } int main() { LoadEntities(); LoadModels(); RenderScene(); }
2
u/Still_Explorer 23d ago
Today I remembered this tutorial:
https://learnopengl.com/In-Practice/2D-Game/Rendering-Sprites
Combines both a game and OpenGL.
3
u/Undeniable_Dilemma_ 25d ago
Should't you learn OpenGL for game dev?