Results 1 to 26 of 26

Thread: GetLockedArray I am BEGGING YOU to show me how to do this...

  1. #1

    Thread Starter
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134

    GetLockedArray I am BEGGING YOU to show me how to do this...

    Does anyone have a GOOD tutorial on GetLockedArray, it keeps lockin' up on my system.
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  2. #2
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    Microsoft MVP : Visual Developer - Visual Basic [2004-2005]

  3. #3

    Thread Starter
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    The ancient code one helped a lot .
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  4. #4
    Frenzied Member Jotaf98's Avatar
    Join Date
    Jun 2000
    Location
    I'm not gonna give you my IP address! Ok... Portugal, South-Western Europe, 3rd rock from the sun (our star is easy to find, a 47 Ursae Majoris in the Milky Way :p )
    Posts
    1,457
    Hey, I managed to make it so it didn't lock up when you get an error. Here's the code:

    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
    Hope that helps
    I used this code for my game's special effects
    Code:
    Temp = Me.GetIQ()
    'Error 9: Overflow
    'DON'T PANIC! :eek:

    To learn how to use realistic effects in your games like fire, rain, snow and magic effects, read my article on particles systems here.


    Jotaf's Theories!
    "Cats land on their feet. Toast lands peanut butter side down. A cat with toast strapped to its back will hover above the ground in a state of quantum indecision."

  5. #5

    Thread Starter
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    Seems to work like a charm, thanks.
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  6. #6
    Frenzied Member Jotaf98's Avatar
    Join Date
    Jun 2000
    Location
    I'm not gonna give you my IP address! Ok... Portugal, South-Western Europe, 3rd rock from the sun (our star is easy to find, a 47 Ursae Majoris in the Milky Way :p )
    Posts
    1,457
    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
    Code:
    Temp = Me.GetIQ()
    'Error 9: Overflow
    'DON'T PANIC! :eek:

    To learn how to use realistic effects in your games like fire, rain, snow and magic effects, read my article on particles systems here.


    Jotaf's Theories!
    "Cats land on their feet. Toast lands peanut butter side down. A cat with toast strapped to its back will hover above the ground in a state of quantum indecision."

  7. #7
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    Whats this bolloxology do anyway ?
    Microsoft MVP : Visual Developer - Visual Basic [2004-2005]

  8. #8
    Frenzied Member Jotaf98's Avatar
    Join Date
    Jun 2000
    Location
    I'm not gonna give you my IP address! Ok... Portugal, South-Western Europe, 3rd rock from the sun (our star is easy to find, a 47 Ursae Majoris in the Milky Way :p )
    Posts
    1,457
    It lets you have an image in an array. DIRECT MEMORY ACCESS!!!

    You can manipulate images with just arrays instead of slow things like Get/SetPixel functions. It's much faster, even in VB
    Code:
    Temp = Me.GetIQ()
    'Error 9: Overflow
    'DON'T PANIC! :eek:

    To learn how to use realistic effects in your games like fire, rain, snow and magic effects, read my article on particles systems here.


    Jotaf's Theories!
    "Cats land on their feet. Toast lands peanut butter side down. A cat with toast strapped to its back will hover above the ground in a state of quantum indecision."

  9. #9
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    Jotaf ; *cough*more special effects*cough*

    Possibly someone will be implimenting this soon ?
    Microsoft MVP : Visual Developer - Visual Basic [2004-2005]

  10. #10
    Frenzied Member Jotaf98's Avatar
    Join Date
    Jun 2000
    Location
    I'm not gonna give you my IP address! Ok... Portugal, South-Western Europe, 3rd rock from the sun (our star is easy to find, a 47 Ursae Majoris in the Milky Way :p )
    Posts
    1,457
    Hey look here, I posted a demo on how to make lights:

    http://forums.vb-world.net/showthrea...&postid=403362
    Code:
    Temp = Me.GetIQ()
    'Error 9: Overflow
    'DON'T PANIC! :eek:

    To learn how to use realistic effects in your games like fire, rain, snow and magic effects, read my article on particles systems here.


    Jotaf's Theories!
    "Cats land on their feet. Toast lands peanut butter side down. A cat with toast strapped to its back will hover above the ground in a state of quantum indecision."

  11. #11
    Frenzied Member Jotaf98's Avatar
    Join Date
    Jun 2000
    Location
    I'm not gonna give you my IP address! Ok... Portugal, South-Western Europe, 3rd rock from the sun (our star is easy to find, a 47 Ursae Majoris in the Milky Way :p )
    Posts
    1,457
    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 )

    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.
    Code:
    Temp = Me.GetIQ()
    'Error 9: Overflow
    'DON'T PANIC! :eek:

    To learn how to use realistic effects in your games like fire, rain, snow and magic effects, read my article on particles systems here.


    Jotaf's Theories!
    "Cats land on their feet. Toast lands peanut butter side down. A cat with toast strapped to its back will hover above the ground in a state of quantum indecision."

  12. #12
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    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....
    Microsoft MVP : Visual Developer - Visual Basic [2004-2005]

  13. #13
    Member Stef's Avatar
    Join Date
    May 2001
    Posts
    41
    Hmmm... any ideas on how to do this in directx8?

  14. #14

    Thread Starter
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    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)
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  15. #15
    Frenzied Member Jotaf98's Avatar
    Join Date
    Jun 2000
    Location
    I'm not gonna give you my IP address! Ok... Portugal, South-Western Europe, 3rd rock from the sun (our star is easy to find, a 47 Ursae Majoris in the Milky Way :p )
    Posts
    1,457
    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

    [edit]

    Well that's tipicaly me... forgot to post the link

    Here it is:

    http://www.vbforums.com/showthread.p...6&goto=newpost

    [/edit]
    Last edited by Jotaf98; Jun 24th, 2001 at 06:26 AM.
    Code:
    Temp = Me.GetIQ()
    'Error 9: Overflow
    'DON'T PANIC! :eek:

    To learn how to use realistic effects in your games like fire, rain, snow and magic effects, read my article on particles systems here.


    Jotaf's Theories!
    "Cats land on their feet. Toast lands peanut butter side down. A cat with toast strapped to its back will hover above the ground in a state of quantum indecision."

  16. #16
    Member Stef's Avatar
    Join Date
    May 2001
    Posts
    41
    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.

  17. #17
    Frenzied Member Jotaf98's Avatar
    Join Date
    Jun 2000
    Location
    I'm not gonna give you my IP address! Ok... Portugal, South-Western Europe, 3rd rock from the sun (our star is easy to find, a 47 Ursae Majoris in the Milky Way :p )
    Posts
    1,457
    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
    Code:
    Temp = Me.GetIQ()
    'Error 9: Overflow
    'DON'T PANIC! :eek:

    To learn how to use realistic effects in your games like fire, rain, snow and magic effects, read my article on particles systems here.


    Jotaf's Theories!
    "Cats land on their feet. Toast lands peanut butter side down. A cat with toast strapped to its back will hover above the ground in a state of quantum indecision."

  18. #18
    Member Stef's Avatar
    Join Date
    May 2001
    Posts
    41

    Question

    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)

  19. #19

    Thread Starter
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134

    Wow, this thread is old =)

    Try VarPtr:

    VB Code:
    1. Dim A() As Byte
    2.    A = VarPtr(d3dl_r.pBits)

    I'm not sure if this will work.
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  20. #20
    Frenzied Member Jotaf98's Avatar
    Join Date
    Jun 2000
    Location
    I'm not gonna give you my IP address! Ok... Portugal, South-Western Europe, 3rd rock from the sun (our star is easy to find, a 47 Ursae Majoris in the Milky Way :p )
    Posts
    1,457
    (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)
    Code:
    Temp = Me.GetIQ()
    'Error 9: Overflow
    'DON'T PANIC! :eek:

    To learn how to use realistic effects in your games like fire, rain, snow and magic effects, read my article on particles systems here.


    Jotaf's Theories!
    "Cats land on their feet. Toast lands peanut butter side down. A cat with toast strapped to its back will hover above the ground in a state of quantum indecision."

  21. #21
    Addicted Member Janus's Avatar
    Join Date
    Aug 2001
    Location
    California
    Posts
    221

    I wrote a C++ DLL that...

    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
    "1 4m 4 1337 #4xz0r!'
    Janus

  22. #22
    Frenzied Member Jotaf98's Avatar
    Join Date
    Jun 2000
    Location
    I'm not gonna give you my IP address! Ok... Portugal, South-Western Europe, 3rd rock from the sun (our star is easy to find, a 47 Ursae Majoris in the Milky Way :p )
    Posts
    1,457
    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?
    Code:
    Temp = Me.GetIQ()
    'Error 9: Overflow
    'DON'T PANIC! :eek:

    To learn how to use realistic effects in your games like fire, rain, snow and magic effects, read my article on particles systems here.


    Jotaf's Theories!
    "Cats land on their feet. Toast lands peanut butter side down. A cat with toast strapped to its back will hover above the ground in a state of quantum indecision."

  23. #23
    Addicted Member Janus's Avatar
    Join Date
    Aug 2001
    Location
    California
    Posts
    221

    Well, yes...

    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++.
    "1 4m 4 1337 #4xz0r!'
    Janus

  24. #24
    Frenzied Member Jotaf98's Avatar
    Join Date
    Jun 2000
    Location
    I'm not gonna give you my IP address! Ok... Portugal, South-Western Europe, 3rd rock from the sun (our star is easy to find, a 47 Ursae Majoris in the Milky Way :p )
    Posts
    1,457
    AHHH!

    That means calling CopyMemory thousands of times! Better use Get/SetPixel

    Besides, I think an average computer with 64mb of ram can handle a 300kb image
    Code:
    Temp = Me.GetIQ()
    'Error 9: Overflow
    'DON'T PANIC! :eek:

    To learn how to use realistic effects in your games like fire, rain, snow and magic effects, read my article on particles systems here.


    Jotaf's Theories!
    "Cats land on their feet. Toast lands peanut butter side down. A cat with toast strapped to its back will hover above the ground in a state of quantum indecision."

  25. #25
    Addicted Member Janus's Avatar
    Join Date
    Aug 2001
    Location
    California
    Posts
    221

    No...

    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.
    "1 4m 4 1337 #4xz0r!'
    Janus

  26. #26
    Frenzied Member Jotaf98's Avatar
    Join Date
    Jun 2000
    Location
    I'm not gonna give you my IP address! Ok... Portugal, South-Western Europe, 3rd rock from the sun (our star is easy to find, a 47 Ursae Majoris in the Milky Way :p )
    Posts
    1,457
    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
    Code:
    Temp = Me.GetIQ()
    'Error 9: Overflow
    'DON'T PANIC! :eek:

    To learn how to use realistic effects in your games like fire, rain, snow and magic effects, read my article on particles systems here.


    Jotaf's Theories!
    "Cats land on their feet. Toast lands peanut butter side down. A cat with toast strapped to its back will hover above the ground in a state of quantum indecision."

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width