problem with pixel and texture
Hello!
A questions!
Applying texture to poligon
I have a problem with recognition is the pixel under cursor transparent or not.
Plaase tell how to get this data.
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 .
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 .
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????
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????
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.
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.
It should look like this for D3DFMT_R8G8B8 (24bit)
You should check if it's another format. If the format is different, the assembling of the color parts is different.
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 inttest = ( 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.
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??
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??
A D3DXCOLOR carries the rgb values as float. You're using %d, which is reserved for ints.
For printf type formatting you need to use %f for floats/doubles.
For printf type formatting you need to use %f for floats/doubles.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement