ofCamera and inverted texture mapped image
Hi, arturo asked me to open an issue about this here.
original forum post : https://forum.openframeworks.cc/t/ofcamera-and-inverted-texture-mapped-image/26398
I figured out the texture mapped image looks inverted when I use ofCamera.
As you can see the American continent is inverted.

It works correctly when I call ofCamera::setVFlip(true); But Is this natural to see the image inverted when VFlip is set to false?
Here's a test code below. I used ofEasyCam.
void ofApp::setup(){
ofEnableDepthTest();
ofDisableArbTex();
img.load("earth.jpg");
mesh = ofMesh::sphere(300,300);
}
void ofApp::draw(){
cam.begin();
img.bind();
mesh.draw();
img.unbind();
cam.end();
}
And Here's a link to the test image [http://paulbourke.net/geometry/transformationprojection/earth.jpg]
Hi, I was facing a similar issue where the U coordinate of the texture is flipped. Below is my solution in hopes that it helps someone in the same situation.
The solution of flipping the camera did not solve the issue I had. Doing that changed the winding order of the mesh and flipped the view upside down. I also tried the solution of changing the winding order by scaling ( ofScale(1,1,-1) ) that's posted on the forum, and again, it altered the mesh in a way I did not want since I use back face culling.
What I needed to do was alter all the U coordinates of every mesh as I loaded the model. Here is my load function that flips the U coordinate without altering the camera or mesh.
bool ScreenPreview::loadModel(const std::string path) {
if (!model_.loadModel(path)) {
ofLogError("[ScreenPreview::loadModel]") << "Failed to load screen preview model from: " + path;
return false;
}
model_.setNormalizationFactor(1.0f);
model_.calculateDimensions();
glm::vec3 modelPosition = model_.getPosition() + model_.getSceneCenter();
model_.setPosition(modelPosition.x, modelPosition.y, modelPosition.z);
// Most models have an inverted U coordinate, here we flip it so that it's rendered properly
for (size_t i = 0; i < model_.getMeshCount(); i++) {
auto& mesh = model_.getMesh(i);
auto& helper = model_.getMeshHelper(i);
auto newCoords = mesh.getTexCoords();
for (size_t i = 0; i < newCoords.size(); i++) {
newCoords.at(i).x = 1.0f - newCoords.at(i).x;
}
mesh.clearTexCoords();
mesh.addTexCoords(newCoords);
helper.vbo.updateTexCoordData(mesh.getTexCoordsPointer(), mesh.getNumTexCoords());
}
return true;
}