Need help on school project regarding UV mapping with texture images

edited November 2016 in GLSL / Shaders

I am having a hard time wrapping my head around how to set UV's for textures. Everytime I try to display shape with the texture it vanishes.

PImage iceCream;
PImage waffleCone;

PShape cone;
PShape cream;

PShader texlightShader;
PShader shader2;
PShader toon;

float angle;
boolean button = false;
//boolean button2 = false;
//boolean button3 = false;


void setup() {
  size(800, 800, P3D);
  iceCream = loadImage("cream.jpg");
  waffleCone = loadImage("waffle.jpg");

  texlightShader = loadShader("texlightfrag.glsl", "texlightvert.glsl");
  shader2 = loadShader("lightfrag.glsl", "lightvert.glsl");

  toon = loadShader("frag.glsl", "vert.glsl");
  toon.set("fraction", 1.0);

  //noLoop();
    frameRate(30);
}

void draw() {
  background(0);
  lights();
  translate(width / 2, height / 1.5);

  ////cameras
    rotateY(angle);
    //rotateX(map(mouseX, 0, width, 0, PI));
    //rotateY(map(mouseX, 0, width, 0, PI));
    rotateZ(map(height, 0, height, 0, -PI));



  ////lights
    //pointLight(255, 255, 255, width/2, height, 600);  
    directionalLight(255,255,255, -1, 0, 0);

    //float dirY = (mouseY / float(height) - 0.5) * 2;
    //float dirX = (mouseX / float(width) - 0.5) * 2;
    //directionalLight(204, 204, 204, -dirX, -dirY, -3);


  noStroke();
  fill(0, 0, 255);
  translate(0, -40, 0);

  ///buttons to be implemented later
  //if(!button) {shader(toon);} else {resetShader();}
  //if (!button2){noStroke();}else { stroke(0);


  if(!button) {
  //shader(toon); not working must troubleshoot
  resetShader();
  drawCylinder_noTex(10, 75, 250, 16);} 

  else {
  shader(texlightShader);
  cone = drawCylinder(10, 75, 250, 16, waffleCone); }

  //cone = drawCylinder(10, 75, 250, 16, waffleCone); 
  //drawCylinder_noTex(10, 75, 250, 16);

 angle += 0.01;
}

PShape drawCylinder(float topRadius, float bottomRadius, float tall, int sides, PImage tex) {
  textureMode(NORMAL);
  PShape sh = createShape();


  sh.beginShape(QUAD_STRIP);
  //sh.noStroke();
  sh.texture(tex);

  for (int i = 0; i < sides + 1; ++i) {
    float angle = 0;
    float angleIncrement = TWO_PI / sides;

    sh.vertex(topRadius*cos(angle), 0, topRadius*sin(angle), 0);
    sh.vertex(bottomRadius*cos(angle), tall, bottomRadius*sin(angle), 100);
    angle += angleIncrement;
  }
  sh.endShape();
  return sh;  

/*
  pushMatrix();

    //ice cream
    translate(0,height/3);
    sphere(75);
  popMatrix();

*/
}

void drawCylinder_noTex(float topRadius, float bottomRadius, float tall, int sides) {
  textureMode(NORMAL);
  createShape();

  float angle = 0;
  float angleIncrement = TWO_PI / sides;
  beginShape(QUAD_STRIP);
  //sh.texture(tex);

  for (int i = 0; i < sides + 1; ++i) {
    vertex(topRadius*cos(angle), 0, topRadius*sin(angle));
    vertex(bottomRadius*cos(angle), tall, bottomRadius*sin(angle));
    angle += angleIncrement;
  }
  endShape();

/*
  pushMatrix();

    //ice cream
    translate(0,height/3);
    sphere(75);
  popMatrix();
  */
}

void keyPressed()
  {
    if (key == 'b' || key == 'B') {button = !button;}
    //if (key == 'n' || key == 'N') {button2 = !button2;}  //future implementation
    //if (key == 'm' || key == 'M') {button3 = !button3;} //future implementation  
  }

Answers

Sign In or Register to comment.