Jump to content
  • Advertisement

Archived

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

octavsoft

need help with locking dd surf

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

When I lock a dd surface, how can I get to pixel (x,y)?? Let''s say that I lock rectangle rc, and in ddsd I have the surface description. What''s the formula to get to the memory for pixel (x,y), relative to the upper-left corner of rc. The bpp is 16bits. I tried: *(WORD*)((BYTE*)ddsd.lpSurface+y*ddsd.lPitch+x*2) but i get something weird. Please help me, someone. Octavian E-mail: octav@octavsoft.com Webpage: http://www.octavsoft.com

Share this post


Link to post
Share on other sites
Advertisement
Try this ...

  

WORD *pixbuffer = (WORD *)ddsd.lpSurface

pixbuffer[x+y*ddsd.lPitch];



This is all assuming that you locked the surface with the proper perameters such as DDLOCK_SURFACEMEMORYPTR in the flags when you lock the surface...

Also note that x and y are the co-ordinates on the screen - I hope this helps ...

Sincerely,

Destroyer

===============================
In a world without boundaries -
Who needs gates or windows ?
=============================== [/source]

Edited by - Destroyer on June 25, 2001 4:30:02 PM

Share this post


Link to post
Share on other sites
In 16bpp mode if you are going to cast the buffer to a word* you will need to divide the pitch by 2. If you are going to cast to a byte* you need to mult x by 2:

WORD *pixbuffer = (WORD *)ddsd.lpSurface;
pixbuffer += (x + (y * (ddsd.lpitch/2)));
*pixbuffer = color;

or

BYTE *pixbuffer = (BYTE *)ddsd.lpSurface;
pixbuffer += ((x*2) + (y * ddsd.lpitch));
*pixbuffer = color;

Lots of room for optimization here, but you get the picture.

Share this post


Link to post
Share on other sites
I figured it out in the end. Aldacron is right, because each pixel is 2 bytes (1 word) in 16 bpp. he pitch is always in bytes, so the width has to be multiplied with 2 or the oder way around. The fastest one would be:
*( (WORD*) ( (BYTE*) surf + y * ddsd1.lPitch ) + x )
cause there is no divide or multiplication.

Octavian
E-mail: octav@octavsoft.com
Webpage: http://www.octavsoft.com

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!