strange effect after using OPENGL

edited December 2013 in Questions about Code

hi guys, i wrote some code about a circle(or like the watch) to show the month, for example: at 6 o'clock is june, so at 12 o'clock is december, every thing is fine, until i realized the antialiasing, so i used OPENGL in the size(width, height, OPENGL), then i found the month-clock is broken at 3 o'clock. any idea?

    import processing.opengl.*;
    int radius, thickness;
    PImage img;
    PGraphics testPG;

    void setup(){
      size(displayWidth, displayHeight, OPENGL);
      background(80);

    }

    void draw(){
      testPG = createGraphics(displayWidth, displayHeight, OPENGL);
      testPG.beginDraw();
      testPG.noFill();
      radius = 175;
      thickness = 35;
      elevation = 40;
      testPG.strokeWeight(thickness);

      testPG.arc(200, 200, radius, radius, -PI/2, month()*TWO_PI/12-PI/2);

      testPG.endDraw();

      img = testPG.get(0,0,displayWidth, displayHeight);
      image(img, 0, 0);

    }

Answers

  • Sorry I can't help you with the opengl problem, but image() will take a PImage or a PGraphcis object. You don't need to convert them.

  • I have to use the Image, because I have to add some SVG file on the foreground, without Image, the SVG files will just stay in the background.

  • edited January 2014

    What exactly do you mean with broken?

    Does the following code fix your problem?

    import processing.opengl.*;
    
    int radius = 175;
    int thickness = 35;
    int elevation = 40;
    PGraphics testPG;
    
    void setup(){
    
      size(400, 400, P2D); // Don't use OPENGL unless you have to, it doesn't support many of processing's drawing abilities
      background(80);
    
      // Don't create a PGraphics object at runtime unless you absolutely have to
      testPG = createGraphics(400, 400, P2D);
      testPG.beginDraw();
      testPG.smooth(4); // testPG.noSmooth(); // In case you want aliased edges
      testPG.strokeCap(SQUARE);
      testPG.noFill();
      testPG.endDraw();
    
    }
    
    void draw(){
    
      testPG.beginDraw();
      testPG.strokeWeight(thickness);
      testPG.arc(200, 200, radius, radius, -HALF_PI, TWO_PI / 12.0 * month() - HALF_PI);
      testPG.endDraw();
    
      // Just draw the PGraphics object, no need to "convert" it to an image (like Winchestro wrote)
      image(testPG, 0, 0);
    
    }
    

    Btw.: If you want to run your applet in fullscreen mode, just add the following function to your sketch:

    boolean sketchFullScreen() {
        return true;
    }
    
  • image alt text Hmm, i just have the Problem wenn december, it is jan, so everything looks fine

Sign In or Register to comment.