How to normalize texture coordinates of ofMesh?

Running into some issues when attempting to draw an ofMesh in an FBO that has been initialized to use 2D texture coordinates…

In the documentation for ofMesh::addTexCoord it says:

Add a Vec2f representing the texture coordinate. Because OF uses ARB textures these are in pixels rather than 0-1 normalized coordinates.

So my question is, quite simply, is there a way to use 0-1 normalized coordinates with ofMesh? Or alternatively, is there a way to convert ofMesh’s texture coordinates to use a 0-1 normalized coordinate?

Thanks!

Sam

The problem is not with ofMesh but with the textures, you can tell OF to use 2D textures instead of rectangular by calling:

ofDisableArbTex()

As the first thing in setup before initializing any textures

Hey @arturo ,
Really appreciate the response! I should have specified - I have already called ofDisableArbText() this at the start of my setup. The function is called before I instantiate any of my textures. However, it seems that when I draw my mesh (which is having its UV’s updated via the addTexCoor method) into an Fbo (that has been initialized with the GL_2D_TEXTURE ) I’m getting coordinate normalization issues.

So are you suggesting that the ofMesh (if ofDisableArbText() was called at the start) will use normalized coordinates? and will be compatible to draw inside fbos that have normalized coordinates?

Thanks a lot!!
Sam

ofDisableArbTex() is quite confusing, we have to document it better as there have been many questions in the forum regarding this function. We could describe what this function does on this page http://openframeworks.cc/ofBook/chapters/textures.html, instead of just put a link to the forum.

Maybe a short intro about texture coordinates and a description of the 2 different results using ofDisableArbTex() and not using it?

Yes that would be really helpful, also perhaps a comment about it in the ofTexture class docs

ok i think i can explain this again more simply:

why wouuld adding “ofDisableArbTex()” at the start of the vboExample startup() method break the example?

It seems to suggest that the ofMesh.addTexCoords method is not compatible with normalized coordinate system?

the coordinates the example is adding to the mesh are in pixels not normalized coordinates. if you want to use 2d textures with that example then you’ll need to normalize the coordinates before adding them to the mesh, as in mapping them from the size of the texture to the 0…1 range.

so if the example would be using a 640x480 texture you would need to divide the x in every tex coordinate by 640 and the y by 480

1 Like

Amazing. I spent so many hours on this. Makes perfect sense now!

Thank you :slight_smile: