🔒 Locked
I need code really badly!
Advertisement
Original Post
I started to write a 2d game using direct3d. Lots of people told me I should use direct3d instead of direct draw. The problem is, when I just blitted to a surface I couldn't do clipping. So I tried to use textures for my animations. That made my game REALLY slow because I have a lot of sprites in my program. So I've decided I'm going to try direct draw. Could someone please give me code for an animation using direct draw 7 that will compile under direct x 9 summer update edition? Right now I've got directdraw set up but I got stuck at GetAttachedSurface. My compiler wants me to use LPDDSCAPS2 in GetAttachedSurface, but I can't do this with it: ddscaps.dwCaps = DDSCAPS_BACKBUFFER it is saying basically that the left of the . must be a structure or object, I think. Anyway, I'm using data types with the 7 after them, so I need that type of code. I just want enough beginning at setting the backbuffer that continues on to set a color key for transparency and allows for clipping and just basically shows one simple sprite on the screen. If I have enough code to do that I can figure out my game the rest of the way, and I understand code well enough to get it to work with what I'm doing, it just has to be complete code with initializations and everything included. I would REALLY appreciate it if someone could help me on this. Thanks.
they stopped updating directdraw. but it still works with DX 8 or 9. and you can still code and compile DX 7 code with it.
i believe if you can find the ddraw.h file and changed the directdraw version to 0x7000 you'll be fine.
i believe if you can find the ddraw.h file and changed the directdraw version to 0x7000 you'll be fine.
jimiwa, any code you find for DirectDraw should be for version 7. Nothing has changed in version 8 nor in version 9. DirectX is backwards compatible so you can easily compile version 7 code.
No one is going to take the time to write code for you, especially something like an animation system. We will answer specific questions however.
What kind of clipping did you have in mind? Only rendering to certain areas of the render target? Stencil buffers can be used to accomplish this.
Quote:
The
problem is, when I just blitted to a surface I couldn't do
clipping.
What kind of clipping did you have in mind? Only rendering to certain areas of the render target? Stencil buffers can be used to accomplish this.
how bout using d3d, its better than ddraw
u have no clue if u think ddraw is better
u have no clue if u think ddraw is better
Well here is some old dirrect draw clipping code from a VB.NET project of mine. It works nice, I think I got it from here actually faily elegant... ahhemm.
BTW DirectX 9.0 includes dirrect draw, it's just unchanged from the 8.0 version.
Dim srcrect As New System.Drawing.Rectangle
Dim destrect As New System.Drawing.Rectangle(xPixel - offsetX, yPixel + offsetY, 100, 100)
srcrect = (solarsystem.sourceframe(solarsystem.curframe))
Dim cliprect As New Rectangle(0, 0, 800, 600) 'clipper rectange.. whole screen
If destrect.X < cliprect.X Then srcrect.X += cliprect.X - destrect.X
If destrect.Y < cliprect.Y Then srcrect.Y += cliprect.Y - destrect.Y
destrect.Intersect(cliprect)
srcrect.Height = destrect.Height
srcrect.Width = destrect.Width
If destrect.Width > 0 AndAlso destrect.Height > 0 Then
back.Draw(destrect, solarsystem.surfaceAnimation, _
srcrect, DrawFlags.DoNotWait Or DrawFlags.KeySource)
End If
End If
BTW DirectX 9.0 includes dirrect draw, it's just unchanged from the 8.0 version.
Dim srcrect As New System.Drawing.Rectangle
Dim destrect As New System.Drawing.Rectangle(xPixel - offsetX, yPixel + offsetY, 100, 100)
srcrect = (solarsystem.sourceframe(solarsystem.curframe))
Dim cliprect As New Rectangle(0, 0, 800, 600) 'clipper rectange.. whole screen
If destrect.X < cliprect.X Then srcrect.X += cliprect.X - destrect.X
If destrect.Y < cliprect.Y Then srcrect.Y += cliprect.Y - destrect.Y
destrect.Intersect(cliprect)
srcrect.Height = destrect.Height
srcrect.Width = destrect.Width
If destrect.Width > 0 AndAlso destrect.Height > 0 Then
back.Draw(destrect, solarsystem.surfaceAnimation, _
srcrect, DrawFlags.DoNotWait Or DrawFlags.KeySource)
End If
End If
If you found using D3D for your sprites was too slow, chances are that either you made a mistake in your code (e.g. using too many textures, no texture batching, using multiple ID3DXSprites...) or you're drawing so much sprites that you'll find a DirectDraw version equally slow. I bet the first one was it.
Maybe you would like to post some of your D3D sprite rendering code so we can see if anything is wrong.
Maybe you would like to post some of your D3D sprite rendering code so we can see if anything is wrong.
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement