#### Archived

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

This topic is 5778 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I have a windowed DX app. The window is 640x480 with a backbuffer of 640x480 When I lock the backbuffer, I get a pitch of 0xA00(2560) My desktop res is 1280x1024 1280*2 = 2560 I am writing data to the backbuffer. So far I have not gotten the data to look right yet. Knowing the pitch, what is the right way(equation) to write data to a 640x480 backbuffer, one X scanline, then the neat scanline on the Y? Thanks

##### Share on other sites
The pitch is the number of BYTES (not pixels) in each line of the screen. Often, lpitch is the number of pixels horisontally * the number of bytes for each pixel, but not always, it can be a larger number too. From what you're saying, i'd guess you're running in 16-bit color, right? (1280*2=2560)

If you want to write a pixel to a certain location on a 16-bit screen, you do:

USHORT screenPointer;

screenPointer[y*(pitch/2)+x] = color;

Note that I divide pitch with 2, because in 16-bit mode, every pixel is 2 bytes.

Hope that helps

/John

[edited by - FunkyTune on January 21, 2003 6:23:25 AM]

##### Share on other sites
Umm... actually I think he''s running under 32 bit color with a width of 640? (: good luck (; 4 bytes per pixel in the 640 x 480 window.

##### Share on other sites
Ooops, I forgot to says me desktop is 32-bit.

quote:

screenPointer[y*(pitch/2)+x] = color;

Note that I divide pitch with 2, because in 16-bit mode, every pixel is 2 bytes.

So i should divide by 4 as every pixel is 4 bytes in 32-bit mode.

Thanks.

1. 1
Rutin
36
2. 2
3. 3
4. 4
5. 5

• 12
• 14
• 9
• 9
• 14
• ### Forum Statistics

• Total Topics
633346
• Total Posts
3011442
• ### Who's Online (See full list)

There are no registered users currently online

×