-=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- (c) WidthPadding Industries 1987 0|208|0 -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=-
SoCoder -> Blogs Home -> Blogs


 
Dabz
Created : 29 November 2007
Edited : 30 November 2007

DX9Engine

A DirectX 9 Engine for C++

As soon as BRL stated that they have spent most of the recent development of BlitzMax to reflective programming, which to me, draws the emphasis from game development in a BASIC language, especially since other languages do all that fancy programming ideologys more effectively, as well as fully implemented (OOP being one of them too), so I decided it was about time to quit middleware and try and have a pop at 2D DirectX engine creation myself.

I've already built an engine using GDI+ once before, so I had a rough head start on how to put it together, the only problem was that I didnt have too much experience using DirectX... So I set about delving into it, though, using the skills that I've aquired over the years... More notably; C++/C#

I wasnt too sure where to start, luckily, I picked up a little DirectX over the years, not much, just general reading of the odd article and dabbling in it in Blitz+ via userlibs... So, I decided to have a poke around DirectX10 (Of all things)

This is a beast of an api and I soon discovered there wasnt much information on the internet surrounding the subject... I couldnt rely on DX9 info as the two api's are'nt the same, and the pipeline works a lot differently, so, after playing around, I managed to muster a sprite on the screen, and after hunting all over the place for color-masking and coming up with nothing, I decided to move on...

Next port of call was Managed DirectX 9 with C#, this started well, and I had a bare bones engine up and running in no time... The only problem was, Microsoft were'nt updating Managed DirectX which offically made it obselete and they were gearing towards XNA in this department...

So, DirectX9 and C++ was the next option, it didnt take five minutes to get the engine up to speed as the Managed one, and from there it effectively grew to what I have today... A DirectX9 engine (Split into classes) that matches BlitzMax's graphical capability and more!

The whole 2D thing is built in 3D, I have poly-poly collisions (No pulling pixel data), image buffers and quads flying around, though currently, the quads are still getting implemented, which has materials and is effected by light.

Here is a current list of finished features in the engine:-


LPTSTR DX9GetCurrentDir()
bool DX9CheckGraphicsMode(DX9Mode *mode)
DX9Engine(HINSTANCE hInstance, LPTSTR sWindowClass, LPTSTR sTitle, DX9Mode *mode)
void DX9ShowPointer()
void DX9HidePointer()
void DX9SetClsColor(int r,int g, int b)
void DX9Cls(HEXCOLOR clearColor)
void DX9Cls()
void DX9Flip()
void DX9SetBuffer(BUFFER buffer)
BUFFER DX9GetBackBuffer()
int DX9GetGraphicsWidth()
int DX9GetGraphicsHeight()
void DX9StartImageDrawing()
void DX9EndImageDrawing()
void DX9DrawImage(DX9Image *image, float x, float y)
void DX9DrawImage(DX9Image *image,float x, float y,int frame)
FILE* DX9WriteFile(LPCTSTR filePath)
void DX9CloseFile(FILE* tempFile)
FILE* DX9ReadFile(LPCTSTR filePath)
void DX9WriteInt(FILE* fileHandle, int integer)
void DX9WriteFloat(FILE* fileHandle, float float_)
void DX9WriteString(FILE* fileHandle, LPCTSTR string)
int DX9ReadInt(FILE* fileHandle)
float DX9ReadFloat(FILE* fileHandle)
LPCTSTR DX9ReadString(FILE* fileHandle)
LPCTSTR DX9AppendStrings(LPCTSTR stringOne, LPCTSTR stringTwo)
UINT DX9GetEventMessage()
WPARAM DX9GetWParam()
LPARAM DX9GetLParam()
bool DX9ImagesCollide(DX9Image *imageOne, DX9Image *imageTwo)
DX9Image(UINT width, UINT height, DX9Engine* engine);
DX9Image(LPCTSTR filePath,DX9Engine* engine);
DX9Image(LPCTSTR filePath,DX9Engine* engine, int r, int g, int b);
DX9Image(LPCTSTR filePath, short cellWidth, short cellHeight, short cellAmount,DX9Engine* engine);
DX9Image(LPCTSTR filePath, short cellWidth, short cellHeight, short cellAmount, int r, int g, int b,DX9Engine* engine);
float DX9GetImageWidth()
float DX9GetImageHeight()
float DX9GetImageScaleX()
float DX9GetImageScaleY()
float DX9GetImageAngleR()
float DX9GetImageAngleD()
int DX9GetImageCellAmount()
void DX9SetImageHandle(float x, float y)
void DX9SetImageMidHandle()
void DX9RotateImageR(float radians,float incrementValue)
void DX9RotateImageD(float degrees,float incrementValue)
void DX9SetScale(float newScaleX, float newScaleY)
void DX9RenderCollisionPoly()
void DX9SetAlpha(float Alpha)
BUFFER DX9GetImageBuffer()
DX9Quad(LPCTSTR filePath,DX9Engine* engine)
void DX9DrawQuad(DX9Quad* quadHandle,float x,float y, float z)
void DX9RotateQuad(float x, float y, float z)
void DX9ScaleQuad(float scaleX, float scaleY)


There are tons of member variables to much around with, and the engine exposes loads of directx features to muck around with, such as light settings etc

All in all, its coming along great and as soon as I have the Quad class finished up, I'll be moving onto adding more to the engine mundane functions, as well as fonts, sound and DXinput!

Dabz

 

Comments


Thursday, 29 November 2007, 18:55
Jayenkai
Sounds like it could be a nice thing to have access to!
Keep up the good work
Friday, 30 November 2007, 10:14
mole
Forgive my ignorance, but what actually does this do?

I currently presume that your engine is like a giant UserLIb that you can add into Blitz and then have access to all those functions you listed?

If so, this seems very interesting indeed, if not, well, explain to me, people!
Friday, 30 November 2007, 11:33
Dabz
Your half right mole!

Its a collection of classes in C++ that help create a DirectX9 application without the hassle of going under the hood of DirectX itself (Which is huge)...

This could be wrapped into a DLL that is compatible with Blitz via userlibs.

Here's a little movie that shows a quad in action:-

www.syntaxbomb.com/forum/index.php?action=dlattach;topic=904.0;attach=457

And this is the entire program that does it (well, it is a little different, but you should get the jist):-





Dabz

|edit| Phoenix here; I took the liberty to change the code formatting, so it doesn't clutter up the page. |edit|
|edit| Thanks Phoenix, I didnt realise I did {quote} instead of {code}... silly me! |edit|
Friday, 30 November 2007, 13:12
mole
Ahh I get it.

That's actually pretty cool!
Saturday, 01 December 2007, 10:41
Phoenix
This looks interesting. When it matures, perhaps a version with support for .NET languages could be made? When do we see a release?
Sunday, 02 December 2007, 05:21
Dabz
Hiya Phoenix!

I have no real release date for it if I'm honest, The schedule I do have is building a port of a game I made from BlitzMax to C++... Programming with DirectX directly will let me have some swanky features not available in BlitzMax and will add that extra bit of 'shine' to the game...

The engine will be available in a C++ SDK format (headers, libs etc etc) and as such, will be wrapable... I have had interest in a wrapped BlitzMax version, and my own personal wrap would be as you mentioned, for C# (Its a good job C# allows the use for unmanaged DLL's)

I already have built a poly editor for poly-poly collisions, you load an image into the editor and map a polygon around it, when saved, its picked up by the engine and you can check collisions using that. That area is actually finished and works a charm!

The quad class offially creates textured rectangle quads, but as like images, having just rectangles is a bit useless for odd shaped images... There is a choice to put a color mask on the quad, but again, even if a colour mask stops a certain color showing, you still cannot see behind the quad.

So, to beat this little quirk of quad nature, I've implemented a 2D mesh editor in the poly editor to help map out a shape of an image to a 2D mesh that will be loaded and created in the engine via an index buffer then manipulated with the same commands as the quad!

Dabz
Monday, 03 December 2007, 00:56
Dabz
Here's a little feature of my engine that shows render-to-quad (The quad in question is the same size as the display)

dabz.syntaxbomb.com/Movie2.wmv

Looks pretty cool doesnt it!

The front image is just there to see if it maps on the quad correct, in aspest to the screen...

And it works a charm!

Dabz
Monday, 03 December 2007, 03:16
Jayenkai
Coool
Thursday, 27 December 2007, 15:25
Dabz
DX9Engine is now under GNU, so source can be found here:-

tinyurl.com/2kywv7

Dabz
Thursday, 17 April 2014, 19:27
Dabz
Just rereading this... Wish I had the time to work on low level code again from the ground up... Some of my biggest programming achievements spawned from heaps of research to knit things together!

I can make a game tomorrow if I was inclined too, but, I had a passion for long drawn out stuff, stuff that would make me sit stuck for days, endless google trawls with the output of a console window for company!

How did I find the time?

Dabz
Friday, 18 April 2014, 03:12
Jayenkai
Same here. Years of Wednesday Workshops and AGameAWeek's has completely destroyed my ability to focus on a lengthy task, although it has inadvertently given me the uncanny ability to churn out exceptionally complicated projects within alarmingly short amount of times.

... Still.. Would be nice to dig deep, and build a nice big proper game, some time.
.. But I'm far too busy with AGameAWeek, to have time for that!
Friday, 18 April 2014, 07:39
caligula
The research bit is fun! Gives you a kick when you figure something out after lots of trial, error and reading. Things like low-level game engines take a lot of time though. It's a larger commitment than one thinks at first.
Tuesday, 22 April 2014, 06:22
Kuron
Looks like a very capable little engine.