3d png texture collision
in
Programming Questions
•
2 years ago
Hello,
I was trying to do a rotating group of shapes, inspired from the brick tower example.
In my scketch, I'm applying texture from a png file, but some background shapes appears over frontground ones.
it's seems to be dependant of the order of drawing, but there is this problem only with png files, it's all right with jpg.
There is a simple example of this problem :
I was trying to do a rotating group of shapes, inspired from the brick tower example.
In my scketch, I'm applying texture from a png file, but some background shapes appears over frontground ones.
it's seems to be dependant of the order of drawing, but there is this problem only with png files, it's all right with jpg.
There is a simple example of this problem :
- PImage img_png, img_jpg;
- boolean value; //switch with mouse clic
- int foreGround, backGround; // z position
-
- void setup()
- {
- size( 600, 300, P3D );
-
- img_jpg = loadImage("http://www.michaelluis.fr/processing/test.jpg");
- img_png = loadImage("http://www.michaelluis.fr/processing/test.png");
- value = false;
- foreGround = 50;
- backGround = 100;
- }
-
- void draw()
- {
- background(127);
-
- if( value == false ) //draw first foreground, after background
- {
- beginShape( QUADS );
- texture( img_png );
-
- vertex( 100, 100, foreGround, 0, 0 );
- vertex( 200, 100, foreGround, 100, 0 );
- vertex( 200, 200, foreGround, 100, 100 );
- vertex( 100, 200, foreGround, 0, 100 );
-
- vertex( 100, 100, backGround, 0, 0 );
- vertex( 200, 100, backGround, 100, 0 );
- vertex( 200, 200, backGround, 100, 100 );
- vertex( 100, 200, backGround, 0, 100 );
-
- endShape();
-
- beginShape( QUADS );
- texture( img_jpg );
-
- vertex( 400, 100, foreGround, 0, 0 );
- vertex( 500, 100, foreGround, 100, 0 );
- vertex( 500, 200, foreGround, 100, 100 );
- vertex( 400, 200, foreGround, 0, 100 );
-
- vertex( 400, 100, backGround, 0, 0 );
- vertex( 500, 100, backGround, 100, 0 );
- vertex( 500, 200, backGround, 100, 100 );
- vertex( 400, 200, backGround, 0, 100 );
-
- endShape();
- }
- else //draw first background, after foreground
- {
- beginShape( QUADS );
- texture( img_png );
-
- vertex( 100, 100, backGround, 0, 0 );
- vertex( 200, 100, backGround, 100, 0 );
- vertex( 200, 200, backGround, 100, 100 );
- vertex( 100, 200, backGround, 0, 100 );
-
- vertex( 100, 100, foreGround, 0, 0 );
- vertex( 200, 100, foreGround, 100, 0 );
- vertex( 200, 200, foreGround, 100, 100 );
- vertex( 100, 200, foreGround, 0, 100 );
-
- endShape();
-
- beginShape( QUADS );
- texture( img_jpg );
-
- vertex( 400, 100, backGround, 0, 0 );
- vertex( 500, 100, backGround, 100, 0 );
- vertex( 500, 200, backGround, 100, 100 );
- vertex( 400, 200, backGround, 0, 100 );
-
- vertex( 400, 100, foreGround, 0, 0 );
- vertex( 500, 100, foreGround, 100, 0 );
- vertex( 500, 200, foreGround, 100, 100 );
- vertex( 400, 200, foreGround, 0, 100 );
-
- endShape();
- }
- }
-
- void mousePressed()
- {
- value = !value;
- }
1