updated: Help texturing in 3D? quad_strip, triangle_fan

Hi all,

I am new to this site, however I am in a Processing course at my university. I am in the process of creating a scene to present to the class that includes a non-primitive 3D object, with one required aspect that I need to texture the object.

I decided to use drawCylinder, as well as QUAD_STRIP and TRIANGLE_FAN to get my desired shape. However, I am completely stuck on how I might texturize it.

I have looked through the book and even asked peers, but no luck. Can't figure out how to map the UV coordinates. Hoping someone on here can point me in the right direction. Any help would be GREATLY appreciated!

I was trying different things but it just ended up messing with the overall outcome of my scene so I decided to revert back to the original. My goal is to import a diamond texture in order to wrap the diamond shaped geometry. Apologies for the comments/notes.

Thanks so much. My code is below:

    PImage tex;

    void setup() {
      size(800, 600, P3D);
      tex = loadImage("diamond.png");

    void draw() {
      pointLight(255, 101, 0, width/2, height/2, 200); //point light
    //  lights(); //default lighting
      translate(width/2, height/2);
      rotateY(map(mouseX, 0, width, 0, PI));
      rotateZ(map(mouseY, 0, height, 0, -PI));
    //rotateX(map(mouseX-mouseY, 0, width, 0, PI*2)); //add wacky X rotation
      //stroke color
      //stroke weight
      fill(255, 255, 255);
      translate(0, -40, 0);

    //mouse triggers object mesh view
    if (mousePressed == true){ 
       stroke(random(0,255), random(0,255), random(0,255)); //stroke strobe
       noFill(); //mesh viewable

    drawCylinder(0, 150, 150, 8); // Draw a hexagonal base
    //drawCylinder(10, 180, 200, 16); // Draw a mix between a cylinder and a cone 
    //drawCylinder(70, 70, 120, 64); // Draw a cylinder
    //drawCylinder(0, 180, 200, 4); // Draw a pyramid

    void drawCylinder(float topRadius, float bottomRadius, float tall, int sides) {
      float angle = 0;
      float angleIncrement = TWO_PI / sides;

      // 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;


      // If it is not a cone, draw the circular top cap
    /*  if (topRadius != 0) {
        angle = 0;
        // Center point
        vertex(0, 0, 0);
        for (int i = 0; i < sides + 1; i++) {
          vertex(topRadius * cos(angle), 0, topRadius * sin(angle));
          angle += angleIncrement;
      // If it is not a cone, draw the circular bottom cap
      if (bottomRadius != 0) {
        angle = 0;
        // Center point
        vertex(0, tall, 0);
        for (int i = 0; i < sides+1; i++) {
          vertex(bottomRadius * cos(angle), tall, bottomRadius * sin(angle));
          angle += angleIncrement;



  • edited December 2015

    I've looked and read through the processing reference.. not looking for a free ride here. Literally don't know what else to do...

    Just like the last 2 lines in the syntax explanation I need to have a u, v coordinates.


        vertex(x, y)
        vertex(x, y, z)
        vertex(x, y, u, v)
        vertex(x, y, z, u, v)"

    But with the shape's vertex being angles, and dealing with cosine (Lines 48-49, 75) I don't physically understand how to plot the coordinates for the uv points. I even resized the image to be a power of 2 to see if that was the problem but it didn't help.

    If anyone can give me anything at all, even a hint it'd be better than what I have now. I've been on this all day, literally.


Sign In or Register to comment.