Archived

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

setting bytes in a locked texture

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

Recommended Posts

I've gone over this code twenty times, searched all over, and I can't find what is wrong.
	D3DLOCKED_RECT texture;
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][ i ][j];
pBits[j*texture.Pitch + i*4 + 1] = alphavalues[1][ i ][j];
pBits[j*texture.Pitch + i*4 + 0] = alphavalues[2][ i ][j];
pBits[j*texture.Pitch + i*4 + 3] = alphavalues[3][ i ][j];
}
}
alphamap->UnlockRect(0);  
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? [edited by - Raloth on January 24, 2004 6:49:06 PM]

Share on other sites
for(int i=0;i<256;i++){	for(int j=0;j<256;j++)	{		pBits[(j * texture.Pitch + i) * 4 + 2] = alphavalues[0][ i ][j];		pBits[(j * texture.Pitch + i) * 4 + 1] = alphavalues[1][ i ][j];		pBits[(j * texture.Pitch + i) * 4 + 0] = alphavalues[2][ i ][j];		pBits[(j * texture.Pitch + i) * 4 + 3] = alphavalues[3][ i ][j];	}}

Should work better, I think..

-Morten-

Share on other sites
crashes

[edited by - Raloth on January 24, 2004 8:21:53 PM]

Share on other sites
What format is the texture?

-Morten-

Share on other sites
d3ddevice->CreateTexture(256,256,1,0,D3DFMT_A8R8G8B8,D3DPOOL_MANAGED,&alphamap,NULL);

Share on other sites
Does it look like a swizzle-pattern?
(I can''t see anything wrong with it either..)

-Morten-

swizzle-pattern?

Share on other sites
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-

Share on other sites
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.

Share on other sites
Looks like the
= alphavalues[0][ i ][j];
as its indicies the wrong way around..

-Morten-

• 16
• 9
• 13
• 41
• 15