Share this post

Link to post

Share on other sites

Thanks mate, I can see pixels change now.
can you please explain these lines to me?
;lines;
[code[color="#1C2837"][font="CourierNew, monospace"][color="#000000"] RGBA [color="#666600"]*[color="#000000"]dest [color="#666600"]= [color="#666600"]([color="#000000"]RGBA[color="#666600"]*)([color="#000000"]backBuffer [color="#666600"]+[color="#000000"] row [color="#666600"]*[color="#000000"] lockedRect[color="#666600"].[color="#660066"]Pitch[color="#666600"]);[/font]
[font="CourierNew, monospace"] RGBA [color="#666600"]*[color="#000000"]src [color="#666600"]= [color="#666600"]([color="#000000"]badger [color="#666600"]+[color="#000000"] row [color="#666600"]*[color="#000000"] SCREEN_WIDTH[color="#666600"]);[/font]]
If I get it right, the pitch is the pointer to the number of bytes in a row of pixels, but I don't quite understand what the arithmatics in these line yield.

0

Share this post

Link to post

Share on other sites

RGBA *dest = (RGBA*)(backBuffer + row * lockedRect.Pitch);backBuffer is a char pointer to the start of the back-buffer memory, top left corner first pixel.row is the row-number, where the top row is 0 and the bottom is SCREEN_HEIGHT-1.Pitch is the number of bytes per row.

row * Pitch = the number of bytes from the start of the back-buffer to the start of the row with number 'row'
Since backBuffer is a char-pointer and char size = 1 byte, adding to it yields a pointer exactly that many bytes from the start. So dest is the start of the row we currently want to fill in the back-buffer.

RGBA *src = (badger + row * SCREEN_WIDTH);badger is the start of the source image, and it's type is a pointer to an RGBA which is 4 bytes in size (32-bit color)
The source memory is always SCREEN_WIDTH * 4 bytes per row. However, since badger is an RGBA pointer each addition is in RGBA units (4 bytes), so badger + row * SCREEN_WIDTH is the start of the source row to copy into the back-buffer.

The memcpy simply copies the whole row (memcpy takes the number of 1-byte units to copy).

0

Share this post

Link to post

Share on other sites

haven't been home for a while, and read the reply.
now I have only got one windows-oriented question, am I getting the HBITMAP the wrong way?
HBITMAP hbm;
hbm = CreateCompatibleBitmap(DDC,SCREEN_WIDTH,SCREEN_HEIGHT);

because using stretchBlt with DDC, I get an actual desktop pic, but while trying to memcpy the pixels by the method above, they all turn black.(even when the d3d-device's clear color, or the window's brush color isn't black- it just repeats 0,0,0,0 (A,R,G,B) for all pixels).
Think I might be getting the hbm wrong.