Best way to draw hexes and texture them?

What’s the best way to draw hexagonals:

  1. 1 GL_QUAD and 2 GL_TRIANGLEs ?
  2. 6 GL_TRIANGLE_FANS ?
  3. 1 GL_POLYGON with 7 vertices ?
  4. Other?

I’m creating a hex map and want to apply a texture image to it. Does the use of a texure affect choices above? Is there any way to apply a single texture to cover a set of polygons rather than 1 texture per polygon?

First, how would 6 GL_TRIANGLE_FANS be a single hex? a single GL_TRIANGLE_FAN would make a hex, granted that the center of the hex is a vertex.

There are two possibilities. Which you use depends on you texturing/color needs.

You could be rendering a hexmap with a single texture overlayed over the entire map. If so, you should use triangle strips. Because the mesh is continuous, a hexmap should strip very well.

However, if each hexagon needs to have a separate texture (and therefore separate texture coordinates) or each hexagon is at a different height, and is therefore discontinuous, then you should use a single GL_TRIANGLE_FAN for each hex. You should also sort the hexes by texture to minimize texture binds.

my suggestion is using GL_TRIANGLE_STRIP:

  1. Quad + 2 Triangles : 4 + 2 * 3 = 10 vertices

  2. Trianglefan: 1 (center) + 6 = 7 vertices

  3. 1 Polygon: 6 vertices, but probaly slow

  4. TriangleStrip: 6 vertices

    3----5
    / |\ |
    1 | \ | 6
    \ | \ | /
    2----4
    (hope this looks right)

[edit]
no, it doesn’t, but i hope u got the point
[/edit]

[This message has been edited by Tron (edited 06-19-2001).]

GL_TRIANGLE_FAN and GL_POLYGON are the only 2 real options. GL_TRIANGLE_STRIP is totally pointless since the other 2 are FAR easier. GL_QUADS is impossible since a hex aint got 4 sides
For TRIANGLE FAN specify the first vertex as the center of the hex and the rest the outside vertices.

Originally posted by Korval:
First, how would 6 GL_TRIANGLE_FANS be a single hex? a single GL_TRIANGLE_FAN would make a hex, granted that the center of the hex is a vertex…

Sorry, you are correct. I meant to say 1 GL_TRIANGLE_FAN with center vertex and 7 vertices.

You could be rendering a hexmap with a single texture overlayed over the entire map. If so, you should use triangle strips. Because the mesh is continuous, a hexmap should strip very well.[/QUOTE]

This is a valuable insight. That’s exactly what I have in mind. Thanks.

I find GL_Polygons fairly fast and sometimes better than a tri-fan or tri-strip! It should be failry easy to implement all of these suggestions to work out the fastest for you (and hopefully everyone else).

Originally posted by Tim Stirling:
I find GL_Polygons fairly fast and sometimes better than a tri-fan or tri-strip.

I think you’re right. Creating a continuous mesh of hexagons using tri-strips is more difficult than it sounds. Using 6-sided polys to create the individual hexes and then apply a texture image with hexagonal transparency mask to each poly is pretty straight forward. Simplicity of this coding approach may offset any performance penalties. Just out of curiosity, does anyone have code or algortithm to produce continous mesh of hexagons using GL_TRIANGLE_STRIP?


GL_TRIANGLE_FAN and GL_POLYGON are the only 2 real options. GL_TRIANGLE_STRIP is totally pointless since the other 2 are FAR easier. GL_QUADS is impossible since a hex aint got 4 sides
For TRIANGLE FAN specify the first vertex as the center of the hex and the rest the outside vertices.

TRIANGLE_FAN needs 7 vertices (center + 6 corners)
TRIANGLE_STRIP only needs 6 (6 corners)
=> TRIANGLE_STRIP


I think you’re right. Creating a continuous mesh of hexagons using tri-strips is more difficult than it sounds. Using 6-sided polys to create the individual hexes and then apply a texture image with hexagonal transparency mask to each poly is pretty straight forward. Simplicity of this coding approach may offset any performance penalties. Just out of curiosity, does anyone have code or algortithm to produce continous mesh of hexagons using GL_TRIANGLE_STRIP?

since TRIANGLE_FAN is no option (see above)
TRIANGLE_STRIP and POLYGON remain
i don’t know if 1 poly is really slower than 1 tri-strip (i guess so, 'cause poly is seldom used => bad [=slow] implementation AND the order of vertices has to be rearrenged (slow) by the driver, if it draws the poly internally as tris)

BUT u can only produce 1 poly with 1 begin-end, with tri-strip u can generate a diagonal of hexes (see the scheme below), so every following hex only needs 4 vertices (given the texture is spread among several hexes)

    7---9
   /|\  |\

3—5 | \ | 10
/|\ || |/
1 | \ | 6—8
| |/
2—4

(hope it looks correct this time)

btw: it’s in no way more complicated to texture a tri-strip than a poly, only the order of vertices (and tex-coords) is different

=> i’d use tris, 'cause AT LEAST they’re as fast as a poly (if not faster)

[This message has been edited by Tron (edited 06-21-2001).]

Originally posted by Tron:
[b]----------
with tri-strip u can generate a diagonal of hexes (see the scheme below), so every following hex only needs 4 vertices (given the texture is spread among several hexes)

[quote]

    7---9
   /|\  |\

3—5 | \ | 10
/|\ || |/
1 | \ | 6—8
| |/
2—4

btw: it’s in no way more complicated to texture a tri-strip than a poly[/b][/QUOTE]

Thanks for the reply Tron. Just to draw a single diagonal, row or column of hexes does me little good. I need a continuous mesh of hex rows and columns if I want to apply a single texture image. I’m still confused on how tri-strips would handle the end of row or column, when in effect the tri-strips have to “change direction”. In short, thinking about tri-strips gives me a headache! <g> Polys and tri-fans are convenient because they dont have a relationship to any previously drawn shapes.

Originally posted by RJH:

Thanks for the reply Tron. Just to draw a single diagonal, row or column of hexes does me little good. I need a continuous mesh of hex rows and columns if I want to apply a single texture image. I’m still confused on how tri-strips would handle the end of row or column, when in effect the tri-strips have to “change direction”. In short, thinking about tri-strips gives me a headache! <g> Polys and tri-fans are convenient because they dont have a relationship to any previously drawn shapes.

i know what u mean! remeber: every other triangle the last 2 vertices get flipped:
1-2-3
3-2-4
3-4-5
5-4-6

of course u have to draw multiple diagonals, i don’t think it’s possible to draw ha hexmap in one “run”

It probably isn’t possible to draw it all in one run, but drawing a whole load of strips is most definitely faster than drawing all of them individualy in any form. Remember that all you are trying to do here is limit the number of verticies that you have to send to the graphics card, as the real prolem with most graphics cards is memory speed (in short the fewer verticies the better), it’s a little more complicated than this when you start texturing, but not very much.