problem with pixel and texture

Started by
8 comments, last by miha_nik 19 years, 2 months ago
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.
Advertisement
can you give some more information? like what you're trying to do exactly?
"It's better to regret something you've done than to regret something you haven't done."
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 .
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????
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.

Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>

i use .png 24.
how can i Pitch and don't use Max_x?
Tell me pls. I noob in this! )
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 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.

Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>

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??
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.

Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>

ok,THX!

This topic is closed to new replies.

Advertisement