• Advertisement

Archived

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

Direct Access to Backbuffer in D3D8

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

Hi! Lately I''ve been trying to get direct access to the backbuffer, and it hasn''t been working. Here''s how I tried it:
  
// Globals

LPDIRECT3DSURFACE8 lpd3ds;
int *iBuffer;
D3DLOCKED_RECT LockRect;

// COnstants

#define _RGB32BIT(a,r,g,b) ((b) + ((g) << 8) + ((r) << 16) + ((a) << 24))

//In my init code

lp3dd->GetBackBuffer(0, D3DBACKBUFFER_TYPE_MONO, &lpd3ds);
LockRect.Pitch = 3200;
LockRect.pBits = &iBuffer;

//In my Render loop

lpd3ds->LockRect(&LockRect, NULL, NULL);
iBuffer[x+(y*LockRect.Pitch >> 3)] = _RGB32BIT(255, 255, 100, 255);
lpd3ds->UnlockRect();

  
I suspect that my problem is the pitch. How do you get the pitch of the backbuffer? I just guessed that it was 3200, because I''m using 800X600X32 Am I on the completely wrong track? -Forcas
"Elvis is alive. He is Barney the purple dinosaur. He is the pied piper that leads our children into the wages of sin and eternal damnation."

Share this post


Link to post
Share on other sites
Advertisement
Whoa, don''t know how you got that pitch, but that probably is your problem. The pitch should be 800 * 600 * 4 (32-bit equals 4 bytes) which equals 1920000.

Hope that helps

Share this post


Link to post
Share on other sites
Whoa.... I guess that''d be the problem. I thought the pitch just described one line, so I did 800X4. I''ll try it out. Thanks.

-Forcas


"Elvis is alive. He is Barney the purple dinosaur. He is the pied piper that leads our children into the wages of sin and eternal damnation."



Share this post


Link to post
Share on other sites
Ummm.... nope. Still doesn''t work.

-Forcas


"Elvis is alive. He is Barney the purple dinosaur. He is the pied piper that leads our children into the wages of sin and eternal damnation."



Share this post


Link to post
Share on other sites
You should link the buffer to LockRect.pBits after locking the surface, not before it.
After locking the surface, the pitch will be filled to LockRect.Pitch automatically, so don''t worry about it.

GetBackBuffer( ...... );
lpd3ds->LockRect( &LockRect, NULL, 0 );
DWORD* dwBuffer = (DWORD*)LockRect.pBits;
dwBuffer[x+(y*LockRect.Pitch>>3)] = _RGB32BIT(255,255,100,255);
lpd3ds->UnlockRect();

hope this piece of code helps

Share this post


Link to post
Share on other sites
The program still won''t run. It shuts down as soon as it gets to this line:

dwBuffer[x+(y*LockRect.Pitch>>3)] = _RGB32BIT(255,255,100,255);

What could be wrong? I''ve tried putting it inside beginscene and endscene, and outside(that''s where I think it''s supposed to go).

Well... either way, it doesn''t work. Any idea what could be wrong?

-Forcas


"Elvis is alive. He is Barney the purple dinosaur. He is the pied piper that leads our children into the wages of sin and eternal damnation."



Share this post


Link to post
Share on other sites
How are you initializing your D3DPRESENTPARAMETERS ?

Make sure you have the D16_LOCKABLE or whatever that is....or else yuo can''t have access to the back buffer....


dankydoo

Share this post


Link to post
Share on other sites
I wonder about your line

dwBuffer[x+(y*LockRect.Pitch>>3)] = _RGB32BIT(255,255,100,255);


As one Pixel is 4 Bytes your index "x+(y*LockRect.Pitch>>3)" doesn''t seem logical to me. To get the correct line you should imo use y*LockRect.Pitch and to get the right x-value you should use 4*x. So after all I would write:


dwBuffer[4*x+y*LockRect.Pitch] = _RGB32BIT(255,255,100,255);


Could you tell me why you were using your version of that line, as I can''t figure out for what reason you wrote (y*LockRect.Pitch>>3), especially the >>3

Don''t hang me, it''s just a guess

Share this post


Link to post
Share on other sites
Guest Anonymous Poster

The pitch is equal to the number of bytes in one line. BinaryMagus is wrong.

But generally you can''t just assume the pitch is equal to 800x4, you have to query the surface for it''s pitch, as the card manufacturer may make the pitch something else.

For example, on my card, the pitch of an 800x600x32bit surface is 3584, not 3200. That is 3584 bytes per line.

Share this post


Link to post
Share on other sites
Awroight! I got it workin''! Thanks to everyone who replied... especially yangwaiwai and dankydoo! Your posts were the keys. Right after I set the present parameters flag member, evrything fell in to place. Thanks.

-Forcas


"Elvis is alive. He is Barney the purple dinosaur. He is the pied piper that leads our children into the wages of sin and eternal damnation."



Share this post


Link to post
Share on other sites
Mithrandir.... your way works, but it''s like sixty times slower than my way. I''m quite sure how my way works....I''d probably figure it out if I thought about it.... but anyway, it works.

-Forcas


"Elvis is alive. He is Barney the purple dinosaur. He is the pied piper that leads our children into the wages of sin and eternal damnation."



Share this post


Link to post
Share on other sites

  • Advertisement