razong が指摘したように、それは OF の仕組みではありません。OF (私の知る限り) は、多くの OpenGL のものに便利なラッパーを提供します。そのため、OF 呼び出しを使用して現在の描画コンテキストに影響を与える必要があります (スプライト オブジェクトなどを含むキャンバスを考えるのではなく)。私は通常、そのようなものを自分のオブジェクトに統合します。このようなクラスがあるとしましょう...
class TheBall {
protected:
ofColor col;
ofPoint pos;
public:
// Pass a color and position when we create ball
TheBall(ofColor ballColor, ofPoint ballPosition) {
col = ballColor;
pos = ballPosition;
}
// Destructor
~TheBall();
// Make our ball move across the screen a little when we call update
void update() {
pos.x++;
pos.y++;
}
// Draw stuff
void draw(float alpha) {
ofEnableAlphaBlending(); // We activate the OpenGL blending with the OF call
ofFill(); //
ofSetColor(col, alpha); // Set color to the balls color field
ofCircle(pos.x, pos.y, 5); // Draw command
ofDisableAlphaBlending(); // Disable the blending again
}
};
わかりました、それが理にかなっていることを願っています。この構造を使用すると、次のようなことができます
testApp::setup() {
ofColor color;
ofPoint pos;
color.set(255, 0, 255); // A bright gross purple
pos.x, pos.y = 50;
aBall = new TheBall(color, pos);
}
testApp::update() {
aBall->update()
}
testApp::draw() {
float alpha = sin(ofGetElapsedTime())*255; // This will be a fun flashing effect
aBall->draw(alpha)
}
楽しいプログラミング。楽しいデザイン。