2015-11-01 68 views
3

我在OSX和Windows上都使用了处理3(和2)。屏外PGraphics缓冲区中的线性图形比直接画出的线条要粗糙得多。看起来形状边缘的抗锯齿效果不好。处理3离屏难看

你能帮我让离屏缓冲区图形更好吗?

exmple图像 ugly offscreen on the right, on-screen on the left

示例代码

PGraphics pg; 

void setup(){ 
    size (1024,768, P2D); 
    pixelDensity(2); 
    smooth(); 
    pg = createGraphics(width, height, P2D); 
    noLoop(); 
} 

void draw(){ 
    background (0); 
    pushMatrix(); 
    translate (width/2-100, height/2); 
    rotate (PI/6); 
    stroke(255); 
    noFill(); 
    strokeWeight(0.5); 
    rect (0,0,100,100); 
    popMatrix(); 

    pg.beginDraw(); 
    pg.smooth(); 
    pg.clear(); 
    pg.translate (width/2+100, height/2); 
    pg.rotate (PI/6); 
    pg.stroke(255); 
    pg.noFill(); 
    pg.strokeWeight(0.5); 
    pg.rect (0,0,100,100); 
    pg.endDraw(); 

    image(pg,0,0, width, height); 

    save("shot.png"); 
} 

谢谢!

该问题已被交叉处理论坛here

+0

请多个列表之间的链接:https://forum.processing.org/two/discussion/13355/offscreen-pgraphics-is-ugly –

回答

1

该问题是由默认处理启用反锯齿引起的。您可以通过调用smooth()函数明确地启用它,但请注意,这是无关的,因为它已默认启用。

这会导致您的线条在自己的颜色和背景颜色之间“模糊”。在屏幕缓冲区中,该背景颜色为黑色。在屏幕外的缓冲区中,背景颜色是透明的。这就是为什么你的屏外广场看起来更透明 - 因为它是。

要解决此问题,您需要通过调用noSmooth()来禁用消除锯齿功能,或者您需要确保您正在绘制相同的背景颜色。这里是noSmooth()方法:

PGraphics pg; 

void setup(){ 
    size (1024,768, P2D); 
    noSmooth(); 
    pg = createGraphics(width, height, P2D); 
    noLoop(); 
} 

void draw(){ 
    background (0); 
    pushMatrix(); 
    translate (width/2-100, height/2); 
    rotate (PI/6); 
    stroke(255); 
    noFill(); 
    strokeWeight(0.5); 
    rect (0,0,100,100); 
    popMatrix(); 

    pg.beginDraw(); 
    pg.noSmooth(); 
    pg.clear(); 
    pg.translate (width/2+100, height/2); 
    pg.rotate (PI/6); 
    pg.stroke(255); 
    pg.noFill(); 
    pg.strokeWeight(0.5); 
    pg.rect (0,0,100,100); 
    pg.endDraw(); 

    image(pg,0,0, width, height); 

} 

enter image description here