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 › PImage in an OPENGL applet
Page Index Toggle Pages: 1
PImage in an OPENGL applet (Read 490 times)
PImage in an OPENGL applet
Dec 27th, 2007, 10:50pm
 
Hi guys. This is my first post. I'm a newbie in Processing and I have a big problem. All export possibilities don't work. If I save it as an applet, I get the message "Loading Processing Software..."in my browser's statusbar, but it seems frozen. Is my applet too big or what else could it be? Maybe I made a big and stupid mistake, but I have no clue.

Thank you in advance for your help : D


I have this code:


import processing.opengl.*;

float a_rotspeed;
float b_rotspeed;

void setup(){
 size(500,500,OPENGL);
 background(255);
 frameRate(90);
 }

//BILDER-----------------------------------------------------

void brille(){  
 PImage brille;
 brille = loadImage("brille.png");
 pushMatrix();
 image(brille,0,0);
 translate(0,0,0);
   
 popMatrix();
 }
 
void sebo(){    
 PImage sebo;
 sebo = loadImage("sebo.jpg");
 pushMatrix();
 translate(100,0,-10);
 rotateY(PI/2);
 image(sebo,0,0);
 popMatrix();
 }
 
void ikarus(){    
 PImage ikarus;
 ikarus = loadImage("ikarus1.gif");
 pushMatrix();
 translate(20,-50,-150);
 rotateY(PI/-2);
 //rotateX(PI);
 image(ikarus,0,0);
 popMatrix();
 }
 
void shishi(){
 PImage shishi;
 shishi = loadImage("shishi.gif");

 //rotateX(PI);
 //rotateY(PI);
 //rotateZ(PI/2);
 pushMatrix();
 translate(-120,-50,10);
 image(shishi,0,0);
 popMatrix();
 }
 
//-------------------------------------------------

void draw(){
 noFill();
 background(255);
 //ANFANG BOX UND BEWEGUNG---------------------
 pushMatrix();
 translate(width/2,height/2);
 rotateX(a_rotspeed);
 rotateY(b_rotspeed);
 stroke(150,80);
 box(250);
 a_rotspeed+=0.009;
 b_rotspeed+=0.008;
 //ENDE BOX UND BEWEGUNG-----------------------

 brille();
 sebo();
 ikarus();
 shishi();
 popMatrix();
 
}
Re: PImage in an OPENGL applet
Reply #1 - Dec 28th, 2007, 10:02pm
 
The applet isn't to big but you load every image in every draw loop and thats not so good. One right way is to load all images in the setup method and store them as global variables.
Code:

PImage brille, sebo, ikarus ...;

void setup(){
brille=loadImage("brille.png");
.
.
}

void brille(){
pushMatrix();
image(brille,0,0);
translate(0,0,0);
popMatrix();
}



Another way would be to create a class, cause all your different function does mostly the same things only with different settings.

Code:


class Bild{
PImage myImage;
float translatex,translatey, translatez;

Bild(String myImageName, float translatex, float translatey, float translatez){
this.myImage=loadImage(myImageName);
this.translatex=translatex;
this.translatey=translatey;
this.translatez=translatez;
}

void drawMe(){
pushMatrix();
translate(translatex,translatey, translatez);
rotateY(PI/2);
image(myImage,0,0);
popMatrix();
}
}
Page Index Toggle Pages: 1