🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Directly Accessing 24-bit surfaces in DirectDraw

Started by
2 comments, last by Nutz4Linux 24 years, 6 months ago
Hello, I would like some help directly accessing 24-bit surfaces in DirectDraw. I am trying to rotate a surface and then blit it to the backbuffer, so I need to copy all the pixels on the source surface to a new destination on the screen. I have locked both surfaces and got the DDSURFACEDESC for each surface. The source pixel is at (oldx, oldy) on the source surface, the destination pixel is at (newx, newy) on the backbuffer. I need to know what to cast the lpSurface to for copying a 24-bit surface, and I need to know if this would work in a loop:
drawSurf[newy * drawSurfInfo.lPitch + newx] = spriteSurf[oldy * spriteSurfInfo.lPitch + oldx]; 
But I don''t know what data type drawSurf and spriteSurf should be. Do I use a "UCHAR *" and copy three times per pixel to get all 24-bits? PLEASE HELP! Thanks in advance, -Jey Kottalam 14 Year Old Computer Programmer http://www.armageddongames.com
-Jey Kottalam14 Year Old Computer Programmerhttp://www.armageddongames.com
Advertisement
Hi,
normally you use 16 + 8 = 24, because it would be faster than 8 + 8 + 8 = 24. But why use 24-bit ? 32-bit would be faster, because copying 16 bits is faster than copying 8 bits now.

CU

Graphix Coding @
Skullpture Entertainment
Graphix Coding @Skullpture Entertainmenthttp://www.skullpture.de
OK, but what data type would I use for 16-bit graphics? 16-bit is probably better because it''s compatabile with more graphics cards...

-Jey Kottalam
14 Year Old Computer Programmer
http://www.armageddongames.com
-Jey Kottalam14 Year Old Computer Programmerhttp://www.armageddongames.com
I would use 16-bit if I were you. The problem with 16 bit is that you have to handle both 15 bit - xrrrrggggbbbb and 16 bit rrrrgggggbbbb; although, this is unimportant if you''re just copying pixels. You would implement copying in 16 bit mode by casting drawsurf to a WORD (short int), which is 2 bytes in length. For 32 bit you would cast to a DWORD, or just an int. For 24 bit, you would first have to cast to BYTE (uchar). The best method from that point would probably be to use memcpy. You could do something like this-

// temporary pointers for pointer arithmetic
BYTE *pDrawSurf, *pSpriteSurf;

while(...)
{
pDrawSurf = drawSurf;
pSpriteSurf = spriteSurf;
// increment the pointer to point to the
pDrawSurf += ( newy * drawSurfInfo.lPitch )+ ( newx * 3 );
// increment the pointer to point to the
pSpriteSurf += ( oldy * drawSurfInfo.lPitch )+ ( oldx * 3 );
// Copy the pixels
memcpy(pDrawSurf, pSpriteSurf, sizeof(BYTE)*3);
}

Of course, sizeof(BYTE) is 1, so you could just put
memcpy(pDrawSurf, pSpriteSurf, 3);

Hope this helps.

Brian P. Retford
www.losthorizonsoftware.com
Brian P. Retford Lost Horizon Software

This topic is closed to new replies.

Advertisement