Sign in to follow this  
darktemplarcs

Color Key Collision Detection Help

Recommended Posts

I don't know how color collision works, but if you want to get pixel values from a texture, you simply need to call LockRect on it and get its D3DLOCKED_RECT.
Then you can access the texture bits as you would with a normal array (size increment depends on texture format, of course).

Hope this helps :)

Share this post


Link to post
Share on other sites
Let say I loaded a 640x 480 image.bmp image as texture. How would I go about getting the Color value at that pixel x y from the D3DLOCKED_RECT object? Sorry, I am very new at Window Programming, sample code would help. Thanks!

Share this post


Link to post
Share on other sites
something like this should do the trick:


D3DXCOLOR IMAGE[256 * 256]; // assumes source image is R8G8B8
D3DLOCKED_RECT pLockedRect;

if(FAILED(Texture->LockRect(0, &pLockedRect, NULL, D3DLOCK_READONLY)))
return false;
for (int y=0; y<IMAGE_SIZE; y++){
for (int x=0; x<IMAGE_SIZE; x++){
D3DXCOLOR color = *((DWORD*)(((BYTE*)pLockedRect.pBits) + pLockedRect.Pitch*y + x*sizeof(DWORD)));
IMAGE[x + y*IMAGE_SIZE] = color * 255;
}
}
Texture->UnlockRect(0);




Hope this helps :)

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
can you explain what does this mean in details.
D3DXCOLOR color = *((DWORD*)(((BYTE*)pLockedRect.pBits) + pLockedRect.Pitch*y + x*sizeof(DWORD)));

I know you convert pLockedRect.pBits to BYTEs and pLockedRect.pBits represent the texture in bits.

what does pLockedRect.Pitch*y + x*sizeof(DWORD)) do??

Share this post


Link to post
Share on other sites

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