Jump to content
  • Advertisement
Sign in to follow this  
Coluna

Getting a texel value

This topic is 4980 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
Advertisement
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
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!