PDA

View Full Version : Writing a game engine from the scratch



chronozphere
25-03-2006, 09:37 AM
Hi all 8)

I 'm new here. Game development has been my hobby for a long time, and i am plannning to write my own game-engine from the scratch. (only with some DirectX headers).

I will first write the graphics part, wich should have hardware accelerated 2d graphics using Direct3d 7
(My pc still only hardware-supports DX7 :( ).
So my engine will use both, directdraw and direct3d (just as delphix does).
but before i start i need to know some things first:

A. Is it meaningfull to use Directdraw in my engine and will it still work under Windows Vista?? Or is it better and faster to use 100% Direct3d7 and draw the whole game using vertex quads??

B. Has any of you guys ever written a Directdraw/Direct3d engine from the scratch??
Is it worthwile, to write it from the scratch and decide wich features must be implented and wich not (for some extra speed, and efficiency)??

C. Are there any good tutorials or open-source games available, wich show how to write DirectDraw/Direct3d from the scratch??

Thanks in advance ;)

Traveler
25-03-2006, 10:18 AM
Hi chronozphere,

First, let me welcome you to PGD. I hope you'll enjoy your stay.

Writing an engine is a huge task. I'm currently writing one (using opengl) for my PGD entry (and future projects), and let me tell you, it is difficult and a lot of work. However, it is also very rewarding, so dont let the difficulty stop you there.

First thing you should consider is do you want to go 2D or 3D. If you go for Directdraw then it's going to be a huge task converting to 3D, if in the future you decide to go 3D.
I'm not sure about Windows Vista. I haven't really looked into that much, but I doubt Directdraw is not going to be supported in some way.
It is also not perse better to use D3D. It really depends on your needs. Writing a pixelperfect collision detection routine for example, is a whole lot harder since you can't easily detect pixels. D3D is however a whole lot faster.

I dont know about DirectDraw sources, but there are a couple people on PGD that have quite a bit of experience with D3D.

User137
25-03-2006, 12:06 PM
If you are going for DirectX, i'd recommend making the use of latest possible headers. There may be many publishers, pick one that seems much used :P
I started an OpenGL based engine about a year ago too (GLEngine). It has been much work but it works so well in every task i give it so i'm pleased with its progress. Just recent addition was fast frame based animation of 3D models.

chronozphere
25-03-2006, 12:54 PM
Thanx for your replies


Hi chronozphere,

First, let me welcome you to PGD. I hope you'll enjoy your stay.


Thanx :D

The game i want to make with my engine is 2d but must also use hardware acceleration for special fx.
So i defenitly want D3D support in my engine.



If you go for Directdraw then it's going to be a huge task converting to 3D, if in the future you decide to go 3D.


Okay, so if i definitly want D3D in my project, it will be difficult to use it with DirectDraw.
Is it a good idea to drop directdraw and make a 100% Direct3d engine (even if i want to make 2d games with it)??

About collision detection, i am only planning to use rectangles, circles, lines and points. So reading pixels for Collision detection wont be nessecary.
Is there more 2d stuff that will become harder when using D3D???



If you are going for DirectX, i'd recommend making the use of latest possible headers. There may be many publishers, pick one that seems much used


Remember that i only can use DX7 hardware until i have a better videocard installed.
I decided to use the specs of my machine as 'minimum system requirements' for my engine.

>> Is it worthwhile to use the latest headers, even if i begin with DX7?? (might use DX8 or DX9 later)
>>Is it hard to convert an engine to a newer DX version??
>>And, most important, wich headers would you recommend??

User137
26-03-2006, 12:17 AM
Sorry, can't help you with headers as i haven't used directx. But as for their version, you should still use DirectX 9 headers. They work fine with every graphics card, even old ones. DirectX9 just brings new additions that you can use or make them available to others who use your programs, but basic functions should work for everyone.

Try not to make just another DelphiX :wink: It use DX7 and everyone's complaining about it.

czar
26-03-2006, 12:31 AM
Hi chronozphere,

Any reason why you want to make a gfx engine? There are so many now available - they all do similar things and the support for them is being divided.

Is your goal to try and make an engine then cool. If your goal is to make a game then I would suggest putting effort into the actual game itself using one of the other engine's on offer.

Have a look at the DanJetX engine on www.dan.mirg.ru it does the lot including 3d animation and looks promising.

Traveler
26-03-2006, 01:19 AM
One reason could be the knowledge he gains. It is the #1 reason for me as well.

chronozphere
26-03-2006, 09:33 AM
Try not to make just another DelphiX Wink It use DX7 and everyone's complaining about it.


Is DX7 that bad, or is Delphix buggy?? :?
The main difference between DelphiX and my engine is that mine is gonna be 100% Direct3d. As Traveler mentioned, writing an engine wich uses both DirectDraw and direct3d is quite hard (and may not work well).
Or is it better to buy a DX8.1 GFX card for about 30/40 Euro's (maybe second hand), and try clooties DX8.1 SDK to write an engine??

@czar: Indeed DanJetFX looks pretty cool. I've tested some examples on an other machine (Wich has DX9) and they look awesome.
However i dont need that much features.
I assume DanJetFX uses DX9, if that is true, i rather use something else because i want my engine to be compatible with older machines witch probably use DX7 or DX8.1.
2D drawing using vertex quads, and a few blending and transformation tricks will do. :D



One reason could be the knowledge he gains. It is the #1 reason for me as well.


:D You're totally right :lol:

User137
26-03-2006, 12:02 PM
Is DX7 that bad, or is Delphix buggy?? :?
Or is it better to buy a DX8.1 GFX card for about 30/40 Euro's (maybe second hand), and try clooties DX8.1 SDK to write an engine??
Maybe there is some bugs but that is not header's fault. UnDelphiX is actually DirectX 8.1 but it cannot take use of latest graphics cards speed and visual tricks.

What i meant with old graphics cards, i mean like Riva TNT, GeForce 1, Radeon 8xxx series from time when computers were like 300MHz "Speedbusters" :lol: Every one of those can run program made with DX9 headers. There are things like Pixel shaders that are maybe supported by DX9 header but they also require high end graphics card, so simply don't code with them :P Advanced tricks anyway...

Here's few DX9 ones:
http://sourceforge.net/projects/delphi-dx9sdk/
.. and.. that's about all i could find :o

chronozphere
26-03-2006, 01:02 PM
Thanks, User137 for explaining the whole thing. :D

So, that was the reason why i could run the basic D3D examples for Clooties DX8.1 SDK on my DX7 GFX card (See Samples/Tutorial directory). They just don't use the fancy Pixel-shader thing(or whatever it might be).

So, if i use the DX8.1 SDK for my games. All user need to install DirectX 8.1, but will not always need a 100% DirectX 8.1 Compatilbe GFX card. This depends on whether the game uses the newest features or not).

For example if my game uses DX8.1 but only uses the features that where available in DX6, then the user only needs a DX6 compatilbe GFX card, but must have DirectX 8.1 installed.

Can someone verify this for me?? :wink:

User137
26-03-2006, 04:08 PM
That is correct as explained before :) And the same applies for OpenGL, which has numerous EXT, ARB, NV and others that differ greatly depending on graphics card. If use extensions/high end abilities be sure to check whether card is capable of using them. Some games have unique settings for different cards to display everything as optimal as possible.

chronozphere
27-03-2006, 09:11 AM
Thank you for you explanation. :D

NecroDOME
27-03-2006, 11:12 AM
3D game engine created from scratch by me:
http://necrodome.homeftp.net/Project.nss?project=App_Necro3D
I'm currently building the game .S.C.A.G. with it. It's using only triangles and DX9. Take a look. I also have created an engine with DX7, with NecroSPACE 2 was build on.

Success with your project!

chronozphere
27-03-2006, 12:45 PM
Yeah, i have already seen your website and the screenies. There is only on thing to say:

WOW :o

You must be a DirectX guru. How long are you programming with it??

I have allready played NecroSpace a few month's earlier, and it's a realy cool game, simple gameplay but amazing graphics. It has also a very nice intro movie. Very well done. :D ;)

If i where you, i would write some tutorials to show other people how to make games with Direct3d. :)
(That's exactly what im gonna do when i have that much experience).

NecroDOME
27-03-2006, 02:25 PM
The intro of NecroSPACE 2 sux, I wanted to make in fully 3D in my engine :P

I'm currently creating an engine that you can script your games.

ToDo list in engine:

- Model animation
- Model scripting
- Advance physics with newton (including ragdolls and car physics)
- Pixel and vertex shader support by .fx files
- More script functions, I already created pong :)
- Scene manegment
- Better skyboxes
- Maybe an advance/scripted particle system

For my next game I want to create some sort of race game, fully 3D.

chronozphere
27-03-2006, 06:39 PM
The intro of NecroSPACE 2 sux, I wanted to make in fully 3D in my engine


It may be a low resolution movie, but i do like the camera movement a lot. And yeah it would definitly better to make it in your engine (It reduces game filesize), but its way harder to do that.

I played the game but unfortunatly, it showed some hiccups, even if i set graphics detail to low. :cry:
Here are my specs:



Processor: intel pentium 4 (3.2 Ghz hyperthreading)
RAM: 512 MB DDR.
GFX Card: ATI Radeon 300X (128MB Video-ram and DX9 compatilbe)


I have no idea why this happens, although if i switch to windowed-mode its a lot faster.
The graphics are fantastic but apparently they also occupy quite a lot of system resources.
I couldn't exactly measure the speed because no FPS was shown.
I think i should upgrade my GFX card to get better results. Besides that its one of the best (non-commercial) games i've ever seen. :D

Even though S.C.A.G's screenies look very promising, it might be a good idea to add some extra options, like resolution, particle density, background detail etc.. for those who dont have an expensive GFX card (Mine was about 70 Euro).

I wonder what your specs are and how your games run on your pc??

Besides this all your work looks great. good luck with S.C.A.G ;)

NecroDOME
27-03-2006, 08:59 PM
NecroSPACE 2 has no real fullscreen option, its juist that I set a form fullscreen (i know, not the correct way)

The movie looks cool, but it was juist that I wanted exploding astroids and the ships shooting around. I'm just not that good in 3D max. I can model some things but animating it and making a movie out of it is a lot harder. In .S.C.A.G. I WILL NOT put .avi .mpg or whatever, I'm planning to make a real ingame movie :D (Hope I'll finish it before te compo ends)

Anyway, my computer specs:

AMD Athlon 64 3700+ (2.2 GHz)
1024 MB ram
2x nVidia GeForce 6800 - SLI configuration since I am a gamer
And a nice case :)

All games have no trouble running. I should test them on lower systems.

chronozphere
27-03-2006, 09:37 PM
NecroSPACE 2 has no real fullscreen option, its juist that I set a form fullscreen (i know, not the correct way)


Hmmm.... Interesting. I looked it up and i didn't found something yet.

One way to do this is using A directdraw object, and two flipping surfaces. You only have to render your scene to the backbuffer. (I dont know how you do such things, but i know they can be done :) ).



The movie looks cool, but it was juist that I wanted exploding astroids and the ships shooting around. I'm just not that good in 3D max. I can model some things but animating it and making a movie out of it is a lot harder.


I have 3ds Max too, i'am not a hardcore 3d artist but i can do some things with it. I will use it in the future to make some background images and maybe some of the sprites i will use in my games.



2x nVidia GeForce 6800 - SLI configuration since I am a gamer


Holy crap :o :o .. my ATI Radeon X300 is nothing compared to that.



All games have no trouble running. I should test them on lower systems.


That's indeed a good idea. I would like to test S.C.A.G when it is finished, and show you my FPS. :D

chronozphere
28-03-2006, 07:59 AM
Ohw... I found something. Clooties CD3DApplication
has a 'device and displaymode switching' feature.

I will try to figure out how it works, because i want to use it for my own engine.

If there is somebody here who could explain how to switch to another display-mode, could you please explain how this is done?? :p

NecroDOME
28-03-2006, 08:47 AM
Currently I use the Omega DX9 components, they have a fullscreen option, but it needs some tweaking since resolusions are hard coded.

tpascal
28-03-2006, 10:18 PM
If there is somebody here who could explain how to switch to another display-mode, could you please explain how this is done?? :p


Switch from windowed or full screen mode in a directx 8.x or above app is just a matter to destroy and recreate again the dx device with the correct parameters.

The device object is define like this:

D3DDEV8 : IDirect3DDevice8 = NIL

Then you need few more parameters structures to fill.

_d3dpp : TD3DPresent_Parameters;
_d3ddm : TD3DDisplayMode;
_dtype : TD3DDevType;


The full screen mode select is defined in _d3dpp

_d3dpp.windowed:=false; //false for full screen, true for windowed.
_d3dpp.hDeviceWindow:=__hWnd; //form handle or custum window handle.
_d3dpp.BackBufferWidth := _width; //full screen resolution desired.
_d3dpp.BackBufferHeight := _height; //only full screen suported videocard resolution (640x480, 800x600, 1024x768 etc).
_d3dpp.BackBufferFormat := D3DFMT_A8R8G8B8; //32 bit color format. (D3DFMT_R5G6B5 for 16 bit color format)
_d3dpp.BackBufferCount := 2; //two backbuffer.
_d3dpp.SwapEffect := D3DSWAPEFFECT_DISCARD;


then you create the D3DDEV8 object like this:

D3D8.CreateDevice(D3DADAPTER_DEFAULT, _dtype, _hWnd,
D3DCREATE_SOFTWARE_VERTEXPROCESSING,
_d3dpp, D3DDEV8);

//------------------------------------------

It is important to note that when you setup that in a delphi form application (so you are using VCL), indee you run in full screen mode but your delphi VCL app "thinks" is running in windowed mode and it keeps handling all messages events like it is needed in a VCL app, the mouse pointer still visible and when you move it the paint form event is called and ugly artifact blinks in your full screen rendering.

If you are going to use directx full screen app with delphi, then it is advised not to use VCL at all and just use windows API for create manually one window object and your own custom message loop with just the basic messages required by your game/application.

good luck.

tp.

chronozphere
29-03-2006, 07:28 AM
aah... thank you for this valueable information. :)

I've quickly tested it with my current (VCL) d3d app and it worked fine. Later i will build my own window with message loop. I dont know how this is done. Does someone have a link to a good tutorial that covers windows message loops and handling???



Then you need few more parameters structures to fill.

_d3dpp : TD3DPresent_Parameters;
_d3ddm : TD3DDisplayMode;
_dtype : TD3DDevType;


What exactly is the advantage of filling the TD3DDevType?? I looked into the CD3DApplication code and it seems to be al lot of work.
I just use D3DADAPTER_DEFAULT. :?

Thanx again for your reply. :D

NecroDOME
29-03-2006, 03:18 PM
Rendertargets need te reset to! donno why, but at my system I got problems when I create a rendertarget and render to an other form.