Help us understand the problem. What is going on with this article?

ofSetBackgroundAuto(false)で1frame目から描画する

More than 1 year has passed since last update.

openFrameworksでブラーなどのように前frameの画を残して描く際にofSetBackgroundAuto(false)を使います.

が.

どうも1frame目から描けない謎がありました.
未だに完全には原因不明ですが, 一応荒業(?)での解決もできたので念のため記録まで.

git

https://github.com/KeitaSumiya/oF/tree/master/drawbackgroundauto

事前) ofSetBackgroundAuto(true)の場合

1frameから描画できることの確認

https://github.com/KeitaSumiya/oF/tree/master/drawbackgroundauto/0_1_0a_before_true_drawFrom1frame

ofApp.cpp
#include "ofApp.h"

//--------------------------------------------------------------
void ofApp::setup(){
    ofSetFrameRate(1);
    ofBackground(0);
    //ofSetBackgroundAuto(false);
}

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

//--------------------------------------------------------------
void ofApp::draw(){
    count++;
    cout << count << endl;
    ofDrawBitmapString(count, 100, 10*count);
}
ofApp.h
#pragma once

#include "ofMain.h"

class ofApp : public ofBaseApp{

public:
    void setup();
    void update();
    void draw();

    int count = 0;
};

結果
true.png

本題) ofSetBackgroundAuto(false)の場合

問題) 4frameから描画されてしまう

https://github.com/KeitaSumiya/oF/tree/master/drawbackgroundauto/0_1_0b_bad_drawFrom4frame

ofApp.cpp
#include "ofApp.h"

//--------------------------------------------------------------
void ofApp::setup(){
    ofSetFrameRate(1);
    ofBackground(0);
    ofSetBackgroundAuto(false);
}

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

//--------------------------------------------------------------
void ofApp::draw(){
    count++;
    cout << count << endl;
    ofDrawBitmapString(count, 100, 10*count);
}
ofApp.h
#pragma once

#include "ofMain.h"

class ofApp : public ofBaseApp{

public:
    void setup();
    void update();
    void draw();

    int count = 0;
};

結果
bad.png

解決) 1frameから描画できた

https://github.com/KeitaSumiya/oF/tree/master/drawbackgroundauto/0_1_1_better_drawFrom1frame

ofApp.cpp
#include "ofApp.h"

//--------------------------------------------------------------
void ofApp::setup(){
    ofSetFrameRate(1);
    ofBackground(0);
}

//--------------------------------------------------------------
void ofApp::update(){
    ofSetBackgroundAuto(false);
}

//--------------------------------------------------------------
void ofApp::draw(){
    ofSetBackgroundAuto(true);
    count++;
    cout << count << endl;
    ofDrawBitmapString(count, 100, 10*count);
}
ofApp.h
#pragma once

#include "ofMain.h"

class ofApp : public ofBaseApp{

public:
    void setup();
    void update();
    void draw();

    int count = 0;
};

結果
better.png

参考

openFrameworksで軌道の残像を描画しつつ画像保存する方法

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away