Hi,
I’m trying to map 2d Textures to distorted 3d spheres drawn using ofMesh, but it didn’t work so this is a more stripped down version using a cylindrical shape. some segments draw the shape properly but others don’t. I’m not sure if it’s to do with some depth issue. I can’t seem to upload images which is not helpful but if anyone could help that would be greatly appreciated.
Also if anyone has any ideas as to why mapping the sphere also does not work that would be appreciated.
//.h file
ofImage image;
ofSpherePrimitive sphere;
ofMesh mesh;
// cpp file
void ofApp::setup(){
image.loadImage("moon.jpg");
sphere.set(200, 20);
sphere.setPosition(0, 0, 0);
mesh.clear();
mesh.setMode(OF_PRIMITIVE_TRIANGLES);
int numJ = 6;
int numI = 10;
float r = 100;
for (int i = 0; i < numI; i++) {
for (int j = 0; j < numJ; j++) {
double theta = 360*i/numI;
theta = ofDegToRad(theta);
double x = r * sin(theta);
// int x = r*i;
int y = j*100;
double z = r * cos(theta);
mesh.addVertex(ofVec3f(x,y,z));
mesh.addTexCoord(ofVec2f(x,y));
}
}
for (int i = 0; i < numI-1; i++) {
for (int j = 0; j < numJ-1; j++) {
int n = i * numJ + j;
mesh.addIndex(n); mesh.addIndex(n+numJ);
mesh.addIndex(n+1);
mesh.addIndex(n+numJ);
mesh.addIndex(n+1); mesh.addIndex(n+numJ+1);
}
}
ofEnableDepthTest();
ofDisableAlphaBlending();
ofEnableArbTex();
}
indent preformatted text by 4 spaces
void ofApp::draw(){
ofTranslate(300, 0);
ofRotateY(50*ofGetElapsedTimef());
ofBackground(0);
glPointSize(5);
image.getTextureReference().bind();
//mesh.drawWireframe();
//mesh.drawVertices();
mesh.draw();
image.unbind();
//image.draw(0,0);
}