openframeworks / openframeworks/openFrameworks

Can't copy ofFbo to ofImage when allocate with GL_RGB on iOS

Open
#5,827 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C++
Stars
10.4k
Forks
2.6k
Avg merge
1d 21h
Merged PRs (30d)
9

Description

If I allocate ofFbo with GL_RGBA, I can successfully copy the FBO to ofImage. But if I use GL_RGB instead, I could not properly copy FBO to ofImage.

Here's my simple test code.

in ofApp.h

ofFbo fbo;
ofImage img;

in ofApp.cpp

//--------------------------------------------------------------
void ofApp::setup(){	

    ofSetBackgroundColor(0);
    
    //allocate an image space
    img.allocate(ofGetWidth(), ofGetHeight(), OF_IMAGE_COLOR);
    
    //allocate the fbo
    fbo.allocate(ofGetWidth(), ofGetHeight(), GL_RGBA);
    
    //draw an ellipse to the fbo
    fbo.begin();
    ofClear(0,0,0,0);
    ofSetColor(255);
    ofDrawEllipse(ofGetWidth()/2, ofGetHeight()/2, ofGetWidth(), ofGetHeight());
    fbo.end();
    
    //copy pixels from fbo to image
    ofPixels pixels;
    fbo.readToPixels(pixels);
    img.setFromPixels(pixels);
}

//--------------------------------------------------------------
void ofApp::update(){

}

//--------------------------------------------------------------
void ofApp::draw(){

    //draw the image
    img.draw(0, 0, ofGetWidth(), ofGetHeight());
}

If I run the code, the white ellipse appears on the black background.

But if I change GL_RGBA to GL_RGB from the code and run it, I no longer see the white ellipse but only the black background.

Does any one know why it happens and how to fix this?
Thanks in advance!!

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the reproduction in ofApp.h and ofApp.cpp, changing the FBO allocation from GL_RGBA to GL_RGB on iOS and observing the result of fbo.readToPixels followed by img.setFromPixels. Trace the FBO-to-image pixel transfer and determine what must change so the white ellipse is displayed with GL_RGB as it is with GL_RGBA.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, ios
Domain
computer-graphics, mobile-dev
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.