View Full Version : Extract color from texture coordinate
09-16-2003, 10:11 AM
I have a 3d model and a texture displayed on top of that model.
For each point in my model I know its texture coordinate.
How is it possible from a texture coordinate to get the RGBA value ? (because I need to know for each point of my model its color for some processing)
09-16-2003, 10:25 AM
Texture coordinates are linearly interpolated across a tringle.
In case you use a perspective view you have to add a perspective correction which depends on your field of view.
09-16-2003, 10:31 AM
Sorry I don't see the relation with my question..
Maybe I should re-formulate:
For each vertex of my model I have a texture coordinate. How can I get the RGBA color of the texture at that particular texture coordinate ? is there an openGL function that can do that (but I failed to find it in the red book) ?
09-16-2003, 10:48 AM
Ok, texture coordinates are (usally) normalized between zero and one.
Given a texture of 256x256 the following is true:
-texture coordinate 0.0, 0.0 is the texel 0,0 in the texture.
-texture coordinate 1.0, 1.0 is the texel 256, 256.
-texture coordinate 0.5, 0.5 is the texel 128, 128.
texelX = texturesizeX * texturecoordinateX
texelY = texturesizeY * texturecoordinateY
You will then find the color inside your texture at texelX, texelY
If the texture coordinates are greater then one, it means the texture is repeated so you have to modulo it back to zero to one.
Edit: fixed some typo's
[This message has been edited by 1234! (edited 09-16-2003).]
Powered by vBulletin® Version 4.2.3 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.