Archived

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

retry at pixel test

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

just so whoever told me it was a bad idea last time knows, this isn''t in the loading process anymore. its just in the converter. i need to make a program to load a heightmap into a direct3D texture, and then get the color of the pixel off of it one by one. store these colors in an array, and then write the red component to the file. since they are grayscale, it doesn''t matter, so which ever. so all i need is something to load a surface, and get the red component out of a (x, y) on that surface. it doesn''t matter how slow it is, its only run once. how would i do that? i think i LockRect, and then to a memcpy the length of the amount of memory a pixel takes up. its a DWORD right? how would i go about getting the red component out of this DWORD. or the alpha or green or blue if they are easier (though i don''t see why they would). can someone help me with this?

Share this post


Link to post
Share on other sites
d3d stores textures as sequential lines of Pitch bytes (see D3DLOCKED_RECT). you can make a for loop for the number of scanlines (height) in the image, then on each iteration declare a BYTE pointer and initialize it with d3dlr.pBits+d3dlr.Ptch*i, where i is the current scanline. then have another for loop for the number of pixels in the image horizontally. retrieve one byte from the pointer (that would be blue value, i believe) and advance the pointer by four bytes to the next pixel. use that value for whatever you need.

you can find some code in the sdk samples, for example in the d3dfont implementation.

---
Come to #directxdev IRC channel on AfterNET

Share this post


Link to post
Share on other sites
how do you read from a pointer? like i know how to get the x, y of the place i''m trying to read, but i can''t figure out how to get the first 8 bits out of it.

Share this post


Link to post
Share on other sites
as i said, treat it as a BYTE pointer.

BYTE *pImageData = d3dlr.pBits+d3dlr.Pitch*i;
// read one color component
BYTE ColorValue = *pImageData;
// advance four bytes=sizeof(DWORD) to the next pixel
pImageData += 4;

do that for each line.

Share this post


Link to post
Share on other sites
1st of all, why not save the heightmap as an 8-bit greyscale image instead of a (complete waste of resources) 24-bit color image that is only grey?

2nd of all, why not just read the image file into ram and do whatever you want with it? Why bother DX with creating a D3D texture resource, locking that, messing about, then destroying that?

You could save the 8-bit greyscale heightmap as a .raw file from any paint program on the planet (every one I''ve seen even allows you to specify X number of bytes to reserve as a ''header'').


_____________________________________________
Come join us on IRC in #directxdev @ irc.afternet.org

Share this post


Link to post
Share on other sites