I’m using the openFrameworks ofxPango addon to render text with following code:
ofxPango* pango;
ofxPCContext* context;
ofxPCPangoLayout* layout;
ofImage text_image;
pango = new ofxPango();
context = pango->createContextWithSurface(width, height);
context->color4f(1,1,1, 0.0f);
context->paint();
layout = context->createPangoLayout();
layout->setText(text);
layout->setTextColor(186,34,29, 1.0f);
layout->setWidth(width);
layout->setJustify(true);
//context->paint();
ofxPCPangoFontDescription* fd = new ofxPCPangoFontDescription();
fd->createFromString(font);
layout->setFontDescription(*fd);
layout->show();
text_image.allocate(context->getSurface()->getWidth(), context->getSurface()->getHeight(), OF_IMAGE_COLOR_ALPHA);
text_image.setFromPixels(context->getSurface()->getPixels(), text_image.width, text_image.height, OF_IMAGE_COLOR_ALPHA, true);
I’m having trouble understanding how layout->setTextColor(r,g,b,a) works.
If I run:
- 0,0,0,1 – text is black as it should be
- 255,0,0 – text is red as it should be
- 186,34,29,1 – text appears very light gray (maybe white) when it should be red
- 186,34,0,1 – text is yellow, although it should be red
Why are these colors coming out wrong?
I think color values are supposed to be within the range 0.0f and 1.0f, where:
Here are some abridged examples from the Cairo library, which ofxPango calls out to: