Strange image.draw() behavior >black image after first frame

I’m running into a weird problem and I have no idea what is going wrong.
I’m creating class with different properties (xpos, ypos, imagepixels). I store the objects of that class in a vector and draw them on screen. The image is drawn in the first frame but then it turns black. I have no idea what’s going wrong.
here is the code:
the class

    class Letter{
public:
    int _id;
    ofImage _image;
    string _owner;
    string _letter;
    
    int _xPos=200;
    int _yPos=60;
    int _offset=60;
    int _constNumber;
    
    Letter(string THEID, string LETTER, string OWNER, int constructorNumber){
        _id=ofToInt(THEID);
        _owner=OWNER;
        _letter=LETTER;
        _constNumber=constructorNumber;
        if(constructorNumber<5){
            _xPos=_xPos+(constructorNumber)*_offset;
        }
    }
    void print(){
        printf("id     %i ",_id);
        printf("letter %s ",_letter.c_str());
        printf("owner %s \n",_owner.c_str());
    }
    void loadImage(){
        string URL="WEBADDRESS/images/244x200/"+ofToString(_id)+".png";
        ofHttpResponse resp=ofLoadURL(URL);
        _image.loadImage(resp);
        printf("image loaded : %d\n", _image.bAllocated());
    }
    
    void draw(){
        //printf("xPos %i ", _xPos);
        _image.draw(_xPos,_yPos,244, 200);
    }
    void update(){
        _xPos--;
    }
};

and this is how I draw it:

allLetters[0].loadImage();
    allLetters[0].draw();

there is definitely an image in draw letters, it also seems that the image is loaded… but it’s turning black… any ideas?

don’t you have to load only once (eg. in setup) ?
it seems to me that trying to load every frame wont let you see anything

Hi, if I had to guess I’d bet that the color is set to black when you draw it?

ofSetColor(0);
image.draw(0,0);

will always come out looking black because of the way the color is set.

ofSetColor(255);
image.draw(0,0);

will turn out how you expect because the drawing color is set to white. Without knowing more about the code that’s all i can guess.

3 Likes

stupid me!
thanks @CTWL. That was the problem!
I hope I’ll never forget this again. I looked at this code for hours and I had no idea what was the problem…