setAlphaMask not working on Android

Hi! I’m trying to mask live video. It works fine on Desktop, but on Android it ignores the mask. It looks like this:

// setup
ofSetCircleResolution(5);
mask.allocate(ofGetWidth(), ofGetHeight(), GL_RGBA); // an fbo
mask.begin();
ofClear(0, 0, 0, 0);
ofSetColor(255);
ofDrawCircle(111, 111, 100);
mask.end();

// draw
vidGrabber.getTexture().setAlphaMask(mask.getTexture());
vidGrabber.draw(0, 0, ofGetWidth(), ofGetHeight());
mask.draw(0, 0, ofGetWidth()/2, ofGetHeight()/2); // show mask for debugging

No masking on Android:

Masking on Desktop:

ofEnableAlphaBlending() doesn’t help. Any ideas?

can you try using openGL ES 2?

With ES 2 only the background color is visible, no images or shapes:

int main(){
  ofGLESWindowSettings settings;
  settings.setGLESVersion(2);
  ofCreateWindow(settings);
  return ofRunApp( new ofApp() );
}

With both ES1 and ES2 I see many lines like these, not sure if related:

10-20 16:43:56.905 292-14726/? E/mm-camera: invalid stats mask. Return back
10-20 16:43:56.914 14604-14629/? E/ofTexture: Cannot set alpha mask with different texture target
10-20 16:43:56.915 14604-14629/? I/Adreno-ES20: <validate_vertex_attrib_state:59>: validate_vertex_attrib_state: No vertex attrib is enabled in a draw call!
10-20 16:43:56.916 14604-14629/? I/Adreno-ES20: <validate_vertex_attrib_state:59>: validate_vertex_attrib_state: No vertex attrib is enabled in a draw call!
10-20 16:43:56.917 292-14726/? E/mm-camera: q3a_port_send_event_downstream: AEC event handler returned failure!

Calling ofDisableArbTex() made no difference.

Is there a nightly for Android? … Ha, found it at http://ci.openframeworks.cc/versions/nightly/ It’s not listed in the downloads page. But they are all from July 14th… many nights ago!? :slight_smile:

so the problem i think is that video in android uses a specific type of texture and the alpha mask implementation in OF works only with textures of the same target- it might be that disabling that check works for android, Can you try to change, ofTexture line 844:

	if(mask.texData.textureTarget!=this->texData.textureTarget){
		ofLogError("ofTexture") << "Cannot set alpha mask with different texture target";
	}else{
		texData.alphaMask = std::make_shared<ofTexture>(mask);
	}

to:

	texData.alphaMask = std::make_shared<ofTexture>(mask);

Yes! That makes it work! :slight_smile: