Jump to content
  • Advertisement
Sign in to follow this  
miha_nik

problem with pixel and texture

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

Share this post


Link to post
Share on other sites
Advertisement
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!