Skip to main content
GameDev.net gamedev.net
🔒 Locked

Locking surfaces in DX7

Started by athlon Apr 23, 2001 at 3:19 PM 1 replies 600+ views
Original Post
athlon
athlon
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.
athlon
athlon
Sorry about this doublepost!!
invective
invective
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

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.