Binding texture to ofMesh on iOS

hi,

When binding a texture to an ofMesh, the texture coordinates are normalized on iOS, whereas they are not on osx.

Here is the code i ended up with to draw correctly on iOS and osx.

    for (int i=0;i<mesh.getNumVertices();i++) {
#if !defined(TARGET_OF_IOS)
        mesh.addTexCoord(mesh.getVertex(i));
#else
        mesh.addTexCoord(ofPoint(mesh.getVertex(i).x / 128.,
                                 mesh.getVertex(i).y / 128.));
#endif
        }

Other quads, including font.getStringMesh(), do not need such tricks.

Would this be a bug, or am I missing something?

Thanks, piem

Hi,

Before loading the image/texture you could use ofDisableArbTex() to turn off rectangle textures, the texture would then use normalized texture coordinates and you could use the same code for iOS and OSX.

to add to this answer, there are basically two types of textures:

GL_TEXTURE_2D
GL_TEXTURE_RECTANGLE_ARB (in later opengl called GL_TEXTURE_RECTANGLE)

2d textures have look up via floating point coordinates (ie, 0-1) and have to be in sizes of power of two, rectangle textures can be arbitrarily sized but have coordinates in pixels.

https://www.opengl.org/wiki/Rectangle_Texture

in OF we try to default to GL_TEXTURE_RECTANGLE_ARB on desktop, since it’s easier to not have to pad textures – for example, you have a movie which is 640x480… it’s easier if we can just make a texture that is that size, vs a larger one (which would be powers of two sized) where we upload a portion of the image.

ofDisableArbTex() as @hahakid mentions, forces desktop to use GL_TEXTURE_2D – which is only what openGL ES / ios will use.

also, it’s worth noting that we have convenience functions in OF textures for getting the right coordinate data:

getCoordFromPercent(…)
getCoordFromPoint(…)

this will give you a coordinate for the given texture that should work across platforms, either based on the pct through the image or the pixel coordinate. I find it very handy to use these functions since it doesn’t matter what the texture type is. You do have to be careful when using shaders however since there’s different commands for GL_TEXTURE_2D vs GL_TEXTURE_RECTANGLE_ARB textures.

hope that helps

Thank you both, that did help!

best, piem