Can't change color of the objects in the GLGraphics GLSL shader example
in
Contributed Library Questions
•
1 years ago
for some reason i can't change the color of the torus in the GLSLshader example see the code below:
- // Example of GLSL shader with GLGraphics.
- // Adapted from Vitamin's shaderlib:
- // http://www.pixelnerve.com/processing/libraries/shaderlib/
- // More online resources about GLSL:
- // http://nehe.gamedev.net/data/articles/article.asp?article=21
- // http://zach.in.tu-clausthal.de/teaching/cg_literatur/glsl_tutorial/index.html
- import processing.opengl.*;
- import codeanticode.glgraphics.*;
- GLModel torus;
- GLSLShader shader;
- float angle;
- void setup() {
- size(800, 600, GLConstants.GLGRAPHICS);
- torus = createTorus(100, 50, 20, 500, 0, 0, 255, 255, "");
- // Loading toon shader. Taken from here:
- // http://www.lighthouse3d.com/opengl/glsl/index.php?toon3
- shader = new GLSLShader(this, "toonvert.glsl", "toonfrag.glsl");
- }
- void draw() {
- GLGraphics renderer = (GLGraphics)g;
- renderer.beginGL();
- background(0);
- lights();
- // Centering the model in the screen.
- translate(width/2, height/2, 0);
- angle += 0.01;
- rotateY(angle);
- // The light is drawn after applying the translation and
- // rotation trasnformations, so it always shines on the
- // same side of the torus.
- pointLight(0, 160, 255, 0, 600, 400);
- shader.start(); // Enabling shader.
- // Any geometry drawn between the shader's stop() and end() will be
- // processed by the shader.
- torus.setColors(0, 160, 255, 255);
- renderer.model(torus);
- shader.stop(); // Disabling shader.
- renderer.endGL();
- }
- GLModel createTorus(float outerRad, float innerRad, int numc, int numt, int r, int g, int b, int a, String texName) {
- GLModel model;
- GLTexture tex;
- ArrayList vertices = new ArrayList();
- ArrayList normals = new ArrayList();
- ArrayList texcoords = new ArrayList();
- float x, y, z, s, t, u, v;
- float nx, ny, nz;
- float a1, a2;
- int idx = 0;
- for (int i = 0; i < numc; i++) {
- for (int j = 0; j <= numt; j++) {
- for (int k = 1; k >= 0; k--) {
- s = (i + k) % numc + 0.5;
- t = j % numt;
- u = s / numc;
- v = t / numt;
- a1 = s * TWO_PI / numc;
- a2 = t * TWO_PI / numt;
- x = (outerRad + innerRad * cos(a1)) * cos(a2);
- y = (outerRad + innerRad * cos(a1)) * sin(a2);
- z = innerRad * sin(a1);
- nx = cos(a1) * cos(a2);
- ny = cos(a1) * sin(a2);
- nz = sin(a1);
- vertices.add(new PVector(x, y, z));
- normals.add(new PVector(nx, ny, nz));
- texcoords.add(new PVector(u, v));
- }
- }
- }
- model = new GLModel(this, vertices.size(), QUAD_STRIP, GLModel.STATIC);
- model.updateVertices(vertices);
- if (texName != null && !texName.equals("")) {
- tex = new GLTexture(this, texName);
- model.initTextures(1);
- model.setTexture(0, tex);
- model.updateTexCoords(0, texcoords);
- }
- model.initNormals();
- model.updateNormals(normals);
- model.initColors();
- model.setColors(r, g, b, a);
- return model;
- }
can anyone help me figure this out? i've tried changing the pointLight color, the input values for the torus and tried hard coding in a color in the torus class. any help would be greatly appreciated
1