Shading PShape
in
Core Library Questions
•
8 months ago
hey everybody.
i want to use shaders on a pshape object within processing 2. i got a sketch running which is doing the same thing in processing 1.5 with the glgraphics library:
the important parts of the code look like that:
- import codeanticode.glgraphics.*;
- import processing.opengl.*;
- import peasy.*;
- GLSLShader shader;
- GLModel torus;
- PeasyCam cam;
- void setup()
- {
- size(800, 600, GLConstants.GLGRAPHICS);
- // one-shot shader load and initialise
- shader = new GLSLShader(this, "check.vs", "check.fs");
- // simple camera handling
- cam = new PeasyCam(this, 150);
- torus = createTorus(40, 20, 20, 100, 200, 0, 150, 255, "");
- }
- void draw()
- {
- // explicitly start using OpenGL render stack
- // needed for the native GL commands in the torus rendering
- GLGraphics renderer = (GLGraphics) g;
- renderer.beginGL();
- background(50);
- // start shader processing -- anything between start() and stop()
- // will be handled by our new vertex/fragment shaders.
- shader.start();
- // render a donut object
- renderer.model(torus);
- // stop shader processing
- shader.stop();
- renderer.endGL();
- }
I read that the equivalent object of the 1.5 GLModel is PShape(3D) in 2.0 but i could not get it to work. The code of my processing 2 code to do the same looks like that:
- import processing.opengl.*;
- import toxi.geom.Vec3D;
- import peasy.*;
- PShader shader;
- PShape torus;
- PeasyCam cam;
- void setup()
- {
- size(800, 600, P3D);
- // one-shot shader load and initialise
- shader = loadShader("check.fs", "check.vs");
- // simple camera handling
- cam = new PeasyCam(this, 150);
- torus = createTorus( 40, 40, 40, 40, 40, 40);
- }
- void draw()
- {
- PGraphicsOpenGL gl = (PGraphicsOpenGL) g;
- PGL pgl = gl.beginPGL();
- shader(shader);
- background(50);
- // start shader processing -- anything between start() and stop()
- // will be handled by our new vertex/fragment shaders.
- //shader.start();
- // render a donut object
- //renderer.model(torus);
- shape(torus);
- // stop shader processing
- //shader.stop();
- //renderer.endGL();
- }
i put both sketches here, maybe somebody can figure out to reproduce the stripe-shader on a pshape in processing 2!
cheers,
marcel
1