Gradient fills for rects

Is exist a simple way to set gradient fill to ofRect(x,y, w, h), like a set bacground gradient fill

ofBackgroundGradient(colorOne, colorTwo, OF_GRADIENT_CIRCULAR);

?

1 Like

Hi there!

Basically, no. You have to do it, pixel-by-pixel. There are a lot of topics on this, in this forum. If you want performance, shaders is your best option.

1 Like

you can use a mesh to color vertices:

ofMesh temp;
temp.setMode(OF_PRIMITIVE_TRIANGLE_STRIP);
temp.addVertex( ofPoint(100,100) );
temp.addColor(ofColor::pink);
temp.addVertex( ofPoint(200,100) );
temp.addColor(ofColor::pink);
temp.addVertex( ofPoint(100,200) );
temp.addColor(ofColor::yellow);
temp.addVertex( ofPoint(200,200) );
temp.addColor(ofColor::yellow);
temp.draw();

for complicated things like circular gradient, you can use a shader or texture.

1 Like

that’s good. thank you.