This topic is now archived and is closed to further replies.

Locking surfaces in DX7

This topic is 6079 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

What should I do, if I want to lock an offscreen surface, write some color values on it and disaply the result on the primary surface (NOT FULLSCREEN) (32bit) I have already done most of this, but I''m having problems with lock. I don''t exactly know how to write some color values on the offscreen surface. I calculated the memory address where the color should go like this: ((LPDWORD)((LPBYTE)lpsurface + (y * lpitch) + x)) = color; But that formula does''nt seem to work, if all colors are 0x00000000 only a small left part of the image is white and the other part is full of strange colors. I need a right formula to pu the colors on the image, and a formula to make a DWORD color value from r, g and b colors.

Share this post

Link to post
Share on other sites
Your formula is almost right, but you are only adding one byte for x instead of 4, so you are overwritiing the same pixels. Its a little easier to read as:

pitch = surfacePitch / sizeof (DWORD);
LPDWORD buffer = (LPDWORD) pLock;
buffer [x + y * pitch] = color;

at any rate, 0x00000000 is black, not white! its also transparent because of the alpha. white is 0xFFFFFFFF ARGB. In ARGB format, the bytes are AARRGGBB in hex. Use this macro SDK macro for your ARGB colors, if you don't want to just do it manually:

D3DCOLOR_ARGB(a,r,g,b) ((D3DCOLOR)((((a)&0xff)<<24)|(((r)&0xff)<<16)|(((g)&0xff)<<8)|((b)&0xff)))

Also clear the surface first, so you know that the pixels you see are from your draw function and not some garbage that was in memory when direct x grabbed it.

Edited by - invective on April 24, 2001 4:50:50 AM

Share this post

Link to post
Share on other sites