Sign in to follow this  

problem with pixel and texture

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

Hello!
Create texture.
LPDIRECT3DTEXTURE9 p_Texture;
D3DXCreateTextureFromFile(using_d3d_Device,paht.c_str(),&p_Texture);
I need know where transparent pixel where not, in this texture .

Share this post


Link to post
Share on other sites
i try do this like that:

D3DLOCKED_RECT lr;
unsigned int * Mem;
GetCurrentTexture()->LockRect(0,&lr,0,0);
Mem = ((unsigned int *)(lr.pBits));
unsigned int test;
test = Mem[x_ + Max_x*y_];
D3DXCOLOR t(test);
GetCurrentTexture()->UnlockRect(0);

next i check (t.a) if if this value more than 0 that mean pixel iz not transparent.
What i do wrong????

Share this post


Link to post
Share on other sites
It depends on the surface format of the texture. With 16-bit textures (FMT_R5G6B5 or FMT_X1R5G5B5) you also have to only use a WORD pointer.

Also, do not use Max_X to calculate the line span, but use the pitch parameter you get passed back in the D3DLOCKED_RECT structure. Careful, the pitch is supplied in bytes per line, not pixel per line.

Share this post


Link to post
Share on other sites
It should look like this for D3DFMT_R8G8B8 (24bit)


D3DLOCKED_RECT lr;

unsigned char* Mem;
GetCurrentTexture()->LockRect(0,&lr,0,0);

Mem = (unsigned char*)lr.pBits;

unsigned int test;

// Getting the 3 RGB-Bytes and assemble an unsigned int
test = ( Mem[x_ + lr.Pitch * y_] << 16 )
+ ( Mem[x_ + lr.Pitch * y_ + 1] << 8 )
+ Mem[x_ + lr.Pitch * y_ + 2];

GetCurrentTexture()->UnlockRect(0);


You should check if it's another format. If the format is different, the assembling of the color parts is different.

Share this post


Link to post
Share on other sites
it's ok.
but when i do
D3DXCOLOR t(test);
wsprintf(ttt,"a=%d ",t.a);
TRACE(ttt);
wsprintf(ttt,"r=%d ",t.r);
TRACE(ttt);
wsprintf(ttt,"g=%d ",t.g);
TRACE(ttt);
wsprintf(ttt,"b=%d\n",t.b);
TRACE(ttt);

sometimes value a,r,g,b is negative
what is wrong??

Share this post


Link to post
Share on other sites

This topic is 4691 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this