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.
IndexProgramming Questions & HelpOpenGL and 3D Libraries › OPENGL with SVG(candy library)
Page Index Toggle Pages: 1
OPENGL with SVG(candy library)? (Read 2004 times)
OPENGL with SVG(candy library)?
Sep 10th, 2007, 6:04am
 
Hello
I have tried import SVG file in my sketch, i use the OPENGL render before import SVG file.
As soon as i try to use candy library with OPENGL library,
Nothing come up to my sketch, it seem to be freezen.

Anyone can help me? it is bit urgent.
Re: OPENGL with SVG(candy library)?
Reply #1 - Sep 12th, 2007, 4:34am
 
care to share a minimal example with svg attached?
Re: OPENGL with SVG(candy library)?
Reply #2 - Sep 12th, 2007, 7:17am
 
import processing.opengl.*;
import processing.candy.*;
import processing.xml.*;





SVG grass, hill_left, hill_right;

PFont font_meta11, font_meta24, font_meta14, font_meta12, font_meta10;

// basic information
int sw=1024;
int sh=768;

// counting for add object
int count=0;

// variable for detecting collision
int over;
int sameid;
int[] sidArray;
float targeup;

Nodeflower[] nodef;
UIset uset;


boolean initiation;
boolean saveb;
boolean startGui;

// UserArc active
boolean isActive;



// user input  variable array
int[] genderArray;
int[] ageArray;
int[] locationArray;
String[] nameArray;
String[] commentArray;
String[] emotionArray;
String[] shapeArray_s;
float[] shapeArray_00, shapeArray_01, shapeArray_02, shapeArray_03, shapeArray_04, shapeArray_05, shapeArray_06, shapeArray_07;
int[] rv,gv,bv;

// start button
Button start_b;



void setup(){
 size(sw,sh);
 noStroke();
 frameRate=30;
// smooth();
 
 grass = new SVG(this, "grass.svg");
 hill_left = new SVG(this, "hill_left.svg");
 hill_right = new SVG(this, "hill_right.svg");
 
 
 //basic
 initiation = true;
 startGui = false;
......................
..

I make the sketch with opengl render then i import Candy library like abvoe example.
when i run this sketch but frezen grey screen is all i get.

How can i use Candy library with Opengl library?

 
Re: OPENGL with SVG(candy library)?
Reply #3 - Sep 12th, 2007, 6:56pm
 
I don't think Candy will work as is with OpenGL, for a number of reasons.  Do you get an exception reported?  Like maybe strokeCap()/strokeJoin() not supported by OpenGL?  Then there's breakShape(), and the method used for gradients, etc, all of which don't map well to OpenGL.

About the best you could hope for is create an offscreen PGraphicsJava2D, alter SVG.java to take a reference to it, (and replace all calls like "papplet.g" with that reference), then render the SVG into the offscreen graphics, then use it as a texture in OpenGL.  It's quite a bit of work though.
Re: OPENGL with SVG(candy library)?
Reply #4 - Sep 18th, 2007, 10:33pm
 
Well, I'm experiencing the same thing right now.

Under OPENGL, fill shapes do not get anti-alias by default. You have to add a stroke to all your shapes in order to get smoothed edges.

However, there's currently a bug in Candy that doesn't allow strokes at all in OPENGL because it forces stroke caps and joins on you.

In the meanwhile, you can recompile SVG candy and comment out the stroke cap/join lines:

Code:

protected void drawStyles() {
parent.colorMode(PConstants.RGB, 255);

if (stroke) {
parent.stroke(strokeColor);
parent.strokeWeight(strokeWeight);

//parent.strokeCap(strokeCap);
//parent.strokeJoin(strokeJoin);
} else {
parent.noStroke();
}
...


It's tricky, if you don't know how to compile Java libraries, I admit. If so, you can wait for the next release, hopefully that will be fixed.
Re: OPENGL with SVG(candy library)?
Reply #5 - Sep 18th, 2007, 10:35pm
 
On the other hand, if it's OPENGL, I think candy should stroke using the fillcolor by default if there's no stroke, and smoothing is turned on. That way it will at least look as expected, turning on smooth.
Re: OPENGL with SVG(candy library)?
Reply #6 - Sep 19th, 2007, 9:21pm
 
>> It's tricky, if you don't know how to compile Java libraries

You can easily "hack" the built-in libraries by just copying the .java sources into your sketch folder and comment out the package statement, then just use them as part of your sketch (not as a library) and tweak source as desired.  Libraries are certainly nicer for the reusability, but this hack approach can work in a pinch.  Smiley
Re: OPENGL with SVG(candy library)?
Reply #7 - Sep 20th, 2007, 10:51am
 
Thank you for davbol and mflux. your answer is help me know why Candy library dose't work in OPENGL.But i don't have java education background. So your answer is a bit difficult for me. Can you give me introduction or example where and how to put the code you give me.
I keen to know how to implement these method to import svg file into my sketch.

Thank for your time.
All good happen will be with you.
Re: OPENGL with SVG(candy library)?
Reply #8 - Sep 21st, 2007, 7:02pm
 
Warning: non-kosher hackery follows...

Go to the folder where processing is installed, then into libraries\candy\src\processing\candy and copy those .java files into your sketch folder. (per docs they should go in a "code" subfolder, but this'll work)

Then start p5 and load your sketch - see the new tabs for the java files?  In each java file locate the "package" statement and either delete it or comment it out.  In your sketch, remove the candy import statement.

Now when you create an instance of the SVG() class you're creating a version from these local java files, not from the library code.  So you can now make the changes as suggested by mflux.
Re: OPENGL with SVG(candy library)?
Reply #9 - Sep 23rd, 2007, 9:53am
 
a little simpler than that, you should be able to import the library, and add a class to your sketch ala:

Code:

public class SVG2 extends SVG {
protected void drawStyles() {
// the new drawStyles code
}
}


this way you can leave the original library intact but only fix the necessary functions. you may also need to override the constructor as well to get it to work properly.

that said, the bug is filed so i'll get it fixed for the next release.
Page Index Toggle Pages: 1