Archived

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

jocke

DirectDraw surface memory

Recommended Posts

In the program i''m working on now that uses DX7 i''m locking a surface and use the following line to read a pixel from it: col = video_buffer[x + (y * ddsd.lPitch >> 1)]; The ''video_buffer'' is a USHORT because the program runs in a 16 bpp mode. The program runs fine on my computer but when i tried it on my firends computer the values returned was totally wrong. I was under the impression that by using the ''lPitch'' in the pixel calculation it would work on all memory configurations, linear and non-linear. If this is true, can someone please tell me what i''m doing wrong? Thanks

Share this post


Link to post
Share on other sites
You need to check the pixelformat. Sometimes it''s 5 bits red, 5 green and 5 blue. Sometimes it''s 5 bits red, 6 bits green and 5 blue. I haven''t seen other combinations yet, but who knows?

Share this post


Link to post
Share on other sites
So what do i do next when i have that information?

By the way, do i use GetCaps() to get that information?

Share this post


Link to post
Share on other sites
No you don''t use GetCaps to find that out you use GetPixelFormat.
Then when you have found out what the format is you have to use the correct version of color reading algorithm.

Share this post


Link to post
Share on other sites
Ok, i use this macro to build up an RBG color:

#define RGB16BIT(r,g,b) ((b%32)+((g%32)<<5)+((r%32)<<10))

I learned this from the LaMothe book "Windows Game Programming
For Dummies". In the book he assumed a 5 bit per channel pixelformat. I''m a bit slow when it comes to bit manipulation
so if someone could show me some code that builds up an RGB
color based on the pixelformat it would make me very happy to
say the least.

Thanks

Share this post


Link to post
Share on other sites