We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
Page Index Toggle Pages: 1
accessing the g.smooth? (Read 2769 times)
accessing the g.smooth?
Oct 28th, 2005, 6:49pm
 
Hi there,

I'm writing a library and I'm trying to turn off temporarly the smooth in whatever PGraphics, for rendering certain things.

This is my piece of code but it doesn't seem to work:
Code:

// Save smoothing state and turn off
boolean smoothing = g.smooth;
if(smoothing){g.smooth=false;}

for(int i=0;i<this.countStrips();i++){
g.beginShape(g.TRIANGLE_STRIP);
for(int j=0;j<this.strips[i].vertices.length;j++){
g.vertex(this.strips[i].vertices[j].x,this.strips[i].vertices[j].y);
}
g.endShape();
}

// Restore the old smoothing state
if(smoothing){g.smooth=true;}


using smooth() and noSmooth() isn't an option since certain PGraphicsX don't accept these methods.

By the way Ben: just a phylosophical question, wouldn't it be better to not throw the exception when in P3D using smooth(), and just ignore it? I think that would make the same code work under different renderers.
Re: accessing the g.smooth?
Reply #1 - Oct 28th, 2005, 8:08pm
 
You can test for the renderer in a library by using parent.g.getClass().getName() (which is a string) and then if it contains PGraphics3 dont' mess with smooth, if it isn't then you can do parent.noSmooth()
Re: accessing the g.smooth?
Reply #2 - Oct 28th, 2005, 8:27pm
 
A more elegant method for checking would be to use Java's built in syntax:
Code:
if (!(parent.g instanceof PGraphics3)) 
parent.noSmooth();

Marcello
Re: accessing the g.smooth?
Reply #3 - Oct 28th, 2005, 8:35pm
 
Thanks a lot for the solutions.  I'll give them a try.

But Ben, the question about the exception thrown is still wondering in my head.

cheers
Re: accessing the g.smooth?
Reply #4 - Oct 30th, 2005, 1:37am
 
Ricard wrote on Oct 28th, 2005, 8:35pm:
But Ben, the question about the exception thrown is still wondering in my head.

because unless we throw an actual error, any sort of "warning" message goes unheeded. i.e. when we just printed warnings for the text() functions, we got a lot of questions about why fonts weren't showing up, even though the console had messages at least pointing to the problem.

have you tried putting the smooth/noSmooth calls inside a try/catch block

Code:
try {
gx.smooth();
} catch (Exception e) { } // ignore
Re: accessing the g.smooth?
Reply #5 - Oct 31st, 2005, 8:16pm
 
Well used the try catch method and works quite right.
But I found that g.smooth always returns false.  So I filed it as a bug and posted in the forum.
Re: accessing the g.smooth?
Reply #6 - Oct 31st, 2005, 11:45pm
 
thanks, got it fixed for 94.
Page Index Toggle Pages: 1