Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DX9, C# and Surface.Lock()

Status
Not open for further replies.

Akusei

Programmer
Jul 15, 2003
90
US
Using DirectX 9 and c#, I'm trying to lock a surface so I can manipulate each pixel on the screen.

Surface.Lock() in c# returns a byte[,] (a multidemensional array). Assuming that the array represents the x,y coordinates of the screen I did a little test with my screen set to 800x600 and 8 bit color (8 bit because I can't figure out how to cast byte[,] to int[,]). When I do an incremental fill on the array with different colors, I see that bytearray[320,200] does not equate to the pixel located at 320,200! However, this is what I am lead to believe is true... Any idea why this is not so?

Further explanation:
bytearray[0,0] does equal the upper left of the screen, however bytearray[1,0] equals about a quarter of the way to the right on the x axis!

Does anyone have any suggestions?

 
Use the pitch property of yer surface to determine the correct pixel location in membuff.

Like this:

buff[YCoord*pitch + XCoord]

NOTE: pitch is not equals with surface width, see the SDK

Unborn
 
That's all fine an everything, however, in an 8 bit environment the pitch is always equal to the width. Further more, I don't know how to cast a byte[,] (multidemensional array) to a byte[] (single demensional array)... Unfortunately byte[,] is all Surface.Lock() returns.

Any suggestions?

 
Ok, I've figured out a portion of the problem.

#1: I was trying to use Managed DirectX with C# (this is still very new and does not have good documentation).

New problem...

Now I'm using regular DX9 with C++ (none of that managed crap). There is a strange change from DX8 to 9 which makes it so that you cannot create an image surface and copy it or a portion of it to a destination surface.

I create an Offscreen Surface of type D3DPOOL_SCRATCH (because it fails if I use D3DPOOL_SYSTEMMEM). I modify that surface using LockRect. I then use GetBackBuffer() to retreive the devices backbuffer. Then I use UpdateSurface() to "copy" a portion of my offscreen surface to the backbuffer (I believe the backbuffer is of type D3DPOOL_DEFAULT).

The problem with this is that the UpdateSurface() documentation states that the source surface must be of type D3DPOOL_SYSTEMMEM. I can't create an offscreen surface of that type because it fails, and I can't copy the offscreen surface I can create because it's of the wrong type.

Any ideas about this?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top