Search code examples
opengllwjgl

What is the best way to apply a Framebuffer texture to a particular face of a model?


I've currently got a scene rendering using OpenGL / LWJGL which creates a texture from some rendering to a FrameBuffer, and then renders that texture to a generated quad - all working nicely.

My question is what would be the best way to instead apply this generated texture to a face of a model that I've imported?

  • This model would already have UV's generated for another texture that applies to the remaining faces of the model, but I'm not clear on how I could separately apply the FBO texture to one face.
  • The face would be rectangular and the FBO texture should simply fit to the face the same as if it was filling a separate quad - so in theory the mapping should be straightforward, if I understood how to do it.

An alternative idea is to still render to a separate quad and try and position this quad relative to the model slightly above the desired face, but this seems super awkward to position correctly and involves extra work should the model change.


Solution

  • Your question is overstated. The fact that the texture's data happens to come from a previous rendering operation to an FBO is utterly irrelevant. Your question is "how do I use a particular texture with a particular face?"

    At the end of the day, you have one option: render multiple meshes. One draws the faces that use one texture, and the other draws the faces that use the second texture. It's simply a matter of separating out which faces go to which texture.

    If you're using some externally loaded model, then the model has to be built in pieces, with each piece being used with a different texture.