Hi Nikhan,
if what you want is to load 5 different images, then use them to draw lots of copies of them, here is what I would do:
-in your testApp, load the 5 images:
// in your class declaration
vector<ofImage*> assets;
// in your testApp::setup
int nImages = DIR.listDir("images");
for(int i=0;i<nImages;i++){
ofImage* image = new ofImage();
image->loadImage( DIR.getPath(i) );
assets.push_back(image);
}
-create a new class, e.g. ‘MyImage’ and assign it one of the loaded images. Just make sure, when exiting your program, that all your MyImage instances are deleted before you delete the loaded images.
// in your class declaration, the constructor will look like this:
MyImage(ofImage* img);
// and add a draw function
void draw();
// and you will have a property containing a pointer to the image
ofImage* image;
// and some coords or something, to make drawing easier
float x, y;
// in your MyImage constructor:
MyImage::MyImage(ofImage* img){
image = img;
x = ofRandom(0, ofGetWidth());
y = ofRandom(0, ofGetHeight());
}
// and the draw function:
void MyImage::draw(){
image->draw(x, y);
}
-in your testApp, you can now create as many MyImage’s as you want and then include them in your testApp::draw() function:
// in your testApp class declaration
vector<MyImage*> images;
// in testApp::setup(), after you loaded the 5 image assets:
for(int i=0;i<300;i++){
int rnd = (int) floor( ofRandom(0, assets.size()) );
images.push_back( new MyImage( assets[rnd] ) );
}
// in testApp::draw()
for(int i=0;i<images.size();i++){
images[i]->draw();
}
Note that I wrote this without being able to check the syntax, so there might be a few errors in it. Also, the way I select a random asset (‘int rnd=…’) might be improved on if there is a handier function for it.
I hope this will increase your performance a bit. The reason this might work, is that you only load each image once and pass its reference to any of the MyImage objects you create. They don’t load themselves and drawing can be very fast this way. I had no problems drawing 500+ ants that each was 400x400 pixels (but scaled down) this way.
Hope I made sense,
Droozle