Sign in to follow this  

Getting a texel value

This topic is 4765 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

Hi; I have a textured terrain, and i wanna know the current color at a given position, to put a particle system there with the ground color....how do i get it?

Share this post


Link to post
Share on other sites
Do you want to read a color from a texture (a texel) or a color from the screen ? I'm guessing it's the second option so you have to use glReadPixels or you could trace a ray, intersect it with the terrain and compute the color manually if you have the texture image in system RAM.

Share this post


Link to post
Share on other sites
I wanna read the color from a texture, but its not in system RAM...i read that old games like counter strike reads the lightmap value to modulate the diffuse color that hits a character...i wanna do something like that, but to modulate the particle color...if the player is over a green area, the dust in his foot should be green....and so on...

Share this post


Link to post
Share on other sites
Ok, this is what i can think of:

Get the player's position and project it onto the terrain. Transform and project this point with the current matrices to get screen coordinates. Use glReadPixels to read the color.

The problem is that for a player who is behind a hill, he might be lit even if he is in a shadow if the hill is lit on the front side, but i don't think it would be a big problem.

You could try to get the projected point and its polygon and manually interpolate the texture coordinates to find its texture coord. Now render this texture onscreen before rendering of the terrain occurs to a quad in 2D. use glCopyTexSubImage2D to copy the pixels at the resulting texcoord to a small 1x1 or 3x3 texture which you can get using glGetTexImage. (all this is needed so you don't pass read back big texture on the bus).

Share this post


Link to post
Share on other sites

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

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