Archived

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

Arek the Absolute

To rephrase that DDraw Buffer question...

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