DirectX9 Direct3D 2D games...
Started by BennyK, Feb 12 2008 07:44 AM
27 replies to this topic
#1 Members - Reputation: 122
Posted 12 February 2008 - 07:44 AM
***Introduction:
Hi everyone,
I'm using VB.NET 2005 and I developed many games using Visual Studio's designer.
As you'd probably expect, I soon enough found it less suitable for more serious games.
Then I moved on to DirectX's DirectDraw. Having encountered many problems I sought
help here. I've been warmheartedly recommended against using DirectDraw, and using Direct3D instead, even for 2D games.
***Bottom line:
I'm having many problems in initializing Direct3D for 2D games (I remember reading something about orthographic projection)and actually drawing something.
most of the guides I read aren't clear, many of them don't work, and all of them aren't suitable for 2D games. Plus, ms's examples either don't work after being converted to VB 2005 or stop working as soon as I try to add some code of my own.
I'd really appreciate it if someone will find me a good, step-by-step tutorial for initialization of direct3D, suitable for 2D games.
Benny
Sponsor:
#2 Members - Reputation: 115
Posted 12 February 2008 - 07:58 AM
Yo can still use DirectDraw this is what I am doing and it's far less complicated, only surfaces blitting.
Even SDL exclusively relies on Direct Draw ( if you target win32 machines of course ).
This API is marked as deprecated by Microsoft but it is still supported by DirectX 9 and 10.
Even with D3D interfaces you can get a DDraw surface.
If you want to use DDraw again, you need a C++ compiler.
I would recommend first to design a good 2d game with SDL or DDraw then migrating to Direct 3d.
This is my opinion it's up to you..
Even SDL exclusively relies on Direct Draw ( if you target win32 machines of course ).
This API is marked as deprecated by Microsoft but it is still supported by DirectX 9 and 10.
Even with D3D interfaces you can get a DDraw surface.
If you want to use DDraw again, you need a C++ compiler.
I would recommend first to design a good 2d game with SDL or DDraw then migrating to Direct 3d.
This is my opinion it's up to you..
#3 Members - Reputation: 184
Posted 12 February 2008 - 10:33 AM
EDIT: I don't have a clue about DX in VB so just change the code below so it's suitable for VB. /EDIT
It's pretty pointless using DirectDraw these days. Even setting it up is pretty painful. It's not hardware accelerated in new video cards anymore as far as I know.
Probably the easiest way to do 2D with Direct3D is look into using a Vertex format with a RHW value, which would basically give you pre-transformed vertexes, which means you can specify co-ordinates as screen pixel values rather than having to mess with projection matrixes and orthographic projection and all that :)
use this as your FVF and just set it with d3d.lpD3DDevice->SetVertexShader( D3DFVF_TLVERTEX); or whatever is equivelant for your code
It's pretty pointless using DirectDraw these days. Even setting it up is pretty painful. It's not hardware accelerated in new video cards anymore as far as I know.
Probably the easiest way to do 2D with Direct3D is look into using a Vertex format with a RHW value, which would basically give you pre-transformed vertexes, which means you can specify co-ordinates as screen pixel values rather than having to mess with projection matrixes and orthographic projection and all that :)
use this as your FVF and just set it with d3d.lpD3DDevice->SetVertexShader( D3DFVF_TLVERTEX); or whatever is equivelant for your code
[source code="cpp"]
typedef struct _D3DTLVERTEX {
union {
float sx;
float dvSX;
};
union {
float sy;
float dvSY;
};
union {
float sz;
float dvSZ;
};
union {
float rhw;
float dvRHW;
};
union {
D3DCOLOR color;
D3DCOLOR dcColor;
};
union {
D3DCOLOR specular;
D3DCOLOR dcSpecular;
};
union {
float tu;
float dvTU;
};
union {
float tv;
float dvTV;
};
#if (defined __cplusplus) && (defined D3D_OVERLOADS)
_D3DTLVERTEX() { }
_D3DTLVERTEX(const D3DVECTOR& v,float w,D3DCOLOR col,D3DCOLOR spec, float _tu, float _tv)
{ sx = v.x; sy = v.y; sz = v.z; rhw=w;
color = col; specular = spec;
tu = _tu; tv = _tv;
}
#endif
} D3DTLVERTEX, *LPD3DTLVERTEX;
#4 Moderators - Reputation: 5471
Posted 12 February 2008 - 02:33 PM
Quote:
Original post by HolyGrail
Even SDL exclusively relies on Direct Draw ( if you target win32 machines of course ).
SDL defaults to GDI, even if you specify that you want a hardware device. This is because DirectDraw no longer provides hardware acceleration.
#5 Members - Reputation: 1084
Posted 12 February 2008 - 04:36 PM
Hi there BennyK,
What you should be looking at is the following, Look at the D3DFVF_XYZRHW format if you are using Direct3D9. This basically specifies that the components of the vertex have already been transformed and no transformation operation will be performed on them. This allows you to place objects at exact locations in screen space.
I hope this helps.
Take care.
What you should be looking at is the following, Look at the D3DFVF_XYZRHW format if you are using Direct3D9. This basically specifies that the components of the vertex have already been transformed and no transformation operation will be performed on them. This allows you to place objects at exact locations in screen space.
I hope this helps.
Take care.
#6 Members - Reputation: 122
Posted 12 February 2008 - 05:28 PM
Thanks people,
HolyGrail: I already have a functioning DirectDraw game. I decided to move on to Direct3D and I don't think the reasons are worth discussing again.
As for sirlemonhead and Armadon, I barely have a clue about DirectX.Direct3D (let alone on CPP) so I couldent quite figure out what you are writing about...
BTW, can I attach a file here?
HolyGrail: I already have a functioning DirectDraw game. I decided to move on to Direct3D and I don't think the reasons are worth discussing again.
As for sirlemonhead and Armadon, I barely have a clue about DirectX.Direct3D (let alone on CPP) so I couldent quite figure out what you are writing about...
BTW, can I attach a file here?
#9 Members - Reputation: 122
Posted 12 February 2008 - 05:48 PM
I'd also appreciate it if people will read my post and find out what I asked for before replying.
A link to my DirectDraw game so you'll be able to see what I'm looking for in Direct3D: http://www.mediafire.com/?1nkmz7d42ah
A link to my DirectDraw game so you'll be able to see what I'm looking for in Direct3D: http://www.mediafire.com/?1nkmz7d42ah
#14 Members - Reputation: 122
Posted 13 February 2008 - 02:28 AM
there are quite a few tutorials about managed directX and direct3D out there on the internet.
just google for it.
I typed "vb direct3d sprite tutorial"
and I found http://geekswithblogs.net/clingermangw/articles/83997.aspx
good luck with your 2d game. Im making a 2d game engine myself with c# so if you have any further questions regarding sprites, etc. you can ask me.
ID
just google for it.
I typed "vb direct3d sprite tutorial"
and I found http://geekswithblogs.net/clingermangw/articles/83997.aspx
good luck with your 2d game. Im making a 2d game engine myself with c# so if you have any further questions regarding sprites, etc. you can ask me.
ID
#15 Members - Reputation: 1518
Posted 13 February 2008 - 02:45 AM
BennyK, VB.NET does not appear to be a popular game development language these days. Sure, people do use it, but the vast majority (gaming or otherwise) of .NET material is for C#. Native application development on Windows is primarily C/C++.
If you go against the common flow in any technology then you have to appreciate that there are less resources and less people available to answer your specific questions.
Thankfully .NET API's are pretty much identical regardless of which language you use. I'm sure you can read enough C#-Direct3D code to get a good idea of what to type for your VB.NET-Direct3D code. Intellisense, documentation and these forums will fill in the final few details.
Have a go at reading the C# samples and articles and see where you get to. If there are any specific fragments of DX-specific code you can't translate then feel free to come back here, post what you found, post your attempted conversion and see if we can help out.
Best of luck!
Jack
If you go against the common flow in any technology then you have to appreciate that there are less resources and less people available to answer your specific questions.
Thankfully .NET API's are pretty much identical regardless of which language you use. I'm sure you can read enough C#-Direct3D code to get a good idea of what to type for your VB.NET-Direct3D code. Intellisense, documentation and these forums will fill in the final few details.
Have a go at reading the C# samples and articles and see where you get to. If there are any specific fragments of DX-specific code you can't translate then feel free to come back here, post what you found, post your attempted conversion and see if we can help out.
Best of luck!
Jack
<hr align="left" width="25%" />
Jack Hoxley <small>[</small><small> Forum FAQ | Revised FAQ | MVP Profile | Developer Journal ]</small>
Jack Hoxley <small>[</small><small> Forum FAQ | Revised FAQ | MVP Profile | Developer Journal ]</small>
#16 Members - Reputation: 122
Posted 13 February 2008 - 04:13 AM
Thanks id0001, I have a look there. Looks promising...
jollyjeffers: I don't think C# is more or less popular then VB... They are basically the same languages except that C# looks a bit more like C or Java as far as I can tell. Most of the tutorials I found have both VB and C# examples...
BTW, is that true for all .NET languages?(besides ASP)
jollyjeffers: I don't think C# is more or less popular then VB... They are basically the same languages except that C# looks a bit more like C or Java as far as I can tell. Most of the tutorials I found have both VB and C# examples...
BTW, is that true for all .NET languages?(besides ASP)
#17 Members - Reputation: 122
Posted 13 February 2008 - 05:08 AM
Quote:
BTW, is that true for all .NET languages?(besides ASP)
you can convert any .net language into an other .net language.
I exported my game engine into a dll file and then I made a game with vb using my game engine's dll included as a reference.
#18 Members - Reputation: 115
Posted 13 February 2008 - 08:27 AM
Quote:
Original post by MJP
SDL defaults to GDI, even if you specify that you want a hardware device. This is because DirectDraw no longer provides hardware acceleration.
Ok.
Is there any link or proof your statement ?
You say that DirectDraw no longer provides hardware acceleration.
If it's the case, I don't understand because ddraw.dll is still present.
#19 Members - Reputation: 122
Posted 13 February 2008 - 05:07 PM
The main problem with using DirectDraw in DirectX9 is that It doesn't support blitting anymore which was why it was so fast.
Now it's much slower without this option, and even slower when not using FullScreenExclusive mode, which makes a LOT of problems.
Now it's much slower without this option, and even slower when not using FullScreenExclusive mode, which makes a LOT of problems.
#20 Members - Reputation: 184
Posted 13 February 2008 - 11:03 PM
Quote:
Original post by HolyGrail Quote:
Original post by MJP
SDL defaults to GDI, even if you specify that you want a hardware device. This is because DirectDraw no longer provides hardware acceleration.
Ok.
Is there any link or proof your statement ?
You say that DirectDraw no longer provides hardware acceleration.
If it's the case, I don't understand because ddraw.dll is still present.
DirectDraw is still there and is usable, but it's not hardware accelerated anymore. Modern GPU's just dont have any support for that stuff in hardware anymore because directdraw is obsolete.






