ofDrawStringAsShapes not effected by ofSetColor

ofDrawString() is behaving very differently from ofDrawStringAsShapes() in terms of the coloring. I don’t want to paste the whole code because it’s quite lengthy and out of context is sort of useless but the following produce very different results,

song is ofTrueTypeFont and tracks[i] is some string

ofSetColor(51, 102, 183);
song.drawStringAsShapes(tracks[i], 0,0);
ofDrawBox(0, 0, 0, 100);

vs

ofSetColor(51, 102, 183);
.drawStringAsShapes(tracks[i], 0,0);
ofDrawBox(0, 0, 0, 100);

with ofDrawString(), the color goes in effect but the font looks terrible, with drawStringAsShapes I’m not getting the color I want but it’s not completely ignored because I notice a difference when I use (255,0,0) as opposed to say (0,255,0) or reddish vs greenish tint. This code is actually wrapped up in some loops and is quite convoluted but I was just wondering if anyone knew any obvious difference in behavior between the two. Shouldn’t the color of the font always be dictated by whatever comes right before it. I guess that’s the real question or is there something else I should be checking

Is your full code hosted somewhere?

Both ofDrawString(...) and ofDrawStringAsShapes(...) are working for me with regards to color:

ofTrueTypeFont font;
string text = "Test";
float strWidth;

//--------------------------------------------------------------
void testApp::setup(){
    font.loadFont("verdana.ttf", 50, true, false, true);
    strWidth = font.stringWidth(text);
}

//--------------------------------------------------------------
void testApp::draw(){
    ofBackground(0);

    ofPushMatrix();
        ofTranslate(ofGetWidth()/2-strWidth/2, ofGetHeight()/2);

        if(ofGetKeyPressed(' ')) {
            ofSetColor(255, 0, 0);
            font.drawStringAsShapes(text, 0, 0);

        }
        else {
            ofSetColor(0, 0, 255);
            font.drawString(text, 0, 0);
        }

    ofPopMatrix();
}

Appreciate your help mike, I don’t like to post the code until it’s sort of finished, you only get one shot at a first impression. But I’ll post the whole thing when I’m done. I’ve stripped down the portion to its bare essentials and made it as self contained as possible. Basically it’s a bunch of rotating cubes with some text arranged in a helical shape above it rotating in the same fashion.

for( int i = 0; i < 5; i++) {
if( (page != 1) || (i != 0) ){
    if( (page != 3) || (i != 4) ){
        if(bUseTexture) covers[10+i].getTextureReference().bind();
        ofPushMatrix();
        ofTranslate(-200 + i*100, 500, 200);
        //ofRotate(ofGetElapsedTimef()*.6 * RAD_TO_DEG, 1, 0, 0);
                  
        if(rotate[10+i]){
            
            trans = 100;
          
            ofTranslate(0,0,enlarge);
            
            ofPushMatrix();
            //ofRotate(-60, 1,0,0);
            ofRotate(ofGetElapsedTimef()*.6 * RAD_TO_DEG, 0, 1, 0);                            
            
            //ofSetColor(51, 102, 183);
            for(int i = 0; i<tracks.size(); i++){
                ofPushMatrix();
               
                deg = 360/tracks.size();
                deg *= i;
                deg = deg * pi / 180;
                
                translatex = 20*sqrt(2)*cos(deg);
                translatez = -20*sqrt(2)*sin(deg);
                
                
                ofTranslate(translatex,height + 30*sqrt(2)*cos(deg/2),translatez);
                ofRotate(-ofGetElapsedTimef()*.6 * RAD_TO_DEG, 0, 1, 0);
                                      
                //ofSetColor(51, 102, 183);
                
                ofSetColor(255,0,0);
                songs[i].drawStringAsShapes(tracks[i], 0,0);
                //ofDrawBitmapString("heloooo", 0,0);
                
                //ofSetColor(255,255,255);
                ofPopMatrix();
                
                trans = 100;
            }
            ofPopMatrix();

            trans = 255;
            ofRotate(ofGetElapsedTimef()*.8 * RAD_TO_DEG, 0, 1, 0);
        }
        
        ofSetColor(255,255,255);
        ofDrawBox(0, 0, 0, 100);
        ofPopMatrix();
        if(bUseTexture) covers[10+i].getTextureReference().unbind();
    }
}

}

the trouble is with the songs[i].drawStringAsShapes(tracks[i], 0,0); whatever color is being set right above it in (for ex. ofSetColor(255,0,0)) is bleeding or mixing with the inherent color of the text (which I don’t know how it’s being set) But when I change it to drawString() it takes on the color correctly but the box being drawn outside of that loop is now taking on the same color or some other color (ofSetColor() that comes right before it), ie the texture appended to it is destroyed. with drawStringAsShapes, the (255,255,255) would keep the texture intact. I just don’t have a very good handle on ofSetColor, what does it impact, how long does it persist, how is it affected by code blocks and conditionals.

1 Like

@nuvella ahhh, thank you for sharing some more extended code. I can completely understand not wanting to share code until it is more complete.

I couldn’t think of a reason why ofSetColor(...) would be tripped up, but I think your problem has to do with how you are using bind() and unbind().

You are trying to use a texture to draw a cover album on some box shape, right? Your bind() and unbind() calls should be immediately around the object that uses that texture. Like:

covers[10+i].getTextureReference().bind();
ofDrawBox(0, 0, 0, 100);
covers[10+i].getTextureReference().unbind();

ofSetColor(51, 102, 183);
songs[i].drawStringAsShapes(tracks[i], 0,0);

Right now, your whole loop is in between those bind() and unbind() calls. So anything inside of that, like drawStringAsShapes(...), is being draw using the texture from covers[10+i], and so your ofSetColor(...) isn’t controlling color in the way you expect.

So to quickly see if that’s the cause of the problem, try commenting out your code that uses texture binding and rerunning. If that fixes it, then just go back and move your bind and unbind statements to only encapsulate the box drawing code.

Someone else who is more familiar opengl can jump in and explain exactly how the opengl commands for binding and setting color are interacting.

That did the trick! thanks a lot. Yea that’s exactly what I’m doing. I’ll share it when I’m done.

No problem - looking forward to checking it out