Examples of 2d in D3D Classes

iMuYa said:
40x20, that means u use 800 sprite objects to come out the background. How's the memory consumption? Consumed lots of memory?

ThePentiumGuy, can you tell the reason why using Paint - Invalidate is better than using WHILE LOOP?

Any recommendation from you guys, how to compact the use of memory. .NET used up too much memory I think.

Thanks.

The trick is to DELETE all of those objects once they are created and just "think" of the map as one object. My map object is a class that holds all of the data for the map and all of the map can be drawn from this class alone.

So there is a little less consumption here if you aren't storing all of that data somewhere. But, either way works too.
 
iMuYa said:
ThePentiumGuy, can you tell the reason why using Paint - Invalidate is better than using WHILE LOOP?

Any recommendation from you guys, how to compact the use of memory. .NET used up too much memory I think.

Thanks.
Using loops take up a LOT more resources, the Paint trick is another way of doign a loop (becuase Me.Invalidate calls the paint event again :D).

I'm not too sure how to compact the memory :s, im developing on a good computer (3.0c, 1 gb ram)- its actually sort of bad to develop on a good computer as opposed to an average computer becuase you assume that your program is fast enough :-D.

-The Pentium Guy
 
ThePentiumGuy said:
Using loops take up a LOT more resources, the Paint trick is another way of doign a loop (becuase Me.Invalidate calls the paint event again :D).

I'm not too sure how to compact the memory :s, im developing on a good computer (3.0c, 1 gb ram)- its actually sort of bad to develop on a good computer as opposed to an average computer becuase you assume that your program is fast enough :-D.

-The Pentium Guy
You are correct on both points. Testing on a REALLY nice computer is sort of worthless...that is why you should work on optimization later on in the project when you can test it on a different computer.

BTW, I would like to point out that VB.NET has AWESOME memory management. It is like 2.33 times better than VB6. Don't believe me?

http://216.5.163.53/DirectX4VB/Tutorials/GeneralVB/GM_NETvsVB6.asp
 
Here, I attached a Sprite class, quite similiar to the one used in this forum. Anyway, this is not my original job. I extracted from the Tutorial game The RiverPlanet V.I. It supports transparency.

Thanks.
 

Attachments

You got this from ".NET Game Programming with DirectX 9" eh?
I love that book :).

Hey btw, there are a couple problems with the sprite class from that book, and it has to do with creating the vertex buffer:

First of all, the FVF_CUSTOMVERTEX in the class you attached is not defined :p.
Second of all:

Dim Vertices as CustomVertex() is not a good way to code... this is because you must specify the type of CustomVertex... for example

Dim Vertices As CustomVertex.PositionTextured().

In either case, Dim Vertices as CustomVertex() would not work becuase in the book, it is defined in another class (GameClass I beleive)

3rd of all, in public sub Draw:
If transparent then
objDirect3DDevice.Alphablend = True
End If

would not work :), in the book they turn on the SourceBlend and the InvSourceBlend in the Initialize sub in the GameClass.

4th of all, CreateFlexVertex (arguments) as CUSTOMVERTEX would not work, becuase CUSTOMVERTEX is defined in GameClass in the book (or something like that)..
The easiest thing to do is rather than use that function, just say
Vertices(0) = new CustomVertex.<whatever>(arguments)

The book is great(that's what my tutorials are mainly based off of), but its got a few quirks here and there :P)

Just remember, don't define anything as "CustomVertex"... becuase CustomVertex is a DirectX class,

-The Pentium Guy
 
ThePentiumGuy said:
You got this from ".NET Game Programming with DirectX 9" eh?
I love that book :).

Hey btw, there are a couple problems with the sprite class from that book, and it has to do with creating the vertex buffer:

First of all, the FVF_CUSTOMVERTEX in the class you attached is not defined :p.
Second of all:

Dim Vertices as CustomVertex() is not a good way to code... this is because you must specify the type of CustomVertex... for example

Dim Vertices As CustomVertex.PositionTextured().

In either case, Dim Vertices as CustomVertex() would not work becuase in the book, it is defined in another class (GameClass I beleive)

3rd of all, in public sub Draw:
If transparent then
objDirect3DDevice.Alphablend = True
End If

would not work :), in the book they turn on the SourceBlend and the InvSourceBlend in the Initialize sub in the GameClass.

4th of all, CreateFlexVertex (arguments) as CUSTOMVERTEX would not work, becuase CUSTOMVERTEX is defined in GameClass in the book (or something like that)..
The easiest thing to do is rather than use that function, just say
Vertices(0) = new CustomVertex.<whatever>(arguments)

The book is great(that's what my tutorials are mainly based off of), but its got a few quirks here and there :P)

Just remember, don't define anything as "CustomVertex"... becuase CustomVertex is a DirectX class,

-The Pentium Guy

In all honesty, I haven't come across one tutorial that didn't have its quirks. I think that it is part of the learning experience for them to have quirks. If you can fix the quirks, you have successfully "learned" the material.
 
This was tested in FullScreen, a 393216 vertex Heightmap was rendered on a:
3.0c & 1 gb ddr3200 & radeon 9800 pro overclocked to XT speeds

Using the "Paint Trick"... FPS = 44
Without using the Paint Trick... FPS = 43

... DOH :), you're right, this has no effect on FullScreen whatsoever.

-The Pentium Guy
 
ThePentiumGuy said:
This was tested in FullScreen, a 393216 vertex Heightmap was rendered on a:
3.0c & 1 gb ddr3200 & radeon 9800 pro overclocked to XT speeds

Using the "Paint Trick"... FPS = 44
Without using the Paint Trick... FPS = 43

... DOH :), you're right, this has no effect on FullScreen whatsoever.

-The Pentium Guy

Ya, I would hope it didn't have any effect. If it did...I would be worried. ;)

That is because when you have fullscreen, it gives you exclusive rights to the screen pretty much. Which means a really nice boost in speed. The reason why your paint trick works is not because loops are "slow", it is because GDI+'s paint() function is slow. When you override it like that, you are effectively speeding it up.
 
Last edited:
cant check it now.. vacation.. Will check when i come home.. Cant you just download my project and check self?? It should be ready to compile...

EDIT: I saw you edited your post.. :p

--Loffen
 
Loffen said:
Ok.. here it is.. Had very short time, so if i missed a part just tell me..
Rendering the transparent sprite is not included though...

I'm attempting to get this code to run, but can't. Maybe it's because I'm using the summer 04 update.

I get the following error:
C:\Documents and Settings\Nick\My Documents\Visual Studio Projects\EngineDocumented\GraphicsText.vb(45): Overload resolution failed because no accessible 'DrawText' can be called with these arguments:
'Public Function DrawText(sprite As Microsoft.DirectX.Direct3D.Sprite, text As String, pos As System.Drawing.Point, color As Integer) As Integer': Value of type 'String' cannot be converted to 'Microsoft.DirectX.Direct3D.Sprite'.
'Public Function DrawText(sprite As Microsoft.DirectX.Direct3D.Sprite, text As String, pos As System.Drawing.Point, color As Integer) As Integer': Value of type 'System.Drawing.Rectangle' cannot be converted to 'String'.
'Public Function DrawText(sprite As Microsoft.DirectX.Direct3D.Sprite, text As String, pos As System.Drawing.Point, color As Integer) As Integer': Value of type 'Integer' cannot be converted to 'System.Drawing.Point'.
'Public Function DrawText(sprite As Microsoft.DirectX.Direct3D.Sprite, text As String, pos As System.Drawing.Point, color As Integer) As Integer': Value of type 'System.Drawing.Color' cannot be converted to 'Integer'.
'Public Function DrawText(sprite As Microsoft.DirectX.Direct3D.Sprite, text As String, pos As System.Drawing.Point, color As System.Drawing.Color) As Integer': Value of type 'String' cannot be converted to 'Microsoft.DirectX.Direct3D.Sprite'.
'Public Function DrawText(sprite As Microsoft.DirectX.Direct3D.Sprite, text As String, pos As System.Drawing.Point, color As System.Drawing.Color) As Integer': Value of type 'System.Drawing.Rectangle' cannot be converted to 'String'.
'Public Function DrawText(sprite As Microsoft.DirectX.Direct3D.Sprite, text As String, pos As System.Drawing.Point, color As System.Drawing.Color) As Integer': Value of type 'Integer' cannot be converted to 'System.Drawing.Point'.
 
Back
Top