Texture data from uv

How to get texture info from uv ?
not from pixel , i want ot get texture info from uv.

do you mean querying the ofTextureData of an ofTexture?
Not sure what you mean by info from uv?

If i have 4 point mesh and add color , how can i get color by uv?

Hey I’ll try to be of some help.

If you have an ofImage or ofPixels, you can get the color of a pixel with .getColor() and the x and y coordinates (uv in this case). If you draw the ofMesh to an ofFbo, you can call ofTexture::readToPixels() to get the pixels for its texture. This might be a good method if you need all of the colors at the same time, and/or with each frame.

You can also calculate the color at “uv” from the 4 mesh colors using functions from ofMath, like ofLerp, ofMap, etc, or by using some of the glm functions, like glm::mix(). This might be a good method if you don’t need all the colors, and/or don’t need them that often.

I don’t think there is a way to get a color for “uv” directly from a framebuffer, at least without first rendering it to something that your oF application can access.

Dear TimChi

Thank you helping.
I thought getColor could get data from int pixel position. could not get data from uctexturecoord.
I’ve attached image just has 4 points. So i want to know how get color data from uvcoordinate.

But you mean getColor() could access like getCOlor(0.3,0.5) ?

The pixel position of .getColor() is the pixel coordinates in an ofImage or an ofPixels object, which is a cpu-side representation. This is not the same as the uv or texcoord in a fragment shader or the rendering pipeline of openGL, which is on the gpu side. Some of these topics are covered in ofBook, especially the ones under the Graphics heading: ofBook - Introducing OpenGL for OF and maybe ofBook - Introducing Shaders

Also, there is a version of .getColor() that takes an int as an argument and returns a color at that index position.

I don’t know openGL that well, or If there are any openGL calls that return values (like a vec3) to a calling function or to the oF application, either with a shader or without. I’m thinking not, but I could be wrong.

To use .getColor(), you have to get the pixels back from the openGL rendering pipeline so you can access them in oF. An easy way to do this is to draw something (the ofMesh say) into an ofFbo, which has an ofTexture (basically pixels on the gpu). So a general outline for doing this might be:

// probably in ofApp.h
ofFbo fbo;
ofMesh mesh;
ofColor color;

// set up the mesh and allocate the fbo in ofApp::setup();
// then draw the mesh into the fbo in ofApp::update()
mesh.drawFaces(); // or maybe mesh.draw()

// then get some ofPixels from the ofTexture in the fbo ,
// and get the color at an index from the ofPixels
int index = 100;
ofPixels pixels;
color = pixels.getColor(index);
// or get a color with an xy coordinate
color = pixels.getColor(0.3 * fbo.getWidth(), 0.5 * fbo.getHeight());