We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
Page Index Toggle Pages: 1
Renderer Types (Read 1218 times)
Renderer Types
Aug 20th, 2007, 4:16am
 
I am new to processing and 3D and I have been trying to test renderer differences. I am wondering why the following code works with the default and JAVA2D renderers, but not with the P3D or OPENGL renderers. This particular code does not manipulate the shape in the Z-axis but I am trying to figure out why i can't use the P3D and OPENGL renders with this code, before adding more variables. Any help would be appreciated. Thank you.

Quote:


import processing.opengl.*;

int shapes = 100;
float[]speedX = new float[shapes];
float[]speedY = new float[shapes];
float[]x = new float[shapes];
float[]y = new float[shapes];
float[]w = new float[shapes];
float[]h = new float[shapes];
color[]c1 = new color[shapes];

void setup(){
 size(500,500, OPENGL);

 frameRate(30);

 for (int i=0; i<shapes; i++){
   x[i]=width/2;
   y[i]=height/2;
   w[i]=random(.1, .2);
   h[i]=w[i];
   c1[i]=color(random(255), random(255), random(255));
   speedX[i] = random(-5, 5);
   speedY[i] = random(-2, 2);
 }

}

void draw(){
 fill(255, 90);
 rect(0,0, width, height);

 for (int i=0; i<shapes; i++){
   fill(c1[i]);
   fontA(x[i], y[i], w[i], h[i], c1[i]);
   x[i]+=speedX[i];
   y[i]+=speedY[i];

   if (x[i] > width-(64.01*w[i])){
     x[i] = width-(64.01*w[i]);
     speedX[i]*=-1;
   }
   else if (x[i] < 0){
     x[i] = 0;
     speedX[i]*=-1;
   }
   else if (y[i] > height-(71.73*w[i])){
     y[i] = height-(71.73*w[i]);
     speedY[i]*=-1;
   }
   else if (y[i] < 0){
     y[i]  = 0;
     speedY[i] *=-1;
   }
 }

}
void fontA(float x, float y, float w, float h, color c1){
 resetMatrix();
 translate(x,y);
 scale(w, h);
 fill(c1);
 partA();
 fill(255);
 partB();
}

void partA(){

 beginShape();

 vertex(27.01, 0);
 vertex(37.98, 0);
 vertex(64.01, 71.73);
 vertex(53.37, 71.73);
 vertex(45.88, 50.24);
 vertex(17.74, 50.24);
 vertex(9.96, 71.73);
 vertex(0, 71.73);
 vertex(27.01, 0);

 endShape(CLOSE);
}

void partB(){

 beginShape();

 vertex(32.08, 10.64);
 vertex(43.12, 42.33);
 vertex(20.6, 42.33);

 endShape(CLOSE);
}



Re: Renderer Types
Reply #1 - Aug 20th, 2007, 4:58pm
 
You have two issues, one big, one small:

First, you probably don't want to call resetMatrix() in your fontA(), you should instead call pushMatrix() at the top, and then popMatrix() and the bottom.  Make that change and it should work as is.  Otherwise you're throwing away the camera transform along with the model transform, so your stuff is probably appearing somewhere offscreen outside of camera space.

I'm not quite sure if that's how it's supposed to work (?) but it does, because the modelview matrix "contains" the initial camera.  It works in 2D because there isn't the camera stuff in the matrix.

The other issue you'll have is with your "trails" technique.  The "don't clear background, fade by using transparent rect" trick won't work with OPENGL.  Instead your text will fly around without trails.  (should work with P3D though)
Re: Renderer Types
Reply #2 - Aug 21st, 2007, 12:45am
 
Thanks davbol. Your explanation and tips helped a lot.
Re: Renderer Types
Reply #3 - Aug 28th, 2007, 11:23am
 
From what i've experienced, the trail trick doesn't work only if you have antialiasing turned on in your graphic card driver settings.
Page Index Toggle Pages: 1