×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

DX9, C# and Surface.Lock()

DX9, C# and Surface.Lock()

DX9, C# and Surface.Lock()

(OP)
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?

RE: DX9, C# and Surface.Lock()

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

RE: DX9, C# and Surface.Lock()

Sorry, I don't know C#. That was in C++. Hope it helps.

RE: DX9, C# and Surface.Lock()

(OP)
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?

RE: DX9, C# and Surface.Lock()

(OP)
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?

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close