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.
IndexProgramming Questions & HelpOpenGL and 3D Libraries › OpenGL and speed problem
Page Index Toggle Pages: 1
OpenGL and speed problem (Read 948 times)
OpenGL and speed problem
Dec 2nd, 2006, 12:25pm
 
Hello and merry Christmas

I have an problem with OPENGL and classes.
In my program I’ve created an ball class which bounce nicely around the screen, as you can see from my code im not using any processor demanding calculations, but still im only able to run 500 objects at a decent speed.
I’ve used OPENGL before and classes to run 10’000 objects without problems.
Any suggestions.

System:
Win 2K. ATI 9000, P5-115.

Kind regards
Mads Ny


//*************** code
import processing.opengl.*;

int antal = 2000;
ballClass[] ball;

void setup(){
 size(400,400, OPENGL);
 framerate(30);
 // SETUP BALLS
 ball = new ballClass[antal];
 for(int i=0; i<antal; i++){
   ball[i] = new ballClass();
 }
}

void draw(){
 background(255);
 for(int i=0; i<antal; i++){
   ball[i].update();
 }
}


class ballClass{
 float x,y; // position
 float speed=1.4; // speed of ball
 float vx=random(-1,1), vy=random(-1,1); // move vector
 float r = random(5,20); // radius of ball
 float tvx, tvy; // temp vector

 ballClass(){
   x = random(r,width-r);
   y = random(r,height-r);
 }

 void update(){
   tvx = vx*speed;
   tvy = vy*speed;
   collisionWithScreenWalls();
   // update Position    
   x += tvx;
   y += tvy;

   ellipseMode(CENTER);
   ellipse(x,y,r*2,r*2);
 }

 void collisionWithScreenWalls(){
   //X
   if(x+tvx+r>width || x+tvx<r){
     vx=vx*-1;
   }

   //Y
   if(y+tvy+r>height || y+tvy<r){
     vy=vy*-1;
   }    
 }
}
//******************** code off
Re: OpenGL and speed problem
Reply #1 - Dec 13th, 2006, 8:02am
 
With your code i can run 2000 balls without problem.

You should check in your ATI's drivers settings, if Antialiasing is not activated over X2.

(tested on OS X 10.4.8, core2duo 2.33Ghz, 2GB of RAM and RADEON X1600XT 256MB)

I hope this can help.

Merry Christmas Wink
Page Index Toggle Pages: 1