Sign in to follow this  
dave

Manipulating individual pixels on a directx back buffer?

Recommended Posts

dave    2187
I REALLY would like to know how to do this. You could draw a quad 1-pixel by 1-pixel but the render spead would be stupidly slow if u filled the screen. All i really want to do is litereally alter individual pixel colour values. Can it be done? regards ace

Share this post


Link to post
Share on other sites
twix    636
Use that Lock function. It returns a pointer to the buffer; I'm sure you can figure it out from there. [smile]

Also you have to remember that each row in the buffer is typically padded by some unused bytes at the end, so its size is not width x height, but 'pitch' x height. You can get the pitch from a surface description structure, I think.

Share this post


Link to post
Share on other sites
Dmytry    1151
edit: same as in post above ^^^^^^^^.

it's wrong forum...

I somehow did it once for my programs but don't remember how exactly... iirc i locked the screen using some function that also returns a pointer to image data.
Google must help.

Share this post


Link to post
Share on other sites
Agony    3452
I haven't tried this with the backbuffer, so I don't know if it will allow it, but it works with normal surfaces, so here's my guess:

Use the function IDirect3DDevice9::GetBackBuffer() to get a pointer to the IDirect3DSurface9 object that is the back buffer.

Use the function IDirect3DSurface9::LockRect() to get a pointer to the pixel data of the surface, along with the pitch.

You can now just do whatever to the pixels. The data is a 1-dimensional array. Each row is pitch bits long, so the nth row starts at byte index (n - 1) * pitch. If the size of the pixel multiplied by the width is less than the pitch, then the extra bytes are padding, as mentioned.

Call IDirect3DSurface9::UnlockRect() when done altering pixels, and then Release() the surface.

Share this post


Link to post
Share on other sites
Agony    3452
Another thought. I don't know which is optimal (or if the above is even allowed), but you might consider making a dynamic texture, and then performing the LockRect() on that texture. Then all you need to do is draw 1 quad, and you've avoided having to mess with the back buffer altogether, which might be preferable.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this