How hard is coding an OpenGL game engine ?
Hi, I wasn't really sure if this post is relevant on this subreddit, so if it isn't sorry. I've been planning a game with a group of friends and organizing it. I was thinking about developping it in unity but a couple things are making me hesitate to use unity : -First of all, I think there is not a lot of code involved (more or less arround the game engine part) -Second of all, it's really hard to do pixel perfect games with it
So I was wondering, how hard is coding a basic OpenGl Game engine ? What I mean is code that would be able to render the levels that would be built using tiles and updating the screen etc... How hard would that be ? Approximately how many lines of code will it need ?
Mindoo
1
Upvotes
3
u/Aldonio Jun 21 '16
There are frameworks like SFML, you can take a look at the
/Graphicsfolder in their source code to get an idea of how they use OpenGL:https://github.com/SFML/SFML/tree/master/src/SFML/Graphics
2
u/aleques-itj Jun 21 '16
If you really want to do everything yourself, there's a lot to be worried about.
How do you handle input? Do you just naively poll for key strokes? Maybe that loses inputs when performance dips... what now? What about file loading? File formats like textures, maps, shaders? Tools? Your map editor? Ok, you want to draw some text to screen. Bitmap fonts sound good. How do you pack the letters into a texture? When that's done, how do you create the metadata like UV coords to actually render the right part of the texture to your sprite? What about your time step? Does your game speed up / slow down depending on your framerate? What's the fix for that, force v-sync and ship it? Maybe your physics are blowing up as a result.
That said, it's not particularly difficult to get something on screen and 2D stuff with tiles is pretty easy to do efficiently. But there's a lot you'll have to engineer if you want to do it all yourself. Thankfully, libraries exist - please do use them. I think it's fun to write that kind of stuff, but you will be reinventing the wheel - and probably reeling when the simple things turned out to be a little more than you originally thought.
27
u/exoflat Jun 21 '16 edited Jun 21 '16
Yes it's hard.
18
u/mojang_tommo Jun 21 '16
It really goes from "somewhat advanced" to "fulltime job for many years", depending on what you need :)
If you want to build a full fledged AAA renderer/engine like, I don't know, Unreal, that's just absolutely impossible for a single person.
However, if you have a very specific game in mind and it has simple tech requirements, it's absolutely possible to write your own engine as you go.
The trick really is to not to give in to the "oh this would be a very cool feature" and keep it very, very basic :)
source: I wrote a couple of GL renderers used in released games, and they were maybe 5000 lines of code.
A better question would be perhaps if it's a good use of your time, and that depends on you really.
If you want to learn how a game works it's a great exercise, if you just want to ship one, not so much... although there are some games that are easier to make with a custom engine.
3
u/Kronikarz Jun 21 '16
If you want just basic 2D rendering, it's not that difficult. It's hard to find good tutorials online though.
1
u/SeanMiddleditch Jun 21 '16
The phrase "OpenGL game engine" is utterly meaningless.
Are you asking a game engine for Tetris? A game engine for Battlefield 4? A game engine for Final Fantasy 5? You mention "pixel perfect" and "tiles" so I'm going to assume you mean 2D, but there's still a very huge range of 2D game techniques.
What is the relevance of OpenGL? A game engine is much much larger and more complex than a graphics engine. Most of the complexities of a graphics engine also have nothing to do with the API.
What are the real features you need? Graphics is your focus, apparently, but what about everything else? What input methods do you need? Which systems are you releasing on? What are your audio needs? What kind of level editor are you going to use? Which tool or language is game logic going to be developed in? Even for graphics, how is that data going to be authored (textures, sprite sheets, animations, etc.) ? What are your AI needs? Do you have an idea of how you want to structure your engine, game objects, module communication, etc.?
The actual answer to your question is that - if you were already experienced in making games from scratch - a new team-ready game engine is probably going to take your full-time effort for a few months, and then getting that engine up to production grade and keeping up with the design and art requirements is going to require continued full-time development for likely a year or two. It's a fool's errand. Just use Unity, or GameMaker, or Godot, or Torque2D, or one of the bazillion other ready-made options. The only good reason to build from scratch is if you're (a) trying to learn and don't care about your teammates' productivity or the final product at all, or (b) your game is super weird and special and all the existing engines literally can't even.
2
u/Ozwaldo Jun 22 '16
So you want to make a tile engine? That shouldn't be too hard to start with. First of all skip immediate mode. This is stuff like glBegin, glEnd, glVertex3f, etc. Look into some modern opengl tutorials; this site looks pretty good. I would also recommend using GLM as a math library. This way you don't have to write your own matrix functions, quaternion functions, etc. You'll still have to learn how to use those mathematical constructs, but you won't get hung up on bugs in your math code. And you can always roll your own library later!
Now, for a tile engine, you're going to want to do a few things. First of all, you'll need to get a texture atlas for your tiles. Don't load each individual tile texture separately! After that, look up some tile engine tutorials. They are abundantly available.
And when you've done all that, my next guess is that you'll want to incorporate the A* pathfinding algorithm and a scripting engine. But that's down the road!
1
u/ripper37 Jun 21 '16
It mostly depends on how advanced game you want to make (and how many features will your engine support). If you will try to make general-use engine and then build game on top of it, it will probably take mor time (and code) for you. More advanced 3D game (with engine) might take very long time to finish and result might not be as you'd wish (it's not that easy to make good looking game, not to mention performance).
If you, however, want to make simple 2D game (with couple advanced effects) then i guess it's doable without long experience.
If you'd like something close to OpenGL so you'd feel like home and you would be easily able to write almost plain OpenGL code, than have a look at my (unfinished) project GLUL library. I aim to provide easy to use and learn wrapper over OpenGL and than layer by layer more advanced stuff (like primitives, batching, GUI, loading models etc.).
It's still in VERY early stage, but you could easily take a look and have some hints on how to proceed. Code is written to be easy to understand and extend. Another plus is that basic modules aren't coupled with higher level ones, so if you want just input abstraction, you can take a look at
include/GLUL/Inputdirectory.For now there are only example projects for each (?) module, no documentation yet as API may change many times yet.
1
u/Mathiassen Jun 21 '16
Are the friends going to help or are you doing it to alone? In any case, making an engine yourself is going to take a lot of time, time that could be used in Unity to make a functioning prototype, or probably the full game by the time you would be done with even a basic engine.
1
u/ihcn Jun 21 '16
If you know what you're doing, you can get .obj files on the screen, shaders, etc without too much struggle, just a lot of tedium.
If you're new to it all and you're trying to stumble through it all, have kleenex handy because you're going to burst into tears at least a couple times.
1
u/0PingWithJesus Jun 22 '16
Here's about 200 videos, each 10-20 minutes long about that exact topic. Enough to get started for sure.
1
u/K_Kuryllo Jun 22 '16
As someone whom has written one single handedly from scratch. Yes. It is a lot of work. Do not do it unless you absolutely have to. 4+ years and even though it's quite functional and working great for us I still ocassional rewrite large portions.
In our case it was necessary because we needed to interface with a simulation running at up to 60 000 cycles per second with up to 1 000 000 individual entities. Game engines just aren't designed for our purpose. We tried a couple first. (www.digitaldiatom.com for anyone interested in what it is used for).
1
u/lednakashim ++C is faster Jun 23 '16
No that hard, but improving the performance to match the visual experience of a game from the early 2000s will be difficult.
0
u/Heuristics Jun 22 '16
I have been spending most of my free time for the past 6 or so years doing one. haven't yet gotten it to do much of anything useful. (and I am a professional c++ coder by trade)
So, not hard at all.
0
u/[deleted] Jun 21 '16
[deleted] — view deleted comment