Skip to content

Instantly share code, notes, and snippets.

@admsyn
Last active December 11, 2015 00:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save admsyn/977bbeb1fc0d40688227 to your computer and use it in GitHub Desktop.
Save admsyn/977bbeb1fc0d40688227 to your computer and use it in GitHub Desktop.
// trying to replicate https://github.com/openframeworks/openFrameworks/issues/1533
// this test has ofFbo and ofPixels as members of testApp, and does everything in setup()
#include "ofMain.h"
#include "ofAppGlutWindow.h"
struct testApp : public ofBaseApp {
void setup();
ofFbo fbo;
ofPixels_<unsigned char> pixels;
};
void testApp::setup(){
std::cout << "start" << std::endl << "------" << std::endl;
const unsigned int w = ofGetWidth();
const unsigned int h = ofGetHeight();
fbo.allocate(w, h, GL_RGB);
fbo.readToPixels(pixels);
for(int y = 0; y < h; y++) {
for(int x = 0; x < w; x++) {
ofColor someColor = pixels.getColor(x, y);
}
}
pixels.clear();
std::cout << "------" << std::endl << "end" << std::endl;
ofExit();
}
int main(){
ofAppGlutWindow window;
ofSetupOpenGL(&window, 1024,768, OF_WINDOW);
ofRunApp( new testApp());
}
The following is the output for each of these on my system (OSX 10.8, Xcode 4.5), tested with Debug and Release.
GNU gdb 6.3.50-20050815 (Apple version gdb-1822) (Sun Aug 5 03:00:42 UTC 2012)
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "x86_64-apple-darwin".tty /dev/ttys001
[Switching to process 13475 thread 0x0]
start
------
------
end
Program ended with exit code: 0
// trying to replicate https://github.com/openframeworks/openFrameworks/issues/1533
// This creates ofPixels on the stack, and has ofFbo as a member of testApp
// It does color reading / writing and pixels.clear() in update(), and draws the fbo in draw()
#include "ofMain.h"
#include "ofAppGlutWindow.h"
struct testApp : public ofBaseApp {
void setup();
void update();
void draw();
ofFbo fbo;
};
void testApp::setup(){
std::cout << "start" << std::endl << "------" << std::endl;
fbo.allocate(ofGetWidth(), ofGetHeight(), GL_RGB);
}
void testApp::update(){
const unsigned int w = floorf(fbo.getWidth());
const unsigned int h = floorf(fbo.getHeight());
fbo.begin();
ofSetColor(rand()%255, rand()%255, rand()%255);
ofFill();
ofRect(0,0,w,h);
fbo.end();
ofPixels_<unsigned char> pixels;
fbo.readToPixels(pixels);
for(int y = 0; y < h; y++) {
for(int x = 0; x < w; x++) {
ofColor someColor = pixels.getColor(x, y);
}
}
pixels.clear();
if(ofGetFrameNum() > 120) {
std::cout << "------" << std::endl << "end" << std::endl;
ofExit();
}
}
void testApp::draw(){
fbo.draw(20, 20, 640, 480);
}
int main(){
ofAppGlutWindow window;
ofSetupOpenGL(&window, 1024,768, OF_WINDOW);
ofRunApp(new testApp());
}
// trying to replicate https://github.com/openframeworks/openFrameworks/issues/1533
// This creates ofPixels and ofFbo on the stack
// It does color reading / writing and pixels.clear() in update()
#include "ofMain.h"
#include "ofAppGlutWindow.h"
struct testApp : public ofBaseApp {
void setup();
void update();
};
void testApp::setup(){
std::cout << "start" << std::endl << "------" << std::endl;
}
void testApp::update(){
ofFbo fbo;
fbo.allocate(ofGetWidth(), ofGetHeight(), GL_RGB);
const unsigned int w = floorf(fbo.getWidth());
const unsigned int h = floorf(fbo.getHeight());
fbo.begin();
ofSetColor(rand()%255, rand()%255, rand()%255);
ofFill();
ofRect(0,0,w,h);
fbo.end();
ofPixels_<unsigned char> pixels;
fbo.readToPixels(pixels);
for(int y = 0; y < h; y++) {
for(int x = 0; x < w; x++) {
ofColor someColor = pixels.getColor(x, y);
}
}
pixels.clear();
if(ofGetFrameNum() > 120) {
std::cout << "------" << std::endl << "end" << std::endl;
ofExit();
}
}
int main(){
ofAppGlutWindow window;
ofSetupOpenGL(&window, 1024,768, OF_WINDOW);
ofRunApp(new testApp());
}
// trying to replicate https://github.com/openframeworks/openFrameworks/issues/1533
// this test has ofFbo and ofPixels as members of testApp, does color reading / writing
// and pixels.clear() in update(), and draws the fbo in draw()
#include "ofMain.h"
#include "ofAppGlutWindow.h"
struct testApp : public ofBaseApp {
void setup();
void update();
void draw();
ofFbo fbo;
ofPixels_<unsigned char> pixels;
};
void testApp::setup(){
std::cout << "start" << std::endl << "------" << std::endl;
fbo.allocate(ofGetWidth(), ofGetHeight(), GL_RGB);
}
void testApp::update(){
const unsigned int w = floorf(fbo.getWidth());
const unsigned int h = floorf(fbo.getHeight());
fbo.begin();
ofSetColor(rand()%255, rand()%255, rand()%255);
ofFill();
ofRect(0,0,w,h);
fbo.end();
fbo.readToPixels(pixels);
for(int y = 0; y < h; y++) {
for(int x = 0; x < w; x++) {
ofColor someColor = pixels.getColor(x, y);
}
}
if(ofGetFrameNum() > 120) {
pixels.clear();
std::cout << "------" << std::endl << "end" << std::endl;
ofExit();
}
}
void testApp::draw(){
fbo.draw(20, 20, 640, 480);
}
int main(){
ofAppGlutWindow window;
ofSetupOpenGL(&window, 1024,768, OF_WINDOW);
ofRunApp(new testApp());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment