Loading...
Logo
Processing Forum

2D render Problem in 2.0

in Programming Questions  •  4 months ago  
Hi all, 

I was working in 1.51 version and everything worked well, However I switched to 2.0 9b recently, and several problem occurs here. 

I am using floodfill method to fill 2D image, when I use P2D as renderer 
pgFill = createGraphics(width0, height0,P2D); 
there comes a blue bar on the right side of the image(blue is the background color I defined in the first profile drawing).
The same situation happens when I use P3D and OPENGL as render



and sometimes this occurs

The original image should be


Can anybody help me with this please??

Replies(7)

You could also help us to help you by posting the anti-beta 9 rebelling code!

Processing 2+ uses 2 "real" engines only -> either JAVA2D or OPENGL.
And its OPENGL version is newer than v1.5.1's.
Also, the old P2D & PD3 engines are emulated through this new OPENGL.

Take notice that this recent 2.0b9 version is very buggy.
Perhaps you could also try previous 2.0b8 one.
It worked , but it seems that it keep accumulating the information. It become slower and slower until  out of memory comes in the end, which didn`t happen in 1.51.

According to   http://wiki.processing.org/w/Changes P2D should already be using OPENGL, am I missing anything?

Sorry, I don`t see what you mean by  anti-beta 9 rebelling code.
  PGraphics pgFill;
  int iIF, iPF, iVF, iUF;

  floodFill0(PGraphics pG) {
    pgFill = pG;
    iIF = fillColors.colorIF;
    iPF = fillColors.colorPF;
    iVF = fillColors.colorVF;
    iUF = fillColors.colorUF;
  }

  void fillEnclosedAreas(String nom,boolean output) {
    int ix, iy;
    int ifx = 0;
    int ify = 0;

    pgFill = createGraphics(width0, height0,P2D);
    pgFill.beginDraw();
    pgFill.background(cFiller0.iUF);
    pgFill.strokeWeight(1);             
    pgFill.translate((float)width0/2+offsetX, (float)height0/2+offsetY);
    pgFill.scale(10.24/defaultScaleRate*zoom);
    for (int i=0; i<listOfPoints.size(); i+=4) {
      try {
        pgFill.stroke(cFiller0.iPF);
        pgFill.line(listOfPoints.get(i).floatValue(), listOfPoints.get(i+1).floatValue(), listOfPoints.get(i+2).floatValue(), listOfPoints.get(i+3).floatValue());
      }
      catch(Exception e) { 
        println("pbm");
      }
    }
    for (int i=0; i<listOfTriangles.size(); i+=6) {
      try {
        pgFill.fill(cFiller0.iPF);
        pgFill.triangle(listOfTriangles.get(i).floatValue(), listOfTriangles.get(i+1).floatValue(), listOfTriangles.get(i+2).floatValue(), listOfTriangles.get(i+3).floatValue(), listOfTriangles.get(i+4).floatValue(), listOfTriangles.get(i+5).floatValue());
      }
      catch(Exception e) {
      }
    }

    pgFill.loadPixels();

    for (iy=0;iy<pgFill.height-1;iy++) {
      if (iy==0 || iy==pgFill.height-1) {
        for (ix=0;ix<pgFill.width-1;ix++) {
          //top or bottom row
          if (pgFill.pixels[getIndex(ix, iy)] == iUF) floodFill(ix, iy, iVF);
          pgFill.updatePixels();
        }
      }
      else 
      {
        if (pgFill.pixels[getIndex(0, iy)] == iUF) floodFill(0, iy, iVF);
        if (pgFill.pixels[getIndex(pgFill.width-1, iy)] == iUF) floodFill(pgFill.width-1, iy, iVF);
        pgFill.updatePixels();
      }
    }

    for (iy=0; iy<pgFill.height-1; iy++)
      for (ix=0; ix<pgFill.width-1; ix++) fillIfNeeded(ix, iy, true);

    for (iy=pgFill.height-1; iy>=0; iy--)
      for (ix=pgFill.width-1; ix>=0; ix--) fillIfNeeded(ix, iy, false);  

    for (iy=0;iy<pgFill.height-1;iy++) {
      for (ix=0;ix<pgFill.width-1;ix++) {
        if (pgFill.pixels[getIndex(ix, iy)] == iUF)
          pgFill.pixels[getIndex(ix, iy)] = iVF;
        else if (pgFill.pixels[getIndex(ix, iy)] == iPF)
          pgFill.pixels[getIndex(ix, iy)] = iIF;
      }
    }
    pgFill.updatePixels();
    pgFill.endDraw();
      
      image(pgFill,(width/6.4-width0/11),20,width0/5,height0/5);
      pgFill.flush();

" P2D should already be using OPENGL, am I missing anything?"
In 1.5.1, P2D was a special bitmap mode, faster than JAVA2D in general.
In 2.0, it became an OpenGL mode. That's what GoToLoop meant.

But don't follow the "use 2.0b8 instead of 2.0b9" advice. I don't know what are the supposed new bugs the latter introduces, but it also solves lot of problems, like the OutOfMemoryError you see...
2.0 b7 GL2 didn`t work for me
2.0 b8 runs super slow, I don`t know if it clear its memory every frame, 
2.0 b9 the 2D image is buggy

Should I go back to 1.51 ?? at least it worked and not even slower than 2.0 b9
" Should I go back to 1.51 ?"
Personally, I have both 1.5.1 (and even a 1.2.1!) and 2.0b9 (and b8) installed (really, just unzipped), side by side, and so I can use whichever version I want / need anytime.
I rarely, if ever, use P2D or OpenGL, so perhaps I missed the issues mentioned by GoToLoop (but haven't seen much reported either).
BTW, P2D is almost deprecated, and indeed full of issues, so why do you use it in 2.0?

Note: I see you use try / catch, they are rarely, if ever, needed in pure Processing sketches...
Actually I have them both installed as well, and it was working pretty well in 1.51. But I want to use the fullScreen function in 2.0, which is not that convenient for me, and I assumed that 2.0 should be more powerful.  In addition,  I have another part of the project written in 2.0, I am trying to upgrade this to 2.0,  so they can be combined. 2.0 b9 is working pretty well actually,  if not for the 2D bug. But it works no better than 1.51, to my observation.