Resize non-planar object to texture

I have a project where I’m splitting an ofVideoGrabber into a grid of ofTextures, and then I project each one of these onto a corresponding ofPlanePrimitive, so that when placed side-by-side, the planes reveal the full video. To get this to work I used plane.resizeToTexture(...) for each plane/texture, and then do something like:

for (int i = 0; i < GRID_SIZE; ++i) {
  for (int j = 0; j < GRID_SIZE; ++j) {

and it works perfectly.

I’d like to do a similar thing but with ofSpherePrimitives or with ofIcoSpherePrimitives, but it doesn’t seem either of them have a resizeToTexture method. When I try it on them I get a “blurry” image, as it seems the scale of the texture binding is all off.
I can replicate this same issue with the planes if I remove the call to resizeToTexture.

Is there a way to get this working with the spheres?


Hi @psc-g,
Have you added texcoords to the ofMesh of the ofSpherePrimitives? Try adding/setting texcoords if you haven’t; each vertex needs a texcoord that describes where it maps to a texture. You could try the .setTexCoordsFromTexture() method of the of3dPrimitive class, or you can get the ofMesh for each sphere and add texcoords with .addTexCoord(). If you have a std::vector of points (glm::vec2 or similar), you can add them all at once with .addTexCoords().

You can change the resolution of the ofSpherePrimitives if it helps, so that the texture width and height is some multiple of the resolution. For instance, if your texture is 100x100, using a resolution of 5, 10, 20, 25, 50, 100 will allow the texture to map to the sphere without distorting the last face of each row in the sphere.

I’m thinking the ofIcoSphere is the same, but you may have to work out the mapping from the texture to the triangles of the icosphere.

I’m pretty sure that all of the classes for the 3d primitive shapes inherit from the of3dPrimitive class, so you can use all of those methods. And then each 3d primitive shape has an ofMesh inside of it, so you can use all of those methods too.