I've just converted a tile game over to Direct X/Draw because I'm sick of BitBlt's poor speed when dealing with transparent images. =) I've just got one of MS's DX8 SDK examples and modified it.
However, the main dx blt loop is VERY very slow (and I have a Duron 800!)... I'm getting a poor FPS rate, when I shouldn't be, because all I'm doing is setting the source/target x/y's, and calling the blt function. What could be wrong with it? I've attached the source code.
I've found that the problem lays somewhere within "For ZArray = 1 To Tactical.ZLevel" and "Next ZArray".
I still haven't got a proper map working (I've switched from pure isometric, back to 2D tiles with an isometric perspective), so it may look a little odd...but all I'm concerned about is the performance!
Just a note that I didn't include the background bmp, as it was too large, so the background won't be cleared for each blt loop.
By the way, how do I make the transparent colour purple, instead of black?
I didn't look at the code yet, but if you're using DX8, you might want to consider stepping back to DX7, since it supports DirectDraw which makes 2D easier...
Teaudirenopossum.Musasapientumfixaestinaure. (I can't hear you. There's a banana in my ear)
Yeah, I use DX8. I heard DX7 was easier to use with DD, but I couldn't really find any examples using DX7 (on Planet Source Code), and I can't find a link to the MSDX7SDK for VB...
From what I can see, it's maybe slow because I'm using Blt, instead of BltFast...how can I fix this?
The DirectX4VB link I gave you in my last post has a good set of tutorials for DX7...
The DX7SDK is not available from Microsoft anymore (I think), but I'm sure it's available somewhere. At least the DirectX7 Type Library should be included with DX8, so unless you need the samples (which by the way are crap compared to the DirectX4VB site, at least that's my opinion) you don't need the DX7SDK at all...
I can't help you out if you're using DX8, sorry, I'm still using DX7
Btw, BltFast is a little faster as far as I know, but it shouldn't be that much difference...
Teaudirenopossum.Musasapientumfixaestinaure. (I can't hear you. There's a banana in my ear)
Changed to BltFast, wasn't speeding it up either...
Why aren't you using Fullscreen mode? I know my video card can't handle windowed mode very well, and so do most video cards I think, so it's probably (probably? I'm sure it is! ) much faster in fullscreen.
Teaudirenopossum.Musasapientumfixaestinaure. (I can't hear you. There's a banana in my ear)
This shows you fullscreen DirectDraw...
Basically, you remove the Picturebox (and the Clipper object) and put an extra surface in it instead, which is used for the front buffer. Everything is drawn to the backbuffer exactly like you did before, but instead of blitting it to the front buffer (or a picturebox), you're calling Flip, which moves all data in the backbuffer to the front. Flipping is much faster than blitting, and done directly by the video card...
Teaudirenopossum.Musasapientumfixaestinaure. (I can't hear you. There's a banana in my ear)
Ok, I've implemented the flip... but now I don't have a rtemp RECT. So, how do I tell the function where to blit onto the surface, and the source surface and x/y co-ords? This is what I have so far, but I'm so new to DD/DX I dunno what to do...
Well, since you've got the speed, it's just a matter of some maths and blitting tiles. If you don't know how to use DD, I suggest looking trough the tutorials at http://www.vbexplorer.com/directx4vb/ (the DX7 tutorials), since they provide a lot of info...
Teaudirenopossum.Musasapientumfixaestinaure. (I can't hear you. There's a banana in my ear)
I've tried to fix this up, but it just isn't displaying the tiles correctly. I thorougly compared a tile engine example form the link you sent me with my code, and I can't see any difference in the DX code.
Does anyone know what's wrong here? Here's the source code again.
First of all, at this to the end of your DXLoop sub (declare rScreen As RECT at the top):
Code:
With rScreen
.Left = 0
.Top = 0
.Right = 640
.Bottom = 480
End With
BackBuffer.BltColorFill rScreen, 0
This will clear the whole backbuffer so the flickering goes away...
Also, remove the Flip from the DXLoop sub, and add it here:
Code:
Do While BRunning
DXLoop
DXBlit
Primary.Flip Nothing, DDFLIP_WAIT
DoEvents
Loop
This is because you only want to flip after everything has been drawn, the way you did it it's called before everything has been drawn...
So that removes the ugly graphics a bit, although the tiles still look messed up. I think that problem is in the calculations you are doing to get the tile's rectangle. I don't know exactly what it is though...
Also: if you try to blit a rectangle which does not fit on the screen (even for a pixel), DD won't draw it. The clipper object doesn't work in fullscreen mode, so you'll have to write your own. For example, if your tile is 50x50, and it's X and Y coordinates are 635, 100 (which is 5 pixels off the screen), set the source rectangle's right value to 50 - (640 - 635) = 45 pixels, that way DD will draw it...
Good luck!
Teaudirenopossum.Musasapientumfixaestinaure. (I can't hear you. There's a banana in my ear)
1. In the sub which initialises the surfaces, the width/height for the surface for the tiles hadn't been set to the correct dimensions of the BMP.
2. I hadn't properly enabled transparencies (hence the lack of colour).
Works now at a very nice FPS - I think I need to slow it down.
About the slowing down, don't slow down the FPS by using something like Sleep, instead, use the GetTickCount API to determine the number of milliseconds elapsed since the last frame and work out the moving speed according to that, so whatever FPS one might have, it'll always move for example 300 pixels per second...
Teaudirenopossum.Musasapientumfixaestinaure. (I can't hear you. There's a banana in my ear)