10 | 03 | 2010
Main Menu
Affiliates
Login Form



Alexa
JoomlaWatch Stats 1.2.6 by Matej Koval
Making a Powerful 2D Game Engine Using OpenGL®
Written by rialeru   
Sunday, 27 July 2008 14:36
Article Index
Making a Powerful 2D Game Engine Using OpenGL®
Part 2
Part3
All Pages

Rating 2.9/5 (16 votes)

 


An introduction to a set of series of game programming tutorials

Note: I’m going to provide a step-by-step explanation and full source in C++ with the tutorials.

 

 

Part 1

 

Introduction

I’m really not good at introducing something new. I will try to do my best to give you the basics and details of a two dimensional game engine. First of all, I would like to say that I haven’t done anything about this game engine. I have a 3D game engine that I have made with OpenGL. But we are going to create a 2D game engine. So, for now, 3D is out of interest. I also have a 2D game engine that I made with the GDI library. But GDI is too slow and obsolete. So we are going to utilize the power of OpenGL. This means that I know how a 2D game engine works, and how to make one but only in GDI. This is going to be my first attempt to create a 2D game engine via OpenGL. We’re going to make the engine together; real-time, so if any error occurs we’re going to challenge together. I have chosen to make the series real-time because if I had created the engine beforehand you would probably get bored while reading the tutorials. And if you happen to see any error, it will be hard for me to go back and help you. Here we go.

 

I have a dream...

At the beginning you must choose what there will be in your engine. E.g. - is your engine going to be an isometric or tile-based engine? Here is the first thing to determine; the type of the engine. In my plans it is going to include the two types of a 2D game engine. As I mentioned before the first type is ‘isometric view’ (like Diablo) and the second one is ‘tile-based view’ (like all 2D platform games or any 2D top-down game). Now, let’s take a look at my plan (note that my plan is changeable at any time):

-          Type of Engine: Isometric and Tile-based

-          Engine’s common abilities (Will same in the isometric and tile-based part):

o    Loading of following formats as texture: .dds, .bmp, .png(maybe), .tga, .avi

o    Ability to position and play sounds in a 2D/3D environment

o    Applying effects using 2D/3D particles

o    Real world based physics

o    Ability to produce animation frames out of single pictures

o    Mouse and keyboard support for user interaction

o    2D skinnable GUI

o    Ability to produce a 2D game on a 3D world (not for this series!)

o    Detailed character creation for any kind of game

o    Smart AI

o    Ability to play cut-scenes

-          Isometric part will (Special things for isometric part):

o    have ability to move an object to eight different directions

o    convert normal-view squares to isometric ones

-          Tile-based part will:

o    N\A  (nothing special for tile-based part for now)

 

You see it? Isn’t it nice? Now grab a paper and a pencil and make your own plan! Cause you’re going to follow it! Ok let’s write the first code of our engine! And one thing I forgot to say is this engine is going to be multi-platform and framework-based (this means our engine will run any frameworks for any operating system. If you will find an OpenGL framework for Linux the engine will run on Linux. If you will find an OpenGL framework for windows it will run on Windows! Very smooth and flexible)

 

Curtains up!

Ok if you are ready, fire up your best C/C++ IDE or Notepad. But note that you must have a compiler to get the engine working. Before, let’s choose a name for my engine it might be clown… No, no it is too funny. Well, well it might be OldSkool! Yeah this is more suitable. The first thing to do is to create a basic include file (I call it Basics.h) and put in some basic stuff like includes, defines and type definitions. The most important thing to do is defining the ‘declspec’s for easy usage. I made this as follows:

 

#define OSImport __declspec(dllimport)
#define OSExport __declspec(dllexport)

 

Next comes include section. What they are used for is specified next to them:

 

#ifdef _WIN32
#include <windows.h>     // For Windows
#else 
#include <gltk.h>        // For Linux
#endif
#define GL_CLAMP_TO_EDGE    0x812F
#define NUM_SOUND 10    // 10 sounds supported edit if you want
#include <ddraw.h>        // Direct Draw Header File (FOR .DDS)
#include <vfw.h>        // Video For Windows Header File (FOR .AVI)
#include <math.h>        // Windows Math Library Header File
#include <GL/gl.h>        // OpenGL Library Header File
#include <GL/glu.h>        // GLU Library Header File
#include <GL/glext.h>
#include <AL/al.h>        // OpenAL Library Header file
#include <AL/alc.h>        // OpenAL Codecs
#include <AL/alut.h>        // OpenAL User Toolkit Header file;

 

Well a little long but we are going to use each of these. Let’s personalize the types. I have made a list of my own. It is easy to understand. You can easily change the type names by using the powerful typedef function!

 

 

//----- Type Definitions -----//
// Mostly taken from GL/GL.h
//----- Number Based Types -----//
typedef short            OSshort;        /* 2 byte signed */
typedef unsigned short    OSushort;        /* 2 byte unsigned */
typedef int            OSint;            /* 4 byte signed */
typedef int            OSsizei;            /* 4 byte signed */
typedef unsigned int        OSenum;
typedef unsigned int        OSbitfield;
typedef unsigned int        OSuint;            /* 4 byte unsigned */
typedef float            OSfloat;
typedef float            OSclampf;
typedef double        OSdouble;
typedef double        OSclampd;
typedef long            OSlong;
typedef unsigned long    OSulong;
//----- String Based Types -----//
typedef char            OSchar;
typedef signed char        OSbyte;        /* 1 byte signed*/
typedef unsigned char    OSboolean;
typedef unsigned char    OSubyte;        /* 1 byte unsigned */
//----- Null Based Types -----//
typedef void        OSvoid;

 

Wow great! We have loads of special type-names. Don’t forget we are going to use our own types.

The Big Portrait
That is all for today. We have created our first file of our 2D engine. Here is the whole source:

 

#ifndef __Basics_h__
#define __Basics_h__
/* This is the basics.h every file of our engine is going to include this file because it */
/* includes every file that our wngine will need.                                          */
//----- Macros -----//
#define OSImport __declspec(dllimport)
#define OSExport __declspec(dllexport)
//----- Includes -----//
#ifdef _WIN32
#include     // For Windows
#else
#include         // For Linux
#endif
#define GL_CLAMP_TO_EDGE    0x812F
#define NUM_SOUND 10    // 10 sounds supported edit if you want
#include         // Direct Draw Header File (FOR .DDS)
#include         // Video For Windows Header File (FOR .AVI)
#include         // Windows Math Library Header File
#include         // OpenGL Library Header File
#include         // GLU Library Header File
#include 
#include         // OpenAL Library Header file
#include         // OpenAL Codecs
#include         // OpenAL User Toolkit Header file
//----- Type Definitions -----//
// Mostly taken from GL/GL.h
//----- Number Based Types -----//
typedef short            OSshort;        /* 2 byte signed */
typedef unsigned short    OSushort;        /* 2 byte unsigned */
typedef int            OSint;            /* 4 byte signed */
typedef int            OSsizei;            /* 4 byte signed */
typedef unsigned int        OSenum;
typedef unsigned int        OSbitfield;
typedef unsigned int        OSuint;            /* 4 byte unsigned */
typedef float            OSfloat;
typedef float            OSclampf;
typedef double        OSdouble;
typedef double        OSclampd;
typedef long            OSlong;
typedef unsigned long    OSulong;
//----- String Based Types -----//
typedef char            OSchar;
typedef signed char        OSbyte;        /* 1 byte signed*/
typedef unsigned char    OSboolean;
typedef unsigned char    OSubyte;        /* 1 byte unsigned */
//----- Null Based Types -----//
typedef void            OSvoid;
#endif

 

 

 



Comments
Search
Only registered users can write comments!

3.22 Copyright (C) 2007 Alain Georgette / Copyright (C) 2006 Frantisek Hliva. All rights reserved."

Last Updated ( Sunday, 27 July 2008 15:26 )