Quantcast
Channel: beginners - openFrameworks
Viewing all articles
Browse latest Browse all 4929

Texture on ofSpherePrimitive breaks

$
0
0

@kontur wrote:

Hey,

I've been working on an iOS project where I am trying to map a texture (world map) onto a ofSpherePrimitive, but there seems to be some rendering issue.

While I can get the texture to be mapped onto the sphere, there seems to be parts of the sphere where the texture in the foreground does not render properly but instead it appears "transparent" and renders the far-side of the sphere, the texture inside out. Below two images to illustrate the point.

First, here with a red light illuminating the front/top and colouring the texture correctly, whereas on the bottom part of the sphere there are those unlit texture parts from inside the sphere's other side.

Second, here a minimum test case with no lights, cameras, etc, just a checkered pattern. You can see the smaller checkers from the backside in the bottom half of the sphere. Note, that it is not exclusively in the bottom, but as the sphere rotates, also parts of the top half show the same problem.

For the second example, the relevant code is:

void ofApp::setup(){
    r = 0;
    sphere.setRadius(100);
    texture.loadImage("test.png");
}

//--------------------------------------------------------------
void ofApp::update(){
    r += 0.25;
}

//--------------------------------------------------------------
void ofApp::draw(){
    ofPushMatrix();
    
    ofTranslate(ofGetWidth() / 2, ofGetHeight() / 2);
    ofRotateY(r);
    
    texture.getTextureReference().bind();
    sphere.draw();
    
    texture.unbind();
	
    ofPopMatrix();
}

Noteworthy is that while the sphere is rotating the "transparent" parts rotate with the sphere.

You can also check out the whole code of the second example here: https://github.com/kontur/openframeworks-ios-sphere-texturing-problem

Both texture images are powers of two, the world map image being 1024x1024 and the checker pattern being 512x512 pixels.

I am pretty sure this is some minor problem somehow to do with setting a flag to render the sphere solid, but as a beginner I have not made any progress with this no matter what I have tried so far.

Any ideas?

Posts: 7

Participants: 3

Read full topic


Viewing all articles
Browse latest Browse all 4929

Trending Articles