# OpenGL - cannot load shapes(objects)

**URL:** <https://discourse.processing.org/t/opengl-cannot-load-shapes-objects/12629>\
**Category:** Coding Questions\
**Created:** [July 9, 2019, 3:37pm UTC](https://discourse.processing.org/t/opengl-cannot-load-shapes-objects/12629 "2019-07-09T15:37:12Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ProgrammableBoyCZECH](https://avatars.discourse-cdn.com/v4/letter/p/a6a055/32.png) [@ProgrammableBoyCZECH](https://discourse.processing.org/u/ProgrammableBoyCZECH)\
**Post date:** [July 9, 2019, 3:37pm UTC](https://discourse.processing.org/t/opengl-cannot-load-shapes-objects/12629/1 "2019-07-09T15:37:12Z")

</div>

Hi, can you help me with this code please?  
I want to make program with OpenGL that shows up objects and if you click with mouse it will  
show another one.  
But it is showing only first two, but other not. HERE IS THE CODE:

```auto
import processing.opengl.*;

float a;
int value = 0;
PImage cube;
PImage cube2;
PImage sphere;
PImage sphere2;
PImage backgroundImg;

void setup() {
  fullScreen(OPENGL);
  fill(255, 255);
  noStroke();
  smooth();
  noCursor();
  cube = loadImage("ANY IMAGE");
  cube2 = loadImage("ANY IMAGE");
  sphere = loadImage("ANY IMAGE");
  sphere2 = loadImage("ANY IMAGE");

}
void draw() {
  background(127);
  PShape globe;
  PShape box;
  PShape globe2;
  PShape box2;
  a += 0.01;
  lights();
  
  globe = createShape(SPHERE, 250);
  globe.setTexture(sphere);
  
  
  globe2 = createShape(SPHERE, 250);
  globe2.setTexture(sphere2);
  
  
  box = createShape(BOX, 250);
  box.setTexture(cube);
  
  
  box2 = createShape(BOX, 250);
  box2.setTexture(cube2);
  
  
  translate(width/2, height/2);
  scale(-1, -1);
  rotateX(mouseY * 0.01);
  rotateY(mouseX * 0.01);
  text(value, 50, 50);
  
  if(value == 0) {
    shape(box); 
  }
  if(value == 1) {
    shape(box2);
  }
  if(value == 2) {
    shape(globe);
  }
  if(value == 3) {
    shape(globe2);
  }
}
void mouseClicked() {
  
  if(value >=3) {
    value = 0;
  }else {
    if(value ==0) {
    value = value + 1;
    }
  }
}

```

Thank You for Reply. =]

---

<div class="post-metadata">

**Author:** ![ProgrammableBoyCZECH](https://avatars.discourse-cdn.com/v4/letter/p/a6a055/32.png) [@ProgrammableBoyCZECH](https://discourse.processing.org/u/ProgrammableBoyCZECH)\
**Post date:** [July 9, 2019, 4:21pm UTC](https://discourse.processing.org/t/opengl-cannot-load-shapes-objects/12629/2 "2019-07-09T16:21:25Z")

</div>

Sorry, I made a mistake here:

```auto
void mouseClicked() {
    ¤ ¤ ¤
  if(value >=3) {
    value = 0;
  }else {
    if(value ==0) { //HERE
    value = value + 1;
    }
  }
}

```

error was there: if NUMBEROFCLICKS is 0 then add 1

but when it is 1 it cannot be more because it must be zero again to be 1.

there is the right code:

```auto
void mouseClicked() {
  
  if(value >=3) { 
    value = 0;                 
    
  }else { // Do it anyway
  value++;                     
  }
}

```

And because I am czech i have full code for you =]

```auto
import processing.opengl.*;//vložení knihovny OpenGL

    
    
                                                                    int Objects = 4; // Kolik je objektů

//----------------------------------------------------------
  PImage cube;
  PImage cube2; //Vytvoření proměnných pro textury objektů
  PImage sphere;
  PImage sphere2;
//----------------------------------------------------------

float a; //Pro rotaci objektů
int value = 0;//Pro počítání stisknutí myši

void setup() {
  fullScreen(OPENGL);//inicializace okna v režimu renderování OpenGL
  noStroke();//Objekty bez okrajů
  smooth();//Hladké renderování
  noCursor();//zobrazení bez myši
  
  
  
  //--------------------------------------------------------------------------------------
  
  
  
  cube = loadImage("");
  cube2 = loadImage(""); //Přidání textur k objektu
  sphere = loadImage("");
  sphere2 = loadImage("");
  
  
  
  //--------------------------------------------------------------------------------------

  
  
  

}

public void draw() {
  background(127); //Barva pozadí
  a += 0.01; //Proměnná pro rotaci objektů
  lights(); //Renderování světla
  
  
  
  //------------------------------------------------------------
  PShape globe;
  PShape box;
  PShape globe2;
  PShape box2;
  
  globe = createShape(SPHERE, 250);
  globe.setTexture(sphere);
  
  
  globe2 = createShape(SPHERE, 250);
  globe2.setTexture(sphere2); //Definování objektů
  
  
  box = createShape(BOX, 250);
  box.setTexture(cube);
  
  
  box2 = createShape(BOX, 250);
  box2.setTexture(cube2);
  //------------------------------------------------------------
  
  
  
  translate(width/2, height/2);//Vycentrování objektů
  scale(-1, -1);//Převrácení osy X a Y pro rotaci
  rotateX(mouseY * 0.01);//samotná rotace osy X
  rotateY(mouseX * 0.01);//samotná rotace osy Y

  
//------------------------------------------------------------//

  
  if(value == 0) {
    shape(box); 
  }
  if(value == 1) {
    shape(box2);
  } //Výběr objektu a jeho zobrazení
  if(value == 2) {
    shape(globe);
  }
  if(value == 3) {
    shape(globe2);
  }

//------------------------------------------------------------//

}
void mouseClicked() {
  
  if(value >=(Objects - 1)) { //Pokud je počet stisknutí myši větší jak 3, tak:
    value = 0; //----resetování počtu stisknutí myši
    
  }else { //Když ne tak:
  value++; //----přidá k počtu stisknutí myši 1
  }
}

```
