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 › Setting an Image in Background???????
Page Index Toggle Pages: 1
Setting an Image in Background?????????????? (Read 3201 times)
Setting an Image in Background??????????????
May 29th, 2010, 2:50pm
 
hi
i've found troubles in setting an image as background in my application.
I'wrote a 3D application using opengl library for processing, it implements some 3D animation and I'd like to put an image as background so I've used background(image.jpg) function (both in set and draw method).
The problem is that this background hides all things appening in my window like it is in front of them, but shouldn't it be a background????
thanks for the attention

narciso
Re: Setting an Image in Background??????????????
Reply #1 - May 30th, 2010, 3:58am
 
Even though it's called background, this doesn't mean it automatically goes to the background. What happens depends on where/when you call background in your sketch. See these three examples...

1. Background is called once in setup, after that the drawing is accumulative.

Code:
void setup() {
 size(400,400);
 background(255,0,0);
}

void draw() {
 ellipse(mouseX,mouseY,50,50);
}


2. Background is called every time at the beginning of draw, thereby creating a 'clean slate'. In fact it is just drawing over everything that was drawn before.

Code:
void setup() {
 size(400,400);
}

void draw() {
 background(255,0,0);
 ellipse(mouseX,mouseY,50,50);
}


3. Background is called at the end of draw. This is perhaps what you are doing right now. It basically draws over everything that was just drawn in this draw cycle. The result is you only see the 'background'.

Code:
void setup() {
 size(400,400);
}

void draw() {
 ellipse(mouseX,mouseY,50,50);
 background(255,0,0);
}


So the solution to your problem is to call the background either once in setup or place it at the beginning of draw.
Re: Setting an Image in Background??????????????
Reply #2 - May 30th, 2010, 5:20am
 
these were my first thoughts. but thats not the problem...
i tested it as well...

just test it and change from p3d to opengl...
i have to admit that i dont know, why this happens.

Code:
import processing.opengl.*;



PImage img;
void setup() {
size(640,480,OPENGL);
smooth();
hint(ENABLE_DEPTH_SORT);
background(255);

img = loadImage("bg.jpg");
}

void draw() {
background(img);

pushMatrix();
translate(0,0,mouseX);
translate(width/2,height/2);
rotateX(HALF_PI/2);
rotateY(HALF_PI/2);


box(100);
popMatrix();

}


Re: Setting an Image in Background??????????????
Reply #3 - May 30th, 2010, 8:21am
 
Strange indeed.
This works though..

Code:
void draw() {

hint(DISABLE_DEPTH_TEST);
background(img);
hint(ENABLE_DEPTH_TEST);

pushMatrix();
translate(0,0,mouseX);
translate(width/2,height/2);
rotateX(HALF_PI/2);
rotateY(HALF_PI/2);
box(100);
popMatrix();

}
Re: Setting an Image in Background??????????????
Reply #4 - May 30th, 2010, 9:02am
 
it works!!!!
you're a genius !!!! Smiley (disable opengl depth test only for background, very good idea).

thanks
Re: Setting an Image in Background??????????????
Reply #5 - May 30th, 2010, 9:59am
 
Good one!
Page Index Toggle Pages: 1