Link to home
Start Free TrialLog in
Avatar of glover110697
glover110697Flag for United States of America

asked on

How do i access surface memory using DirectDraw 9?

I need an example of how to access the R,G, B, and A pixels in a surface after locking the surface. I need to be able to read and write them as quickly as possible.

I have tried
surfaceOld.Lock(LockFlags.Wait)

I have also tried
Dim Pic As LockedData = surfaceOld.Lock(LockFlags.Wait)

but I do not know how to get the data from it.  I can get the following INFORMATION but it does not seem to be of any use:
       
        'Dim A As String = Pic.ToString()
        'Dim B As String = Pic.Height.ToString
        'Dim C As String = Pic.Pitch.ToString
        'Dim D As String = Pic.RGBBitCount.ToString
        'Dim E As String = Pic.Width.ToString

If I could get a 1-dimensional array of bytes, I know how to use pitch to get to a new scan line.
I also need to know how to find the pixelformat so I can manipulate the colors.

Thanks,
Ray
Avatar of toddhd
toddhd

You might luck out and get a answer here, but I think you'd get better ones if you asked an admin to move the question here:
/Programming/Game_Development/Game_Graphics/DirectX/
Avatar of glover110697

ASKER

Thank you for your help.
I have asked in Community Support that the question be moved as you advised.
DirectDraw has been deprecated.  If you really want to use is, there is, I believe, a Data field that is the graphics stream.  Have you looked at the deprecated DX9 DirectDraw docs on the msdn.microsoft.com website?  That's my reference I always go back to...

I'm not positive what is being exposed to VB these days, but with C++ if you have a IDirect3DSurface9 object, you can use the LockRect method to lock the surface and UnlockRect to unlock it.

LockRect returns a D3DLOCKED_RECT structure, which contains the pitch, and the pointer to the data bits.  Which is more like the old-style DirectDraw Lock let you do.

They're hiding DirectDraw functions away under D3D bit by bit, then finding people need them more accessible so they 'bubble up' to the top again...

Let me know if you need more of a 'push' than that.

-d
I have checked the deprecated docs for DirectDraw.  They do not give any information other than that it has been deprecated.  Using VS Visual Basic I tried to find out what methods are available for a surface. LocKRectangle is not one of them.  There is a .Lock but it seems to return something called a "GraphicsStream".  I do not know how to use a GraphicsStream to access the bytes that make up each pixel, then get them back onto the surface.

I do not know how to do 2D using Direct3D.  I have tried isome experiments but it was extremely slow.  I would really like to use DirectDraw.

Thanks,
Ray
The GraphicsStream class should have a simple Read method that returns a bytestream.  That should be easy.  Did you try looking at it in VS to find the methods available?

DirectDraw was basically phased out almost two years ago, and is 'dying off'.  "DirectX Graphics" is the merging of DDraw and D3D into one interface.

Also, are you running the latest DX SDK (I think it's the Feb 05 update)?  The newer versions may have more (or less!) functionality...

LockRect is the method off the IDirect3DSurface9 object, so if you are trying to access via a different type of surface, that'd be why you didn't find it.  Unfortunately, LockRect with DXG gives the closest thing to old DX7 or earlier surface locks.

-d
I am running October 2004 SDK.
Referrig back to my earlier code snippet:

Dim Pic As LockedData = surfaceOld.Lock(LockFlags.Wait)

It tells me that Pic.Data is a GraphicsStream.

How can I:
Get the data from it into a byte array
Modify the byte array (I know I need pitch and pixelformat)
Put the data back to the surface so I can flip it to the primary.

I do not understand GraphicsStream or bytestream enough to know how to manupulate them.
ASKER CERTIFIED SOLUTION
Avatar of davebytes
davebytes
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks for your help.  I guess that I will just have to experiment with it until I find out how to use the GraphicsStream.

Ray