Background color change of G4P elements

edited November 2014 in Library Questions

Hello,

i'm having some troubles with G4P elements I use in a 3D-visualization of packages of spheres. For this task, I use peasycam and the g4p-library with GUI Builder. My problem is: the color of the gui-elements change with the change of the camera. I have seen that there is even an example for using g4p with peasycam, but i could not find the difference between my code and the example code. At least not why that color change happens. Does anyone know what I do wrong? The code is attached below.

//PeasyCam
import peasy.*;
// Need G4P library
import g4p_controls.*;

PeasyCam cam;
PVector[] coordinatevectors=null;
SphereObj[] spheres=null;

public void setup(){
  size(800, 600, P3D);
  createGUI();
  frameRate(10);
  sphereDetail(15);
  cam = new PeasyCam(this, 100);
  cam.setMinimumDistance(50);
  cam.setMaximumDistance(5000);
  //create 100 spheres with random coordinates, red or blue (random too)
  coordinatevectors = new PVector[100];
  spheres = new SphereObj[100];
  for(int i=0;i<100;i++)
    coordinatevectors[i]= new PVector(random(20), random(20), random(20));
  for(int i=0;i<100;i++){
    spheres[i]= new SphereObj(coordinatevectors[i], 5.0, (int)random(2), 0);
  }
}

void draw(){
    background(255);
    noStroke();
    lights();
    for(int i=0;i<100;i++){
      spheres[i].disp();
    }
}

class SphereObj{
  PVector coords;
  float radius;
  int active;
  int clusternumber;
  boolean display;
  color c;

  SphereObj(PVector coords_, float radius_, int active_, int clusternumber_){
    coords = coords_;
    radius = radius_;
    active = active_;
    clusternumber = clusternumber_;
    display=true;
    if(active==1){
      c = color(229,2,48);
    }
    else{
      c = color(28,33,216);
    }
  }

  void disp(){
    if(display==true){
       fill(c);
       pushMatrix();
       translate(coords.x, coords.y, coords.z);
       sphere(radius);
       popMatrix();
    }
  }
}

//GUI, created with G4P GUI-Builder

public void txaProperties_change(GTextArea source, GEvent event) { //_CODE_:txaProperties:746241:
  println("txaProperties - GTextArea >> GEvent." + event + " @ " + millis());
} //_CODE_:txaProperties:746241:

// Create all the GUI controls. 
// autogenerated do not edit
public void createGUI(){
  G4P.messagesEnabled(false);
  G4P.setGlobalColorScheme(GCScheme.BLUE_SCHEME);
  G4P.setCursor(ARROW);
  if(frame != null)
    frame.setTitle("Sketch Window");
  txaProperties = new GTextArea(this, 6, 102, 150, 330, G4P.SCROLLBARS_VERTICAL_ONLY | G4P.SCROLLBARS_AUTOHIDE);
  txaProperties.setPromptText("Cluster properties");
  txaProperties.setOpaque(true);
  txaProperties.addEventHandler(this, "txaProperties_change");
}

// Variable declarations 
// autogenerated do not edit
GTextArea txaProperties; 

Answers

  • Answer ✓

    The problem is the lights add noLights() to the end of draw like this

    void draw(){
        background(255);
        noStroke();
        lights();
        for(int i=0;i<100;i++){
          spheres[i].disp();
        }
        noLights();
    }
    

    G4P controls are drawn after the draw() method completes.

  • That solved my problem, thank you! And: great gui-library and builder-tool! You saved a lot of my time.

Sign In or Register to comment.