Sign in to follow this  
jakussano

How can convert a texture pixel coordonate to screen coordonate?

Recommended Posts

Hello ! I render images with directx (sprite and textures).I am using c++. I know how to acces texture memory byte by byte. This is what i want to do: For each pixel in image A: { Find the screen coordinate occupied by this pixel Find the pixel in image B that is also rendered to this position If both pixels are non-transparent { COLLISION! } } Can anyone tell me how to find the screen coordinate (=position x) ocuppied by the pixel from image a? And then (if you know) find the pixel in image B that is also rendered to position of x?

Share this post


Link to post
Share on other sites
I'm taking a wild guess here - You're trying to do per-pixel collisions in 2D. The way you're proposing might not be the best solution taken the fact that reading from the back-buffer (which I take it you're talking about) is very slow since it requieres synchronization between the CPU and GPU for it to read back the data.

What you could do was to check the two textures (byte by byte as you call it) before writing the pixel to the screen. You have to check based on their screen position and utilizing thier bounding boxes. There's a neat little article here - Mind you it's in XNA, but I bet you can handle it.

http://www.ziggyware.com/readarticle.php?article_id=48

Share this post


Link to post
Share on other sites
No it wouldn't work for rotated sprites since all you're doing is to compare the bounding boxes. If you need something that works on rotated sprite I figure you would have to transform the sprites back into untransformed space before doing the compare (read: unrotate the sprite back to the normal upright position).

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