Archived

This topic is now archived and is closed to further replies.

Qpeg

GetPixel() with DIRECT3DTEXTURE8/9

Recommended Posts

I have a texture loaded for a wrapper for D3DXSprite and would like to be able to get ARGB values for a given coordinate (x,y) in this texture (for simple collision detection in a 2D game) - any ideas on how to do this? The closest I can find is GetPrivateData() from the IDirect3DTexture8/9 interface, but there must be a simpler way? Regards, Eivind

Share this post


Link to post
Share on other sites
you have to lock the texture either with the rectangle argument to get the pixel you want, or locate it in the memory yourself, if you are doing collision detection, you should use bounding boxes first before the pixel perfect detection, and you should also store a memory copy of the sprite, as locking is slooow. bounding boxes will probably be plenty accurate.

Share this post


Link to post
Share on other sites
Well then how do you get the pixel data though? I mean, sure locking is slow according to you, but you could still lock the texture, read the data once after load time, and then use pixel-perfect collision detection checking with the data you read.

And you still didn''t really tell us how to read the data from it, like in actual code we can use.

Share this post


Link to post
Share on other sites
A little more specifics on how to get the actual pixels would be nice, yes. I haven''t gotten around to it yet, but I guess GetPrivateData() will return a 2D array of the pixels - am I right? From there you can just make your own function, something like
ARGB GetPixel(int x, int y){
Lock()
..
return privatedata[x][y];
Unlock()
}

And for the other question, if I understand you correctly, yes you could just get the data once, AS LONG as the texture doesn''t change. It often will (take the backbuffer for example).

As for my own use, I will mainly use this for coll det. for the mouse. Therefore, I don''t need to use bounding boxes.

Share this post


Link to post
Share on other sites