|
Author Topic:   Backbuffer DIB surface description
Bwuce Wee
Member
posted November 08, 1999 07:23 AM            
Backbuffer has given me a great boost in learning C++ and graphics/games.
But some of the things I've been struggling with.

The DIB surface description for instance.
In the code, you set a pixel with :

p = ((unsigned char*)bd.data + ypos * bd.pitch + (xpos) % (bd.width - 4) + 2);
for(x = -1; x < 2; x++){
p[x - bd.pitch] = 250;
p[x] = 250;
p[x + bd.pitch] = 250;
}

or something like that, where xpos and ypos are the pixel positions.
(Or so I assumed).

Thats where my problems come in.
If I set a pixel at (200,200) and another in a different colour at (201,200), the second pixel OVERLAPS the first one.
What does the pitch property mean, what is it used for?
Does that have something to do with it?

Please help me out here... I'm learning so well so far.

------------------
--------------
Light? I haven't even found the tunnel!!

IP:

Zpeed
New Member
posted November 10, 1999 08:04 PM            
I think its the width of your window.
800x600: pitch=800.
Is that right Seumas?

------------------
-=The Zpeed of Light=-

IP:

LDA Seumas
unregistered
posted November 10, 1999 10:30 PM           
The pitch is the number of bytes to progress from the start of one line in the buffer to get to the start of the next line down. With an 8-bit buffer with a width that is an even multiple of 4, the pitch is _likely_ to be the width, but there is no guarantee, and the pitch will be different than the width for high-color or true-color buffers. Pitch may even be negative, if the line "below" is actually stored at an earlier memory location in the frame buffer. So you should never assume pitch to be a specific value or a specific sign.

The only time plotting a pixel should "overlap" the pixel to its left is if you're using a 16-bit buffer and mistakenly went only 1 byte to the right instead of 2. With 16-bit buffers you need to multiply the X component by 2 (but not the Y, as the pitch takes care of that!), and with 32-bit buffers, multiply X by 4. You can do this quickly with (x<<1) for 16-bit and (x<<2) for 32-bit.

------------------
-- Seumas McNally, Lead Programmer, Longbow Digital Arts

IP:

Bwuce Wee
Member
posted November 11, 1999 03:22 AM            
Ah ic.
Thanx guys.

So that bit of code I pasted is really making a 3x3 block, not a pixel?

It think I solved my problem, now that I understand the code

Now I can finish this little game

------------------
--------------
Light? I haven't even found the tunnel!!

IP:

LDA Seumas
unregistered
posted November 11, 1999 07:26 PM           
Right, it actually writes 9 pixels.

Subtracting bd.pitch from the address moves it up a line, and adding bd.pitch moves it down a line. The for loop covers three columns horizontally.

------------------
-- Seumas McNally, Lead Programmer, Longbow Digital Arts

IP: