Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I want to make a simple 3D game using openGL, where should I start?

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.

like image 778
obsoleteModel81 Avatar asked Sep 28 '09 09:09

obsoleteModel81


2 Answers

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;
   }
}
like image 106
Ivan Vučica Avatar answered Oct 21 '22 11:10

Ivan Vučica


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...

like image 21
Jawa Avatar answered Oct 21 '22 09:10

Jawa