D3DLOCKED_RECT texture;
alphamap->LockRect(0,&texture,NULL,D3DLOCK_DISCARD);
BYTE* pBits = (BYTE*)(texture.pBits);
for(int i=0;i<256;i++) {
for(int j=0;j<256;j++) {
pBits[j*texture.Pitch + i*4 + 2] = alphavalues[0][j];
pBits[j*texture.Pitch + i*4 + 1] = alphavalues[1][j];
pBits[j*texture.Pitch + i*4 + 0] = alphavalues[2][j];
pBits[j*texture.Pitch + i*4 + 3] = alphavalues[3][j];
}
}
alphamap->UnlockRect(0); </pre> The alphavalues array is made of BYTEs. Nothing crashes and it ends up filling all the data, but it isn't in the right place. It ends up scattered around the texture at equal intervals. What am I missing?
<SPAN CLASS=editedby>[edited by - Raloth on January 24, 2004 6:49:06 PM]</SPAN>
setting bytes in a locked texture
I've gone over this code twenty times, searched all over, and I can't find what is wrong.
for(int i=0;i<256;i++){ for(int j=0;j<256;j++) { pBits[(j * texture.Pitch + i) * 4 + 2] = alphavalues[0][j];<br> pBits[(j * texture.Pitch + i) * 4 + 1] = alphavalues[1][j];<br> pBits[(j * texture.Pitch + i) * 4 + 0] = alphavalues[2][j];<br> pBits[(j * texture.Pitch + i) * 4 + 3] = alphavalues[3][j];<br> }<br>} </pre> <br><br>Should work better, I think..<br><br>-Morten-<br>
When the texture gets uploaded to video memory it usually gets swizzled, so it better fits the texel-cache hardware. I was just wondering if the driver got it wrong doing that operation. If there''s a problem with that, though, I''d be very surprised (needs a bug doing some fancy page fault thing to mark the area of the texture you''ve just scribbled to).
-Morten-
-Morten-
Here''s a screenshot of the problem:
http://www20.brinkster.com/raloth/texturelock.jpg
It''s supposed to be all red with a 32x32 bit of yellow in the top left, but it comes out like that. Making the 32x32 bit bigger makes the dots get bigger.
http://www20.brinkster.com/raloth/texturelock.jpg
It''s supposed to be all red with a 32x32 bit of yellow in the top left, but it comes out like that. Making the 32x32 bit bigger makes the dots get bigger.
Looks like the
= alphavalues[0][j];<br>as its indicies the wrong way around..<br><br>-Morten-
= alphavalues[0][j];<br>as its indicies the wrong way around..<br><br>-Morten-
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement