Archived

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

Typecasting DDSURFACEDESC::lpSurface?

This topic is 6389 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

More than likely it''s something I''m doing,

But something weird is happening when I use this pointer (and yes I lock the surface before I use it to draw). The Microsoft tutorial casts it to an unsigned char * (BYTE *), if I cast it to any other type it crashes my computer. By my calculations a BYTE cast should only give it a range of 511 different adresses. I set the pointer to the middle of the screen 320x240 (it''s at 640x480 resolution) and it comes up at the lower left hand of the screen (almost the middle of the third quatrant). I know the pointer gives a linear address and to get the location right you have to multiply it to DDSURFACEDESC::lPitch and add it to X.

What''s goin'' on man?!?!

Snootchie Bootchies!

-=CF=-

Share this post


Link to post
Share on other sites
Your problem is in the color resolution you have your surface set to. If you are in 640,480 256bpp mode, then there is one on byte per pixel on the screen. If you are 16bpp mode (hicolor mode)then there are two bytes (or a WORD) per pixel. so then for each pixel you would have to set your pointer to (WORD *) resolution to read one pixel. In most cases in hicolor mode, the color format for each word is 5-6-5, which means, 5 bits for red 6 bits for green and 5 bits for blue.

The same pointer notation is true for any other color mode, if you are in 32bpp color mode, then you would have to read a double word (DWORD *) for each pixel.

Share this post


Link to post
Share on other sites