Manipulating individual pixels on a directx back buffer?

Started by
4 comments, last by Agony 19 years, 8 months ago
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
Advertisement
Is this in the wrong forum?
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.
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.
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.
"We should have a great fewer disputes in the world if words were taken for what they are, the signs of our ideas only, and not for things themselves." - John Locke
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.
"We should have a great fewer disputes in the world if words were taken for what they are, the signs of our ideas only, and not for things themselves." - John Locke

This topic is closed to new replies.

Advertisement