Jump to content
  • Advertisement


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

Arek the Absolute

To rephrase that DDraw Buffer question...

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

Thanks anyway, but I''ll be more specific this time. Just for reference, I''m using a 640x480x16 mode. Is there a faster way I can read a pixel from a buffer? (In this case the back buffer) Here''s what I''m doing so far: lpddsback->Lock(NULL,&ddsd,DDLOCK_SURFACEMEMORYPTR | DDLOCK_WAIT,NULL); USHORT *back_buffer = (USHORT *)ddsd.lpSurface; for (int y = 390; y < 475; y++){ for (int x = 10; x < 630; x++){ USHORT pixel = back_buffer[x + (y*ddsd.lPitch >> 1)]; /* here is where I''d do whatever to that info, like drop the red from it, or whatever seemed necessary */ } } lpddsback->Unlock(NULL); Unfortunately, the part that seems to take the most time is reading the pixel from the buffer. Either that, or its simply because I do it so many times per frame. Heh. If the problem''s because of how I''m reading the pixel, is there a faster way I can do it? Is there some way I can optimize it that''s just eluding me? And if the problem simply stems from the repititions, is there something I can do to avoid it? Can I just edit one big chunk of the buffer without the for loops? As you may or may not have noticed, I don''t intend to use this on the whole screen, just portions of it. Is there something I can do to take advantage of that? Any advice would, as always, be greatly appreciated.

Share this post

Link to post
Share on other sites
Arek -

I see one way to speed this up:

Get rid of the for () loops and use while/wend or some other looping, using (until y<475) etc.. I know this works well in VB, getting rid of the loops

Locking/unlocking to read pixels is slow, maybe there is a better way to do this, I am assuming this is for collision detection? Perhaps you could bitblt the selection of screen to a memory buffer for faster acccess and avoid locking/unlocking?

Also, can some of the math be precalculated and thrown into a table?

Edited by - drarem on October 22, 2001 11:38:28 PM

Share this post

Link to post
Share on other sites
If it is pixel perfect collisions you are after, there are loads of articles on these forums that''ll expalin how to do it efficiently - just use the search facilty.

The general feeling is that it''s not really worth it but you can use tricks like a 2 colour mask of your graphic and / or load the data into a look up table in the inialisation phase

Like I say use the search and all should be revealed.

PS - I appologise now if you are after this for some other reason

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!