Getting a texel value

Started by
4 comments, last by Coluna 19 years, 4 months ago
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?
Advertisement
glReadPixels(..) perhaps , its not 100% clear what u wanna do
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.
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...
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).
Ok, its a solution....i think is not the fastest way, but it should work...see ya

This topic is closed to new replies.

Advertisement