Hey, I did just that recently and it’s quite simple. You don’t need FBOs or VBOs or anything (actually I think the 3ds lib that ofx3DSLoader wraps internally uses VBOs, but that doesn’t matter).
This assumes that your 3d model already has embedded UV coordinates exported from 3d software.
Now there is a problem, actually a generic problem in openGL / OF / textures. 3ds stores the UV coordinates as 0…1 (which makes sense, because you don’t want your texture mapping to change depending on the resolution of texture you use!). But by default OF stores your texture as a GL_TEXTURE_RECTANGLE_ARB which uses UV coordinates as (0…width, 0…height). So as of OF006 you can call ofDisableArbTex() to disable GL_TEXTURE_RECTANGLE_ARB and stick with GL_TEXTURE_2D. So now your texture coordinates are 0…1, problem solved? nope
Even though GL_TEXTURE_2D does make the UV coordinates 0…1, it also puts your texture in the closest power of 2 texture. E.g. a 1280x720 video will be placed inside a 2048 x 1024 texture. So all the 0…1 texture coordinates get messed up. E.g. when your 3D model says ‘this vertex has UV (1, 0.5)’ you’d expect it to be the right-most column of your texture, and halfway down your texture. But actually you get something completely different because of all the padding!. I.e. the rightmost column of the padded texture, and halfway down the padded texture.
So there are two solutions.
a simple hack, just call ofDisableArbTex() before loading your video, and hack ofTexture to remove all instances of ofNextPow2();
A better solution (which I hope will make it into OF someday) is to scale all UV coordinates to the range of 0…1 no matter if they are RECT textures, or non-square textures which have been placed inside larger textures. In the code below hasTex is a pointer to an ofBaseHasTexture (so it could be an ofImage, ofVideoPlayer, ofVideoGrabber etc.)
I got the video onto the model ok.
So I’m trying to change ofTexture.cpp as you mentioned on option 2. How should I declare hasTex on the .h file?
As for mixing some more OF graphics, such as live video blended the the video player, is there a way? I could already bind alright a video grabber, but it replaces the video player.
That’s where I thought the FBO could come in handy.
Hi Alexandre, actually the second option doesn’t involve a hack to ofTexture at all, it works externally. So those bind() and unbind() methods would be in your testApp or texture manager class:
the idea is, you’ll be able to call ofEnableNormalizedTexCoords(), then when you bind() a texture, you are garanteed that all UV coordinates for that texture will be 0…1 even if using TEXTURE_RECT or non-pow2 TEXTURE_2D placed inside a larger pow2 texture.
until those mods are in the core, you can just use the code pasted above.
and yes, if you did want to mix videos or videoGrabber etc then the best thing to do is render them all to an FBO with the blending modes you want, then do the same to the FBO instead of myVideo when binding and unbinding.
Sounds like Quase-Cinema is gaining some awesome new features!