Drawing inside a for loop - How?


#1

need to draw some stuff inside a loop but it doesn’t work (doesn’t draw anything at all)

for(int i; i< 50; i++)
{
verdana14.drawString(data[i], 10,i*15);
}

where data is a string vector, and I need to draw all 50 strings in a list.

of course I can write 50 lines of verdana14.drawString and its works fine, but thats obviously stupid…

TIA


#2

Perhaps the « i » not being initialized it behaves not as assumed?

If it’s not that please post a compilable snippet including the data and verdana14 allocations.


#3

Not sure what I was doing anyway figured it out … I grab a block of text from a vector
and update it every second and draw into an FBO like this:

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

float t = ofGetElapsedTimef();
if (t-oldTime > 1)
{
    oldTime= t;
    pos =pos + 1;
    if(pos >  dSize-38)(pos =0);
    fbo.begin();
    ofClear(0,0,0);
    fbo.end();
}

fbo.begin();
if (fileOK) // text file loaded into vector OK
{
    ofSetColor(50,50,50);
    ofDrawRectangle(0,0,1024,750);
    ofSetColor(90,250,90);
    for (int i=1; i<37; i++){
        verdana14.drawString(data[pos+i], 10,i*20);
    }
}else{
    ofClear(0,0,0);
    verdana14.drawString("ERROR - FILE:  data.txt  NOT AVAILABLE", 10,20);
}
fbo.end();

}

//--------------------------------------------------------------
void ofApp::draw(){
ofSetColor(255,255,255);
verdana14.drawString(ofToString(pos), 10,15);

fbo.draw(0,20);

}