Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Geek Culture / OpenGL game engine structure?

Author
Message
Neuro Fuzzy
17
Years of Service
User Offline
Joined: 11th Jun 2007
Location:
Posted: 13th Mar 2011 00:44
So... I've been programming in c++ a lot more, with OpenGL and SDL. SDL provides an interface with mouse/keyboard input, screen handling, sound output, etc.
The thing I'm having trouble with is HOW do I structure an engine that will be easy to use, and provide a good abstraction? A lot of the time, I realize I need to change a lot of the structure if I want to do one specific thing properly, so I just end up making a variable public or some other not-so-good thing.

I guess... since this is a pretty big general topic, are there any books on program structure? I could also use some tips for web development (PHP/SQL websites). I think for now I'll just be modeling my engine after DBPro syntax (make object 1, load mesh, etc.)

ionstream
20
Years of Service
User Offline
Joined: 4th Jul 2004
Location: Overweb
Posted: 13th Mar 2011 11:20
Boy this is something I spent a lot of time with. There are a lot of books for stuff like this, but I've never found an optimal solution. I think that it's because there is no optimal solution. There will always be something you didn't think of later on in the coding phase, and you have to refactor your code because of it. The best way to go about your code is to design as many independent segments as possible: you should be able to change one part of the code without having to change too much, if any, of the other parts of the code.

But that's general advice for programming. The way I have my engine set up is that there is one application manager that handles various subsystems, like sound, input, video, and then calls an event functions on a scene class. Something like this:



That's the jist of what my engine is doing, minus the exception handlers. It's pretty clean, but I'm always adding new things to it, and sometimes I have to refactor more code than I like. There's only so much abstraction you can do, and although you should make things (classes) as independent as possible, don't go crazy with that otherwise you'll end up with some crazy message-passing scheme and custom scripting language. Code readability is key.

This site was helpful: http://gpwiki.org/index.php/Main_Page. Lots of design suggestions. As helpful as that site was, I found that the only way to really know if a design is good or not was to try it out.

Airslide
20
Years of Service
User Offline
Joined: 18th Oct 2004
Location: California
Posted: 13th Mar 2011 19:21
I have this same problem with XNA and C#. I think I've finally been settling into a good design but I think what ionstream said about trying and refactoring is largely true.

The best thing I can say is that whenever possible try to salvage what you have and refactor instead of restart. I've simply restarted things far too many times and it usually ends up with an abandonded project.
bergice
17
Years of Service
User Offline
Joined: 5th Jun 2007
Location: Oslo,Norway
Posted: 13th Mar 2011 20:54
You probably wanta go with what ionstream said. Object oriented programming is the way to go!

Lucy in the

Sky with

Diamonds
PrimalBeans
14
Years of Service
User Offline
Joined: 14th Oct 2010
Location: The sewer.... hunting alligatiors.
Posted: 17th Mar 2011 08:25
Im not sure if this is the solution your working for but it seems but im reading OpenGL Library Red and Orange set 5th edition... seem to be great books. I think i spent 40-60 something on them but they are worth it for an opengl resource. Im not 100% sure but i dont know why you couldnt use any sdk or library you wanted for input. Usually graphics and input arnt reliant on eachother. Shoot you could use opengl and xinput or direct input if you wanted... someone please correct me if im wrong.. which isnt uncommon....

Login to post a reply

Server time is: 2025-05-23 07:20:35
Your offset time is: 2025-05-23 07:20:35