2d Graphics, what's best

shouzama

Active member
Joined
Jan 20, 2003
Messages
38
Location
Another World
Since Im new to this board, I dont know if youve discussed this argument in the past.

Im trying to put up a 2d engine (quite a simple one) using DX9 and VB.NET.

It will be required to do the most common tasks: tiling images, displaying sprites, using transparency and some scaling/rotating effects.

So, basically, I have 2 choices:
DirectDraw
Direct3D.Sprite

What will be the better choice?

(NOTE: I already started with DDraw, basically to "experiment" a little, no problem if Ill have to start again)
 
The only experience I have so far is with using GDI+, which worked quite well. I hear that DX9 DirectDraw can interact with .NET Bitmap objects so theres a chance youll be able to use both.
 
Originally posted by divil
The only experience I have so far is with using GDI+, which worked quite well. I hear that DX9 DirectDraw can interact with .NET Bitmap objects so theres a chance youll be able to use both.

Well, thats true, you can pass a Bitmap object to a DirectDraw.LoadSurface method (if I do remember correctly) - and thats really helpful since it can save a lot of work.

However, you can do the same with the Direct3D.Sprite, since the LoadTexture supports Bitmap as well.

Again, which one should I choose?
 
Since you want rotation, Id go with the Sprite class (and Direct3D interfaces). Besides, DirectDraw is still DX7. Some like it, and its simpler, but Direct3D will give you more power (if you need it, like you do for rotations).

Theres no built in support for rotations in DX7. But, if you DO decide to use Direct3D, be prepared for some more up-front learning. Its a bit harder to use since theres no direct "BitBlt" equivalent in Direct3D. The built-in Sprite class handles the most common types of "sprite" (2D drawing) youll want, but if you need to enhance it, it will get a bit messy.

-nerseus
 
Thanks Nerseus, thats exactly the answer I was looking for.

Besides, in my past experiences, I found the Sprite class to be quite useful to handle the most common tasks, and I already made a VERY basic tile engine (with the old VB6 and DX8 couple).

Since (as you say) there arent been many improvements in DirectDraw technology, I think Ill look for the Sprite class ^_^

So, a new problem arises... Initialization in D3D can be quite a mess... Be prepared to some new questions :P

Thanks again.
 
If you installed the full SDK, you should get a "New Project Wizard" for creating DirectX apps. The wiz allows you to pick a Direct3D project (among others) and start off with a Teapot. Id suggest looking at the code given by the wizard as there is a TON of it there - everything from initialization to events and more.

I dont believe there are any samples using the sprite class with DX9 but there are lots of samples with VB6 and the interface hasnt really changed. Ive coded a sprite class in C# that builds the triangles by hand so if you decide to go that route and need any help, let me know.

-Nerseus
 
To tell the truth I got the initialization code from the great tutorial found at DirectX4VB. GREAT to say the least.

CEngine will be the class that handles the main graphic works (initialization and so on)

CPainter will handle the Sprite class from DirectX

CSprite will handle the single sprites and their drawing function

CTile will handle the single tile, and will inherit from CSprite.

As soon as possibile Ill put my code here, so you can be inspired/give suggestions (VERY needed, if you ask :P)

Out for now, c ya soon.
 
Going further in my ramblings, I hope this wont annoy you... :(

After much research, trials and errors I decided to "go DirectDraw".

However, I still want some suggestion.
What I discovered is that, for a 2D-only engine, DirectDraw is far better than D3D.

Building a 2d tile-engine using D3D.Sprite is quite easy, but I found that drawing 20x15x30 tiles drops the frame rate dramatically to 10-20fps... :( (these statements are based on Environment.TickCount(), and thats not too reliable)

In my engine Ill need:
TILEs, 20x15, on at least 4 layers (so 20x15x4 tiles to draw on every frame)
SPRITEs, any number (but VERY probably LESS than TILEs)
PICTUREs (can easily be considered sprites)

Do you have some suggestion for a tile-based engine?:confused:
 
Are you sure its not something else dropping your frame rate and/or that youre calculating it correctly? Does your graphics card normally go faster than that?

Depending on the implementation of the sprite class, you could also see a HUGE drop in performance if its not optimized for tiling. For example, if each call to Sprite.Draw is setting the texture and calling device.Begin and device.End (BeginScene/EndScene I think) then you may be wasting a lot of cycles. For my Ms Pacman clone, I wrote a "SpriteList" class that takes a bunch of individual sprites and combines all their vertices or vertex buffers. Assuming your tiles all share the same texture, you really only need to call SetTexture and BeginScene one time then draw every sprite in one shot. A nicely packaged sprite engine isnt necessarily the fastest thing - it just makes drawing sprites easier.

If you want, check out the VB Game forums. To misquote Banjo from another thread, writing a tile-based RPG in VB is a common affliction amoungst novice programmers. I hope you dont fall into that category :)

-Nerseus
 
Well, I surely hope so :)

Thanks for the link and info, Nerseus!

I think that the Sprite class of D3D DOES set the texture on every call of its .Draw method.
So, one way around would be the use of vertex buffer and handling the rendering by myself.

For compatibility with another program, sadly, I need to load graphic resources of various dimension, absolutely NOT square.

I think the only way to go will be by DirectDraw.

Ill perform a search "tile engine" on the forum you linked and see what the results will be :P

Thanks again
 
About every 5th post is for a tile engine, I think. Id sort by post count or replies. There are MANY posts with attachments for tile engines, some good, some... not so much. Most are for making editors - not a lot of real game making going on in the forums :)

-nerseus
 
Whew, youre quite right, you know?! ;)

HERE I found a quite interesting discussion on tiling with D3D.

I posted up here since its useful to anyone willing to create a 2d engine.

Again, time to go back coding. See ya tomorrow!
 
Back
Top