0

I want to paint a hex map with each hex a (potentially) different color. The shared border is black and the interior is a solid color. If I want to paint a 1920x1080 display, how can I do this the fastest way with OpenGL?

See the image below for a sample hex (blown up for clarity). The color of the hex won't necessarily be the same as any of the surrounding hexes.

Sample Hex With Black Border

genpfault
  • 51,148
  • 11
  • 85
  • 139
No One in Particular
  • 2,846
  • 4
  • 27
  • 32
  • How often will the hexes change color ? – Bahbar Apr 05 '11 at 07:01
  • @Bahbar: the color of the hex will change once per state change. The state can change based on several criteria: touch from user, AI moving things, etc. My main concern is to NOT have a lag if the AI changes a lot of hexes (possibly the whole screen). – No One in Particular Apr 11 '11 at 10:43

1 Answers1

2

A TRIANGLE_FAN would work quite well, since a hex is convex.

Fill the entire area with the border color, then render each hex as a TRIANGLE_FAN leaving a gap between adjacent hexes where the border color can show through.

Ben Voigt
  • 277,958
  • 43
  • 419
  • 720
  • Sorry, I put my comment in the wrong place. Here it is again for completeness. I read up on triangle_fans and I understand the concept. However, does it work with my particular border scheme. Take a look at the black pixels in the picture. Also, your picture doesn't have a straight line border, but an anti-aliased (or so it seems) border. How do these play into things? – No One in Particular Apr 05 '11 at 01:58
  • @No One: I didn't provide a picture. Anyway, if `GL_SMOOTH` is disabled, you should get pure colors as in your picture. If enabled, edges will be anti-aliased. – Ben Voigt Apr 05 '11 at 02:01
  • @Ben Voigt: I meant the original picture in my post. Notice that the black border lines are not contiguous, rather small line segments. – No One in Particular Apr 05 '11 at 02:03
  • @No One: I just told you, you can control that with `GL_SMOOTH`. Shouldn't matter whether you are drawing lines or, as I suggested, leaving gaps between the hexes and allowing a solid background to show through. `glDisable(GL_SMOOTH);` will get you the aliased lines you are looking for. – Ben Voigt Apr 05 '11 at 02:07
  • @No One in Particular: Are you saying you actually *want* the aliased lines? – Marcelo Cantos Apr 05 '11 at 02:09