Loading...
Logo
Processing Forum
michaelluis's Profile
1 Posts
1 Responses
0 Followers

Activity Trend

Last 30 days
Show:
Private Message
    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 :

    1. PImage img_png, img_jpg;     
    2. boolean value;                          //switch with mouse clic
    3. int foreGround, backGround;      // z position

    4. void setup()
    5. {
    6.   size( 600, 300, P3D );

    7.   img_jpg = loadImage("http://www.michaelluis.fr/processing/test.jpg");
    8.   img_png = loadImage("http://www.michaelluis.fr/processing/test.png");
    9.   value = false;
    10.   foreGround = 50;
    11.   backGround = 100;
    12. }

    13. void draw()
    14. {
    15.   background(127);

    16.   if( value == false )    //draw first foreground, after background
    17.   {
    18.     beginShape( QUADS );
    19.     texture( img_png );

    20.     vertex( 100, 100, foreGround, 0, 0 );
    21.     vertex( 200, 100, foreGround, 100, 0 );
    22.     vertex( 200, 200, foreGround, 100, 100 );
    23.     vertex( 100, 200, foreGround, 0, 100 );
    24.  
    25.     vertex( 100, 100, backGround, 0, 0 );
    26.     vertex( 200, 100, backGround, 100, 0 );
    27.     vertex( 200, 200, backGround, 100, 100 );
    28.     vertex( 100, 200, backGround, 0, 100 );
    29.  
    30.     endShape();
    31.    
    32.     beginShape( QUADS );
    33.     texture( img_jpg );
    34.    
    35.     vertex( 400, 100, foreGround, 0, 0 );
    36.     vertex( 500, 100, foreGround, 100, 0 );
    37.     vertex( 500, 200, foreGround, 100, 100 );
    38.     vertex( 400, 200, foreGround, 0, 100 );
    39.  
    40.     vertex( 400, 100, backGround, 0, 0 );
    41.     vertex( 500, 100, backGround, 100, 0 );
    42.     vertex( 500, 200, backGround, 100, 100 );
    43.     vertex( 400, 200, backGround, 0, 100 );
    44.  
    45.     endShape();
    46.   }
    47.   else                //draw first background, after foreground
    48.   {
    49.     beginShape( QUADS );
    50.     texture( img_png );
    51.   
    52.     vertex( 100, 100, backGround, 0, 0 );
    53.     vertex( 200, 100, backGround, 100, 0 );
    54.     vertex( 200, 200, backGround, 100, 100 );
    55.     vertex( 100, 200, backGround, 0, 100 );
    56.    
    57.     vertex( 100, 100, foreGround, 0, 0 );
    58.     vertex( 200, 100, foreGround, 100, 0 );
    59.     vertex( 200, 200, foreGround, 100, 100 );
    60.     vertex( 100, 200, foreGround, 0, 100 );
    61.    
    62.     endShape();
    63.  
    64.     beginShape( QUADS );
    65.     texture( img_jpg );
    66.    
    67.     vertex( 400, 100, backGround, 0, 0 );
    68.     vertex( 500, 100, backGround, 100, 0 );
    69.     vertex( 500, 200, backGround, 100, 100 );
    70.     vertex( 400, 200, backGround, 0, 100 );
    71.    
    72.     vertex( 400, 100, foreGround, 0, 0 );
    73.     vertex( 500, 100, foreGround, 100, 0 );
    74.     vertex( 500, 200, foreGround, 100, 100 );
    75.     vertex( 400, 200, foreGround, 0, 100 );
    76.  
    77.     endShape();
    78.   }
    79. }

    80. void mousePressed()
    81. {
    82.   value = !value;
    83. }
    So, must I obligatory check the order of drawing or is it an easier way to fix it ?