Lately I’ve been casually working through Daniel Shiffman’s book Learning Processing, to better familiarize myself with Processing.
I was working on exercise 14-5 in the book: “Create a three-dimensional cube using eight quads — beginShape(QUADS)”.
My idea was to create a quad in the xy-plane, and then to translate and rotate the quad six times to generate the cube. Although when I tried this, I encountered a strange problem.
When I try to translate the quad using push/popMatrix(), the quad gets drawn twice, once at the origin, and once to where I translated the quad. If I comment out the push/popMatrix() lines, the quad only gets drawn once.
I don’t understand why this happens. So, I was hoping someone here can help me understand.
In general vertex is more flexible. You can have 3, 4, 5, 6, or 100 points, whereas quad has four. Also, if you are having many tiles – like a quad strip – then you can do it manually with vertex, or you can arrange your vertex data using the QUAD_STRIP feature of PShape / beginShape… if you have a lot of point data then this may end up being much more efficient to render as a surface / object rather than drawing a separate quad() 100 times, and it is often easier to code something that moves along stitching sets of coordinates rather than breaking it down into individual shapes.
Still, there is nothing wrong with using quad – its just that most of the documentation and examples jump straight from rect to vertex, as you say.
quad() also uses (by default) beginShape() and endShape() internally. That you are causing endShape() to be called twice in a row, before and after matrix change, is probably why you see it drawn twice.