Does anyone have a GOOD tutorial on GetLockedArray, it keeps lockin' up on my system.
Printable View
Does anyone have a GOOD tutorial on GetLockedArray, it keeps lockin' up on my system.
I've not the faintest what it does, but these might help :
http://rookscape.com/vbgaming/tutAS.html
http://www.crosswinds.net/~ancientcode/Tut_DD_Mem.html
I got it from :
http://www.google.com/search?q=GetLockedArray
The ancient code one helped a lot ;).
Hey, I managed to make it so it didn't lock up when you get an error. Here's the code:
Hope that helps ;)Code:
'Get an array from each of the surfaces
Dim EmptyRect As RECT
Dim SrcArray() As Byte, DestArray() As Byte
SourceSurface.Lock EmptyRect, SourceDescription, DDLOCK_NOSYSLOCK Or DDLOCK_WAIT, 0
SourceSurface.GetLockedArray SrcArray()
DestSurface.Lock EmptyRect, DestDescription, DDLOCK_NOSYSLOCK Or DDLOCK_WAIT, 0
DestSurface.GetLockedArray DestArray()
'Edit them here :p
'ALWAYS remember to unlock the surfaces!
ErrHandler:
'Unlock the surfaces (IMPORTANT)
SourceSurface.Unlock EmptyRect
DestSurface.Unlock EmptyRect
I used this code for my game's special effects :)
Seems to work like a charm, thanks.
Yeah I know, I had been looking for that for a long time 'til I figured it out. It wasn't that hard after all.
The best of all is that it doesn't crash your computer, even if your game is full-screen :) This is good for debugging, you don't have to constantly reset your computer ;)
Whats this bolloxology do anyway ?
It lets you have an image in an array. DIRECT MEMORY ACCESS!!! :p
You can manipulate images with just arrays instead of slow things like Get/SetPixel functions. It's much faster, even in VB :)
Jotaf ; *cough*more special effects*cough*
Possibly someone will be implimenting this soon :) ?
Hey look here, I posted a demo on how to make lights:
http://forums.vb-world.net/showthrea...&postid=403362
I also made a very fast DX module with more than 20 effects, but I haven't released it yet because I'm trying to make a C++ DLL so it's faster :)
(Still it works fast enough with big images in my PII 833Mhz :p )
Ok, I'll post it here when I get home - but maybe I'll make it a VB DLL instead of a module because I've heard it's 230% faster.
Well If you want it performance tested, I'm running a P-III 650MHz w/128Mb Ram and an S3 Savage IX w/8MB VRam on Windows 98SE....
Hmmm... any ideas on how to do this in directx8?
You can't; no ddraw in DX8. DDRAW has disappeared. So you must use DX7 (dont worry DX7's Visual Basic DLL (Dx7vb.DLL) can still be used)
Ok, here's the DLL so you can all do your "performance test" :)
Please post your comments and what FPS did you get in that thread... and note that it was done in pure VB, so it's not THAT fast :p
[edit]
Well that's tipicaly me... forgot to post the link :o
Here it is:
http://www.vbforums.com/showthread.p...6&goto=newpost
[/edit]
I think it IS possible to do this in DX8, I have found a LockRect method which you can use on textures and surfaces, the problem is I can't find the GetLockedArray, so I guess there must be some other way to manipulate the bitmap in memory. Are there any tutorials on how to do this?
The LockRect function returns a D3DLOCKED_RECT variable, which consists of two Long vars:
Type D3DLOCKED_RECT
pBits As Long
Pitch As Long
End Type
pBits - The locked bits. If a RECT was provided to the LockRect call, pBits will be appropriately offset from the start of the surface.
Pitch - Pitch of surface, in bytes
However, pBits is NOT an array, and I have no idea what it is (besides a large number:))
If anyone knows more about this, please let me know.
Stef, that Long is just a pointer to a C++ array. But you'll need someone that knows more about CopyMemory() API in order to use it :D
So pBits is a pointer to the start of the C array? Is Pitch the length of it (in bytes)? If not, how do I get the length? Any code examples?
Code:Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, _
Source As Any, ByVal Length As Long)
Try VarPtr:
VB Code:
Dim A() As Byte A = VarPtr(d3dl_r.pBits)
I'm not sure if this will work.
(D*mn, it's the 3rd time I try to write this reply :( )
Try UR's site, http://www.ur.co.nz/ (direct memory access)
The value of pBits is the index of the beginning of the array.
Simply convert CopyMemory's Source to ByVal Source As Long, and then pass pBits to it. To access each byte of the array, increment pBits by the Pitch.
Calculating array location from X,Y:
Location = pBits + (X * Pitch) + (Y * (Width * Pitch))
Good Luck
So, the code would look something like this:
-Create a dynamic array
-Redim it to (Pitch, Height)
-Use the "new version" of CopyMemory to copy pBits to your array
-Modify the array as you want
-Copy it again to the structure
Is that right? :)
Yes, you could do that...
Or you could use CopyMemory to copy the individual pixels back and forth from a long variable, thus saving RAM. :) I use the RAM-saving method because it works for any bit depth and is simple, even in C++.
AHHH! :eek:
That means calling CopyMemory thousands of times! Better use Get/SetPixel :D
Besides, I think an average computer with 64mb of ram can handle a 300kb image :p
I've done lots of tests, the overhead involved in creating a copy of the array, and then copying back, etc, is immense compared to modifying pixel-by-pixel. the cpu can cache if you do it a few pixels at a time.
Hum... ok... but in my opinion a big loop with lots of copymemory's is slower than a single loop to copy the memory in assembler or whatever they used to make copymemory :)