Jump to content
  • Advertisement


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


Pixel Plotting in DirectDraw 7

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

I am trying to write a simple function that fills a surface a certain color (the Back-Buffer surface). I am working in 16-bit 565 mode (i have checked this many times) and when I try to fill the surface using my function R:240, G:240, B:240 (a light grey colour), it fills it GREEN!. I don''t think it is anything to do with pitch because whilst testing this function, I divided the pitch of the surface (bytes) by the width of the surface (pixels) and it returned 2 hence 2-Bytes per pixel (1x16-Bit Word per pixel). I would be very grateful if someone could have a look at the following code to see if I have made any errors. Thanks, Spider907. // Screen Filling Code: // iHeight : Height of Surface // iWidth : Width of Surface // lpMem : Pointer to Locked Surface Memory for (UINT y = 0; y < iHeight; y++) { for (UINT x = 0; x < iWidth; x++) { ((WORD*)lpMem)[(y*iWidth)+x] = GraphicsMem_Get565Word(240,240,240); }; }; // GraphicsMem_Get565Word(r, g, b) Macro: #define GraphicsMem_Get565Word(r, g, b) (WORD) ((r << 11) | (g << 5) | (b))

Share this post

Link to post
Share on other sites
I think the problem is in this line of code:

((WORD*)lpMem)[(y*iWidth)+x] = GraphicsMem_Get565Word(240,240,240);

I'll assume that lpMem is a BYTE pointer that you what to convert to a word pointer to plot a pixel. But from what you say is happenning it sounds like only part of the pixel is making it to the surface.

Try this:

*(WORD *)&lpMem[(y*iWidth)+x] = GraphicsMem_Get565Word(240,240,240);

this is how i think it works:

1. &lpMem[(y*iWidth)+x]; returns the correct address
2. (Word *); then casts the pointer to the correct type
3. *; finally puts a value in the address

Good Luck!!

i see how your addressing works now. it should be ok then. (feeling dumb)

if you want to convert 24 bit color to 16 bit color 565 format:
GraphicsMem_Get565Word(r,g,b) (WORD)((r>>3)<<11)|((g>>2)<<5)|(b>>3);

[edited by - CodeJunkie on November 5, 2002 12:13:22 AM]

Share this post

Link to post
Share on other sites
Your GraphicsMem_Get565Word macro is incorrect. You have 24 bits of information (1 byte for each of Red, Green, and Blue) and you''re fitting them into 16 bits of pixel space without removing the extra 8 bits at any stage. The result you''ll see is that your blue component is having an effect on the green component. Try drawing all the bitwise operations out on paper to see what you''ve done wrong.

[ MSVC Fixes | STL | SDL | Game AI | Sockets | C++ Faq Lite | Boost | Asking Questions | Organising code files | My stuff ]

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!