OpenGL: problem with triangular stripes for 3d mesh and normals

I am new to opengl programming. I am currently doing an animation of the formation of a cave wall. I have a set of coordinates for shaft profiles along the z axis. My plan is to make a 3D grid from this data and for this I decided to use TRIANGLE_STRIPS. The way I did this is that I created several stripes:

  11 ---- 12 5 ------ 6
  |  / |  |  / |
  |  / |  |  / |
  9 ----- 10 3 ------ 4
  |  / |  |  / |
  |  / |  |  / |
  7 ------ 8 1 ------ 2

My questions:

  • Is this the right way to do this? Because now I have problems with normals. I would like to use the GL_SMOOTH shader, and for this, as I understand it, do I need to calculate vertex normals? But at my checkout, the vertices 10 and 3 are the same, so there would be two normals ??? This is problem? And is there another way to create multiple bands?

  • And is there another way to create multiple stripes? Or maybe the strip solution is not the best?

  • Another problem is that these stripes do not have the same length. Some of them are shorter than others. Thank you for your help:)

+8
opengl gl-triangle-strip
source share
2 answers

First, do not use triangular stripes. This and the old concept for old equipment. Use simple indexed triangles lists. It is simpler (at first) and faster. To your questions:

1) Each vertex has a normal. It is as unique and important as the position. If two vertices had a different position, they would be different vertices. The same applies to normals: there are vertices with the same position, but with different normals. But they are different peaks. Think about how vertices from a sphere differ from vertices in a cube.

2) Use lists (glDrawElements). Do not use strips. There are optimal ways to organize these caching lists, nvidia and ati have many code examples in their developer sections.

3) Do not worry about it. A good mesh will have approximately equal square triangles. Indexes are sorted to get to the cache top (usually at least 16 entries) most of the time. Stripes are an optimization method for a 2 vertex cache.

+6
source share

First, in your image the diagonals are actually upside down if the numbers represent the order of the vertices (but this is a small representation error).

  • This is the easiest and most suitable approach for removing a more or less uniform grid of vertices. You are right that 10 and 3 need the same normal condition, so you need to give them the same normal condition for proper lighting. In this case, indexing is your friend. Just use one vertex for 3 and 10 (with the corresponding normal) and use an indexed triangular strip where indices 3 and 10 refer to the same vertex. This is the standard way to solve vertex ambiguities. If you don’t know what I mean, go a little deeper into OpenGL and 3D programming in general, especially vertex and index arrays.

  • For regular grids, strips are often a good idea because they can be easily built. More complex grids are no longer required at this time, since it is often important to reduce the number of callbacks.

  • They should have at least a reasonable length compared to the total number of triangles, otherwise the overhead of drawing one strip just outweighs the time spent on a little faster processing of the vertices, but the actual numbers are very implementation dependent. You should use vertex arrays / buffers anyway, avoid start / end if you care about performance.

In fact, you can combine several bands into one by introducing degenerate triangles that are not displayed (to reduce the number of drawing calls). Your example may display as the following single bar:

1, 2, 3, 4, 5, 6, 6, 7 , 7, 8, 9, 10, 11, 12

But then again, keep the answer 3. in mind. The stripes should be of a reasonable size so that degenerate triangles do not overload real triangles too much.

+2
source share

All Articles