0

In processing you can create 3D shapes quite easily by just giving vertex positions in a certain order.

Example for a simple square:

beginShape();// QUAD would work as parameter
vertex(10,10);
vertex(20,10);
vertex(20,20);
vertex(10,20);
endShape();

What I am wondering is if I want to create multiple quads that forms a bigger square(ie some of the quads share corners), should I create the smaller quads by themselves and thus create overlapping vertices or is there a way to just define the vertices that I then can use for multiple quads without creating new ones at the same position?

Example:

X:1,  2   
+---+---+ Y:
|   |   |
|   |   | 1,
+---o---/
|   |   |
|   |   | 2
+---+---+

The middle corner shared between all the quads (marked 'o') will have 4 vertices overlapping from all the neighbouring quads. The rightmost middle vertex point (marked '/') will have 2 vertices overlapping from the quads at (2,1) and (2,2)

Isn't this very inefficient when it comes to vertexcount?

This might be the way OpenGL works but in my mind this does not seem very efficient, if I'm wrong please tell me.

tshepang
  • 12,111
  • 21
  • 91
  • 136
Patrick Dahlin
  • 286
  • 2
  • 5
  • 19

2 Answers2

2

What you're describing is the original method of drawing vertices in OpenGL 1.0. There have been more efficient methods since the OpenGL 1.1 spec, which was released in 1997. Check out API calls like glDrawElements, which allows you to use vertex indices.

Reto Koradi
  • 53,228
  • 8
  • 93
  • 133
  • I might look into that but since I am using processing I'd like to use the built in vertex and beginShape functions. This would though seem like an simple one-liner to draw the whole shape without using an PShape but does this mean worse performance since the object isnt loaded into memory in the same way as an PShape? – Patrick Dahlin May 02 '14 at 10:52
0

What you want is known as a Quad Strip primitive.

You supply your vertices in a special order, and it will re-use 2 of the 4 vertices that made up the adjacent quad. The proper order for vertices in a strip is such that each odd primitive is wound in reverse. Strips are designed for connected geometry, if you want to draw unconnected quads using a quad strip you have to do something called "primitive restart."

Of course quads are deprecated in modern OpenGL; triangles support the very same concept. In fact, a single non-stripped quad has the same vertex order as a triangle strip that fills the same area.

You can also use indexed drawing, where you reference the vertices for each primitive by their ID. This requires additional storage of an array of indices, but it does have the added benefit of allowing you to re-use vertices in meshes that are not a series of connected primitives.

Andon M. Coleman
  • 42,359
  • 2
  • 81
  • 106
  • If making an array of 3D vectors for each vertex would fix my problem then I surely will try it out. And as you said, QUADs and QUAD_STRIPs are deprecated and I would like to stay to supported/modern features. – Patrick Dahlin May 02 '14 at 10:48