• Advertisement
Sign in to follow this  
  • entries
  • comments
  • views

About this blog

Curious about how to build a 2D engine?? Me too, let's resolve this together making one.

Entries in this blog


Just to keep you informed...

I'm rewriting all the Predator Engine... =D

There was very bugs and the code organization was going to the hell..

I'm writing carefully all components and after the primary controls be ready...I'll post the demo here...

Firstly I would like to left done:

PButton (done)
PLabel (done)

with good features to have few work in get amazing effects...


Let's play... = )

Ladies and gentlemans..

I present you..

the Predator Engine =P

(clap clap clap clap)

thanx...thanx =D


Download it from this address

and test what we got until now..

I made the follow components..


no laughs please...I haven't much time = (

test and send me the bugs and new ideas for I implement it...

Thanx a lot...

to everyone
Hi my friends...

After this late in post here...

I bring some news...

The PLabel class supports the Outline Fonts, Bitmap Fonts and Texture mapped fonts..

the PPanel class is almost done, it's working now, except by some details that I'll implement tomorrow, like caption align, borders visible, etc...

the PGraphicObjectCollection is dead...it just brought me problems...

PPanel : PInputEventReceiver

PLabel* FCaption;
SColor* FBackgroundColor;
SColor* FBorderColor;

std::string FTextureFileName;

unsigned int FTexture;
unsigned int FDisplayListRectWireFrame;
unsigned int FDisplayListRect;
unsigned int FDisplayListRectTexture;

int FBorderWidth;
int FRectType;
bool FFilled;
PPanel(SRect* ABounds, int ARectType, IVideoDriver* AVideoDriver);

PLabel* GetCaption(void);
void SetCaption(PLabel* AValue);

SColor* GetBackgroundColor(void);
void SetBackgroundColor(SColor* AValue);

SColor* GetBorderColor(void);
void SetBorderColor(SColor* AValue);

std::string GetTextureFileName(void);
void SetTextureFileName(std::string AValue);

int GetBorderWidth(void);
void SetBorderWidth(int AValue);

bool GetFilled(void);
void SetFilled(bool AValue);

void PrepareToDraw(void);

void Draw(void);

The IVideoDriver have some new methods too

virtual AUX_RGBImageRec* LoadBMPRec(std::string AFileName) = 0;

virtual void SetBlend(bool AValue) = 0;
virtual void SetTexture(bool AValue) = 0;

virtual unsigned int GenerateDisplayList(int AListSize) = 0;
virtual void CallDisplayList(unsigned int ADisplayList) = 0;
virtual void DestroyDisplayList(unsigned int ADisplayList, int ASize) = 0;

virtual void LoadTexture(std::string AFileName, unsigned int &ATextureBuffer, int ATextureType) = 0;
virtual void BindTexture(unsigned int ATextureBuffer) = 0;

virtual void DrawText(std::string AText, float ASize, SColor* AColor, SCoord* ACoord, unsigned int ADisplayList, int AFontType) = 0;

virtual unsigned int GenerateDisplayListRectWireFrame(SRect* ABounds, SColor* ABorderColor, int ABorderWidth) = 0;
virtual unsigned int GenerateDisplayListRect(SRect* ABounds, SColor* ABackgroundColor) = 0;
virtual unsigned int GenerateDisplayListRectTexture(SRect* ABounds, SColor* AColor) = 0;

I'm using display list for everything, if someone has any suggestion in how I can approach the performance...tell me...

I have made a little demo with two panels and one running label to show the use of layers and what we have until now:

Predator Engine Demo

well...I hope you like the system...

I think that our next step is make some buttons..right?

see ya
after some days without post here, I show you the PLabel class...

PLabel: PGraphicObject

unsigned int FDisplayList;


SColor* FColor;

std::string FCaption;
std::string FFontName;

int FSize;
int FWeight;

bool FWireFrame;
bool FItalic;
bool FUnderline;
bool FStrikeOut;

int GetCaptionWidth(void);
int GetCaptionHeight(void);
PLabel(std::string ACaption, std::string AFontName, int AFontSize, SCoord* ACoord);

std::string GetCaption(void);
void SetCaption(std::string AValue);

SColor* GetColor(void);
void SetColor(SColor* AValue);

std::string GetFontName(void);
void SetFontName(std::string AValue);

bool GetWireFrame(void);
void SetWireFrame(bool AValue);

int GetSize(void);
void SetSize(int AValue);

int GetWeight(void);
void SetWeight(int AValue);

bool GetItalic(void);
void SetItalic(bool AValue);

bool GetUnderline(void);
void SetUnderline(bool AValue);

bool GetStrikeOut(void);
void SetStrikeOut(bool AValue);

void BuildFont(void);
void Draw(void);

This class is quite simple, some properties...

the BuildFont Method, have to be called before the Draw Method

Well, like the title says...I have made some changes in our mechanism...

Now, we have a PGraphicObjectCollection class, that have a list of PGraphicObjects (=P)...

PList* FObjects;

IVideoDriver* FVideoDriver;
PGraphicObjectCollection(IVideoDriver* AVideoDriver);

virtual void Sync(void);

the sync method, just distribute the FVideoDriver component(that is unique) between its FObjects...

The Sync Method, must to be called after all objects are inserted and before call methods that uses the FVideoDriver of them.

Okay, I'll try to be more fast and keep on posting everyday...

See ya...

This is like our 2d engine looks after namespace organization:

namespace Predator
namespace Common
namespace System
namespace Drawing
namespace GUI
(PLabel, PPanel, etc...)

Well..any suggestions =D

After that, I'll start the GUI programming..

See ya...

A little doubt

Hi everyone..

I have spent my time reading about create my own engine and use some of existents...

I think about and get in none result = (

I'm here to ask you, what you think?

my next mission is dismember my engine in namespaces,

tomorrow I'll show the engine's new organization

I hope you like...

PS: please give your suggestion about my doubt <=)


Hi my friends...

this is my first post in 2006 =D

I present you the PLayer class:

PLayer : PInputEventReceiver

PList* FGraphicObjects;

std::string FLayerID;
SColor* FColor;
PLayer(std::string ALayerID, SRect* ABounds, IVideoDriver* AVideoDriver);
std::string GetLayerID(void);
void SetLayerID(std::string AValue);

void Draw(void);

This class will be responsible for Keep all objects in the screen, I prefered use the layers because it has the order benefit...

For while, this class just has this few methods, I have not thought in another funcionallity for it.

The draw method just will draw its graphic objects =D

Tomorrow I'll show the PPanel class and after that, I'll need your help to know "what path I have to follow" =P


PS: I'm sorry about the late...

Happy new year!!!

Hi everyone...

I'm in home yet...so...I cannot write any code here heheheu

Monday I'll continue our engine and write new content =D

I would like wish you a happy new year =D

Hi everyone..

I'm home and without my computer with the codes, so...I decided improvise some visual look of our engine...

Above, the images with what we have until now...


SCoord, SRect and SColor.

PList and PStack.


PDevice, IVideoDriver and input drivers.


PWindow, PGraphicObject and PInputEventReciever

Well my friends...I don't know what I'll write until monday, I'm without the computer with the codes...so...be patient =D


Our first Main.cpp

Hi everyone, I'm a little hurried, so I will just write here our first main.cpp =D

We can already create some windows and show...

If you are following the previous days, check how simple is the code:

#include "PStructs.h"
#include "PDevice.h"

int main()
PDevice* MainApplication= new PDevice(vdOpenGL);

MainApplication->CreateNewWindow("MyWindow", new SRect(0, 100, 500, 500));

while (MainApplication->Running())


return 0;

When we create a PDevice instance, we pass by parameter, the type of API we want to use. In this case, is OpenGL..

Well...tomorrow I'll show the first "visual" version of our engine, with what we have until now..

See ya..
Hi, how are you??

well, proceeding, let me explain the IVideoDriver class...

Check out the code:


virtual void RestoreDefaultSettings(void) = 0;
virtual void PrepareScene(void) = 0;
virtual void DrawScene(HDC AHDC) = 0;
virtual void ResizeDriver(SRect* ADimension) = 0;

virtual void SetClearColor(SColor* AColor)= 0;

The IVideoDriver is just an interface that contains all the drawing functions (until now just the "prepare" functions, none of REAL drawing is done) of the engine... the POpenGLDriver only implement this interface with OpenGL methods.

All the graphicobjects have a pointer to IVideoDriver to perform its drawing.

Now..the PWindow class..one of most important classes:

PWindow: PInputEventReceiver

bool FFullScreen;
bool FNeedResize;

std::string FName;
std::string FCaption;
SColor* FBackgroundColor;

HWND FHandle;
PWindow(std::string AWindowName, SRect* ABounds, IVideoDriver* AVideoDriver);

bool GetFullScreen(void);
void SetFullScree(bool AValue);

bool GetNeedResize(void);
void SetNeedResize(bool AValue);

void Show();
void Hide();

std::string GetName(void);

std::string GetCaption(void);
void SetCaption(std::string AValue);

SColor* GetBackgroundColor(void);
void SetBackgroundColor(SColor* AValue);

HWND GetHandle(void);
void SetHandle(HWND AValue);

HDC GetHDC(void);
void SetHDC(HDC AValue);

void SetHGLRC(HGLRC AValue);

void Draw();

This class control the windows of the application. Until now there are no complex methods that need explanation..maybe in the future =P

Okay, tomorrow I'll show the example of a simple Main.cpp that create and show a window with a background color.

Any suggestion or question...comment please =D

See you tomorrow..
Today I should explain the PWindow class and IVideoDriver interface..but...looking the project, I decided to show the PGraphicObject (all the graphic objects will derive from it, so...) and the PInputEventReciever first, because the PWindow class derives from PInputEventReciever =D

Check the code:


bool FVisible;

IVideoDriver* FVideoDriver;
SRect* FBounds;
PGraphicObject(SRect* ABounds, IVideoDriver* AVideoDriver);

bool GetVisible(void);
void SetVisible(bool AValue);

SRect* GetBounds(void);
void SetBounds(SRect* AValue);

IVideoDriver* GetVideoDriver(void);
void SetVideoDriver(IVideoDriver* AValue);

virtual void Draw(void) = 0;

This class have not much to explain...any doubt ask me please...


void (*FOnMouseMove)(SCoord* AMousePosition);
void (*FOnMouseDown)(SCoord* AMousePosition, ENMouseButton AMouseButton);
void (*FOnMouseUp)(SCoord* AMousePosition, ENMouseButton AMouseButton);

void (*FOnKeyDown)(int AKey);
void (*FOnKeyUp)(int AKey);
virtual void DoMouseMove(SCoord* AMousePosition);
virtual void DoMouseDown(SCoord* AMousePosition, ENMouseButton AMouseButton);
virtual void DoMouseUp(SCoord* AMousePosition, ENMouseButton AMouseButton);

virtual void DoKeyDown(int AKey);
virtual void DoKeyUp(int AKey);
PInputEventReciever(SRect* ABounds, IVideoDriver* AVideoDriver);

void OnMouseMove(void (*AOnMouseMove)(SCoord* AMousePosition));
void OnMouseDown(void (*AOnMouseDown)(SCoord* AMousePosition, ENMouseButton AMouseButton));
void OnMouseUp(void (*AOnMouseUp)(SCoord* AMousePosition, ENMouseButton AMouseButton));

void OnKeyDown(void (*AOnKeyDown)(int AKey));
void OnKeyUp(void (*AOnKeyDown)(int AKey));

virtual void Draw() = 0;

This class just have the pointers to the methods. All the PInputEventReceivers objects, will be registered in the MouseDriver and KeyboardDriver on PDevice and the events will be fired from these drivers to the recievers.

just like I said, the PWindow class derives from PInputEventReceiver.

Tomorrow I'll show the PWindow class and the IVideoDriver interface..
at this time, I promisse..hehe

leave comments with suggestions, critics or love phrases =P

well..see you tomorrow..

The PDevice Class

Well, yesterday, because my xmas party, I didn't post here =D

But, like I said, here is my first engine description:

The code:

S[name_of_class] = Classes that describe structs;
P[name_of_class] = Standard classes;
I[name_of_class] = Interfaces;

EN[name] = Enumerators;

F[name] = Attributes;
A[Name] = Parameters;

From the beginning:
I have made some classes (I have not used any structs until now and I don't pretend), to describe the structs that I'll need to use.
SRect, SCoord, SColor. This classes are being used in all the standard classes until now.

My main class, is the PDevice:


PList<PWindow>* FWindows;
PStack<PWindow>* FOpenWindows;

MSG FMessage;
int FActiveWindow;
PWindow* FCurrentWindow;

IVideoDriver* FVideoDriver;
PMouseDriver* FMouseDriver;
PKeyboardDriver* FKeyboardDriver;

void RegisterInstance(LPCSTR AWindowName);
void BuildWindow(const LPCTSTR AWindowName, SRect* ADimension, PWindow* ANewWindow);
void PrepareWindowToDraw(PWindow* ANewWindow);

static private LRESULT CALLBACK PDevice::WindowProcedure(HWND AHandle, UINT AMessage, WPARAM AWParam, LPARAM ALParam);

PDevice(ENVideoDriver AVideoDriver);

PWindow* CreateNewWindow(std::string AWindowName, SRect* ABounds);
PWindow* GetCurrentWindow(void);

IVideoDriver* GetVideoDriver(void);

bool Running(void);
int ActiveWindows(void);

void Show(std::string AWindowName);
void Hide(std::string AWindowName);

void Refresh(void);

void InitializeMouse(void);
void InitializeKeyboard(void);

This class, have a list of PWindows, that are the windows of application =P. The stack with OpenWindows serve to set the DeviceContext to the previous window when another window is about to be closed.

The video driver, contains the drawing functions (that aren't implemented yet, except the "prepare" and "refresh" routines).

Mouse and keyboard drivers will handle the respective messages.

Another methods are explained by itselves.

Tomorrow I will talk about the PWindow and PVideoDriver class.

Remember, I'm building this framework yet, neither the windows system are ready. I will appreciate any suggestions in how can I approach my system.

Tell me what you think.


See ya...

My first entry

Hi, my name is Matheus Von Der Kerkhoff, I'm new in game programming.

For this day forward, my journal will show you a little bit about my experience in the game programming world.

My first project is a graphical engine 2D, in C++.

My idea is quite simple. First, I need to make a little engine, and after that, I can begin with some little games (I have already done some games without an engine, but didn't like), like plataform games and something like Counter Strike 2D.

If my engine support the skills of Counter Strike 2D or Soldat(is just some examples), I'll be very happy. =D

A little piece of my engine is already done. Tomorrow I'll explain you how I plan build it and will appreciate all the suggestions.


See ya..
Sign in to follow this  
  • Advertisement