Quality Dropped after drawing multiple shapes (ofSpherePrimitive's)

Hello All,

When I draw multiple spheres the quality of the remaining spheres drops, significantly. As seen in this gif (I know the UI isn’t the prettiest, just working on basic functionality for now):

Does anyone know why this occurs? Visual Studio says the program takes up around 72 mb of RAM and 4% CPU. Is my code inefficient?

Here are the relevant pieces of code. I’ll only upload the code for the ‘Oxygen’ sphere as the other spheres/ relevant code are near identical copies with different colors and radii.

The class declaration for Oxygen:

class Oxygen {
	void setup();
	void draw();
	void update();

	bool isActive; 

	ofPoint location;
	ofSpherePrimitive oxygen;
	ofLight light;

The oxygen class functions:

void Oxygen::setup() {
	location = ofPoint(895, 100, 0);

void Oxygen::draw() {

	ofSetColor(204, 0, 0);


void Oxygen::update() {



                Oxygen oxygen[3];
		Hydrogen hydrogen[3];
		Sodium sodium[3];
		Nitrogen nitrogen[3];
		Chlorine chlorine[3];

ofApp: setup():

for (int i = 0; i < 3; i++) {

ofApp: draw():

    ofRectangle viewport(0, 0, 768, 900);

	int countO = 0;          
	oxygen[0].isActive = true;
	while (viewport.inside(oxygen[countO].location) && countO < 2) {
		oxygen[countO].isActive = true;

The loop for the other spheres (atoms) is exactly the same, I just initialized a different variable.

and lastly: ofApp: mouseDragged:

for (int i = 0; i < 3; i++) {
		if (oxygen[i].isActive == true) {
			if (x >= oxygen[i].location.x - 55 && x <= oxygen[i].location.x + 55) {
				if (y >= oxygen[i].location.y - 55 && y <= oxygen[i].location.y + 55) {
					if (button == 0) {
						oxygen[i].location.x = ofGetMouseX();
						oxygen[i].location.y = ofGetMouseY();

I’m a beginner so any tips and advice would be greatly appreciated. Also, i do apologize if I formatted this post in an unorthodox way. Thanks for reading!!!

have you tried to build on release mode? (not in debug)
this mode performs much better.

Just tried it, unfortunately it did not work :frowning: . Thanks for the tip though, didn’t even know release mode was a thing.

??? I’m not sure I follow.

Try to put your changing color (ofSetColor) and style code between ofPushStyle(); (change color and draw code) and ofPopStyle(). It looks like 2 last sphere are not the color look you are expecting.

I’m not sure I follow, its my first time hearing those commands. Do you mind sending me some sample code of what you mean? Thanks!

Each instance of your Oxygen class (and i assume your other elements) creates an ofLight. Using oF with OpenGL <3 there is a limit of 8 ofLights. With OpenGL >=3 you can have more but need ofMaterials. See Working with more then 8 ofLights-objects

So, when you reach your 9th instance, there are no lights left to use. (Not sure if a warning is emitted when that happens – check the console).

That being said, you probably do not want a dedicated light for each instance of your elements – the kind of rendering you are doing could use usual “global” scene-based light(s) and achieve the same result (i.e. light all the objects with the same source(s)). So create and manage the desired light(s) at the app/scene level and not at the element instance level.

Ahh, I see. Thank you so much. Appreciate it.