简体   繁体   中英

What is a quick algorithm for converting a matrix of squares into a triangle strip?

Imagine having a 4x4 square, with 16 smaller squares inside of it, with associated data on what the squares should look like (ie., opacity, colour, etc...).

Is there an existing, efficient, algorithm, for converting this set of squares into an open-gl compatible triangle strip?

I am not sure I understand correctly the geometry you try to render. If it is a kind of grid here is how I would do it:

Create and fill a Vertex Buffer Object with all your vertices:

8--9--a--b
| /| /| /|
|/ |/ |/ |
4--5--6--7
| /| /| /|
|/ |/ |/ |
0--1--2--3

Create and fill an Element Array Buffer with the indices used to render your quad grid:

{ 0,1,5,4, 1,2,6,5, 2,3,7,6, 4,5,9,8, 5,6,a,9, 6,7,b,a }

Setup everything using gl*Pointer, use glDrawElements with GL_QUADS to render that. The vertex cache will handle the already transformed vertices: every quad after the first one will only require to transform 2 vertices.

I don't think you will gain anything if you tri-strip or quad-strip it, except some memory on the Element Array Buffer.

If you want to strip it, create the corresponding Element Array Buffer, and call glDrawElements for each line. This can be done in one call using the Nvidia only extension GL_NV_primitive_restart

If it isn't a grid, you can give a try to NvTriStrip .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM