Sign in to follow this  

DirectX9 Direct3D 2D games...

This topic is 3588 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

***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

Share this post


Link to post
Share on other sites
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..

Share this post


Link to post
Share on other sites
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

[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;


Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
As I mentioned look up using D3DXSprites as they are a utility for easy 2d image display without needed to do any 3d work. Just initialize DirectX and call LoadTexture(). Then to draw its simple sprite.draw().

Share this post


Link to post
Share on other sites
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 [url]http://geekswithblogs.net/clingermangw/articles/83997.aspx[/url]

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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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)

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Assuming you're using Managed DirectX9 with VB.Net, I would also recommend reading through Mr. Clingerman's first 2 tutorials (page showing links to all 3 tutorials in the series here: http://geekswithblogs.net/clingermangw/category/5002.aspx ).

They helped me quite a bit in getting my 2D graphics library started (I'm using SlimDX, though, which is quite similar to Managed DirectX ... I first worked up a Managed DirectX version of what I wanted to do, then tweaked things to fit the slight changed needed for SlimDX .).

Good luck with your project,
-Matt

Share this post


Link to post
Share on other sites
Thanks MattWorden,
I have a question about "Gee, I can make black form." (http://geekswithblogs.net/clingermangw/articles/83997.aspx)
what do I need To do about the main loop (Where and how do I need to put it) if I'm initializing D3D through the game form (aGameEngine)?
Take a look in my project in DirectDraw to see what I'm talking about - http://www.mediafire.com/?1nkmz7d42ah

Thanks in advance,
Benny

Share this post


Link to post
Share on other sites
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.


Go ahead and try it yourself. Specify that you want a hardware video surface, and then use SDL_VideoDriverName to see what driver its using (Windib is their name for the GDI driver).

Presumably SDL leaves in DDraw support for platforms that still support it in hardware.

Share this post


Link to post
Share on other sites
In the future DirectDraw will not be supported anymore.
Everything will be done in Direct3D. This is not a very difficult task actually.
the first thing you have to do is initialize a Direct3d device. This may be difficult if you haven't read my first post. but I can help you if you have problems.

the next task is to create a sprite object and draw a texture to the screen using one of the three commonly used methods for the gameloop.

1. Using the onPaint method.
which is not very fast actually.

2. Using the DoEvents() method.
which is not vry fast either.

3. using the peekmessage method.
this one is fast.
it will check if there are any windows messages waiting. if not it
executes a defined code (like update and draw or something).

Your imagination is your only limitation. I made a game engine with sprites, tilemaps, sound (fmod) and input (directInput & clr input) with c# and managed direct3D. vb could also be used.

It may take a while to make a game with managed DX and VB but it can be done.
It took me about one evening to make a ponggame with my game engine (including graphics,sound,input).

my point is: Managed DX isn't very hard, but you need to have a understanding of how games are coded since DX only handels the graphics part.

[Edited by - id0001 on February 16, 2008 3:55:52 AM]

Share this post


Link to post
Share on other sites
I have another question ( I found a way around my last problem):
In the tutorial
http://geekswithblogs.net/clingermangw/articles/83997.aspx
the game engine is initialized through the Direct3D engine, nut then the Direct3D is initialized through the game engine

In DX3DEngine:

Public Shared Sub Main()
'Create a form to attach the DirectX device to
Dim aMainForm As New Windows.Forms.Form
'Create the Game engine
Dim aGameEngine As New GameEngine(aMainForm)
'Display the form
aMainForm.Show()
'Continue the game loop while the form is still running
Do While aMainForm.IsDisposed = False
'Give the computer a chance to process some other things
Application.DoEvents()
'Render the scene
aGameEngine.Render()
Loop
'Destroy the Game Engine
aGameEngine = Nothing
'Destroy the Main form
aMainForm = Nothing
End Sub


In GameEngine:

Private mGraphics As DX3DEngine
'Description: The class constructor. Create the objects for the class
Public Sub New(ByVal theRenderTarget As Control)
mGraphics = New DX3DEngine(theRenderTarget, True)
End Sub


Can someone please explain what this is about?

Share this post


Link to post
Share on other sites

This topic is 3588 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this