views:

927

answers:

12

I find that I learn best by example. Is there a good website or codebase that shows how event handling, collision detection, modeling, and basic 3D drawing works?

The game I'm trying to begin with is a simple racing game where the user controls a small space ship and navigates through channels, asteroid fields, space colonies, and various other obstacles (I know, real original). Movement is in 3 dimensions. The game should know when the shuttle hit an obstacle. There are defined tracks as there are in most racing games (circuits and linear paths).

Pressing the arrow keys should cause the direction vector to rotate appropriately. Also, the ship should use something like an afterburner when the user presses the space bar, for example. Movement up and down is also an option.

+3  A: 

Not knowing your initial skill level I suggest you taking a look at Ogre3D. It is a complete 3D-rendering engine that has really clean interface to work with, easy to extend and best of all, it's quite multiplatform working on Windows, Linux and Mac OS X. The examples and tutorials provided are pretty self-explaining.

If you want to write your own OpenGL-only engine completely from scratch, Ogre3D may not be the path to follow...

Jawa
It's Ogre, not Orge :-)
Ivan Vučica
Yeah, thanks. Made a systematic typo but at least I got the link correctly...
Jawa
+3  A: 

If you want to learn OpenGL, I recommend starting with "OpenGL Red Book", and then looking at NeHe's samples. Red Book is free at least in online HTML format, there are also downloadable PDFs around.

However, Red Book and NeHe will teach you mostly how to use OpenGL; writing games is art, and there's far too much to explain, far too much to learn, and far too much to read about it. Here's just a tip.

This is basic structure of most games. Hopefully it helps with basics. Of course it's not a full game, won't run, and greatly depends on how you do things, but it should give you a basic idea.

void update(float k)
{
  // k == time in seconds since last update; e.g. 0.02
  ship.y += ship.speed_y*k;
}
int main()
{
   while(1)
   {
      if(hasEvents())
      {
        event_t evt;
        getEvent(&evt);
        if (evt.type == keypress && evt.key==down) 
        {
           ship.speed_y=1;
        }
      }
      paint();
      new_ticks = get_ticks();
      update((new_ticks - old_ticks)/1000.);
      old_ticks = new_ticks;
   }
}
Ivan Vučica
+1  A: 

NeHe

This site helped more then anything when I was learning opengl.

corymathews
A: 

I've no idea how much game programming experience you have, but I'd start with something a bit more limited.

Start with a 2d tile-based game (Sokoban etc) - they're relatively easy to write - something where the objects are always exactly on a tile, that makes things pretty trivial.

Once you've got the principles of that, game loop, timing, processing user input, data model, renderer etc, then you can do something more involved.

Then you can try something like "Asteroids" which is going to need some 2d vector maths, modelling intertia (i.e. integration) possibly a bit of trig. and a non-tile based collision system.

Once you've got that licked, then you can try something 3d - which makes things more complicated again, maths-wise.

MarkR
+1  A: 

I would look around on www.gamedev.net, it contains some excellent tutorials for beginners and in the forums you'll find a great deal of information on any subject related to games programming.

Mez
+1  A: 

A couple of notes, some of which have already been stated:

  • The OpenGL Redbook. An excellent place to start. The book has seen several revisions, so the free online version is a bit dated by comparison.
  • GameDev.net. They are a wonderful resource for developers of all experience, and they have a lot of talented people on the forums. They have answered the question, "I want to make a game, where do I start?" many, many times.
  • I do not recommend NeHe. I find that the tutorials there, more often than not, confuse a neophyte. The tutorials show "how", but do very little to explain the crucial why.

Game development is a huge multifaceted discipline. It's challenging even if you have very solid math and programming skills.

Two pieces of advice:

  • Start small. Start small. Start small. You might think your goal is pretty modest, but it will involve a great deal more than you imagine.
  • Avoid the temptation to cut and paste example code. You will cheat yourself out of crucial understanding.
luke
A: 

Yes, look up tutorials online. Yes, hang out at GameDev.net. Yes, NeHe is confusing and specialized.

For OpenGL, I would combine the OpenGL SuperBible's ability to make one aware of the context and possibilities of OpenGL with a good old-fashioned Google search.

It also helps to know someone who can help you out from time to time. GameDev.net has chatrooms and the people are friendly.

Dwight
A: 

First, you should think about the structure of your code. Every game ever has some variation of the following:

int main()
{
   Screen::Init();
   Game::Init();

   while (Game::isrunning)
   {
      Game::Update();
      Screen::Render();
   }

   Game::Shutdown();

   return 0;
}

The rest just becomes an implementation detail. Try looking at SDL, it handles a lot of the nasty things of Windows programming (initializing a window, loading OpenGL, etc.) so you can focus on writing your game.

knight666
A: 

If you want opengl but with the simplicity of python - which could be nice to understand the principle of the API at first - check out the wrappers : http://pyopengl.sourceforge.net/

They are compatible with the latest version of opengl and their development is quite active.

attwad
A: 

I must give a warning for using nehe because many people have recommended it.(don't have an account to make comments, sorry)

Mainly because it only shows how to do things with the fixed pipeline instead of shaders. The first couple of tutorials might be ok the get a kickstart of how to get something on the screen. But don't waste your time with for example learning how to activate alpha blending and setting up lighting for the fixed pipeline, because if you want to do something that doesn't look like a game from 1999 you will have to relearn how to do all that stuff again but with shaders. Better to learn the new way from the beginning imo.

IR
A: 

Firstly, I don't recommend using OpenGL for your first game, especially if you've never programmed before. You should strongly consider the newer and easier methods like XNA with C#.

Secondly, like OpenGL, XNA also has a large number of tutorials on the Internet, which I believe you will find very helpful.

If you've never done programming before, I recommend as a starting project, you should try creating a very simple game like Pong, or Tic Tac Toe. I think you will get a good feel of game development in general. From there, you can start on your actual project from the experience you've gained by creating Pong.

Lastly, the main piece of advice I can give you as you adventure on your quest is to never give up no matter what obstacles you face in creating your game.

Good Luck! ^^

Roy
A: 

did you find something useful?

if you did then please share.

thanks

umerh