Map of US states

Hi everyone,

I am new to OpenGL, and I need some advice for a project I am working on for one of my classes. My objective is to create a map of new england. It should look something like this picture:

I’ve been able to create some flags for the first part of our assignments, however I accomplished this by only using normal shapes.

This is my code for the flag:



#include <iostream>
//#include <GL/glut.h>
#include <glut/glut.h>

using namespace std; 

void display()
{
  double sin(double), cos(double);
  glClear(GL_COLOR_BUFFER_BIT);
  glBegin(GL_POLYGON);
  glColor3f(0.0, 0.80, 0.40);
  glVertex2f(-1.0, -1.0);
  glVertex2f(-1.0, 1.0);
  glVertex2f(0.0, 1.0);
  glVertex2f(0.0, -1.0);
  glEnd();

  glColor3f(1.0, 0.0, 0.0);
  glBegin(GL_POLYGON);
  for (int i=0; i<100; i++)
    {
      glVertex2f(0.29*sin(2*3.1415926*i/100), 0.5*cos(2*3.1415926*i/100));
    }
  glEnd();

  glColor3f(1.0, 1.0, 1.0);
  glBegin(GL_POLYGON);
  for (int i=0; i<100; i++)
    {
      glVertex2f(0.09 + 0.22*sin(2*3.1415926*i/100), 0.37*cos(2*3.1415926*i/100));
    }
  glEnd();

  
   glColor3f(0.0, 0.80, 0.40);
  glBegin(GL_POLYGON);
  for (int i=0; i<100; i++)
    {
      glVertex2f(0.15*sin(-3.1415926*i/100), 0.33*cos(-3.1415926*i/100));
    }
  glEnd();
  

   glColor3f(1.0, 0.0, 0.0);

glBegin(GL_TRIANGLES);

  glVertex2f(0.0, 0.14);
  
  glVertex2f(0.28, 0.0);
  glVertex2f(0.1, -0.1);
  glEnd();

glBegin(GL_TRIANGLES);

  glVertex2f(0.17, 0.25);
  
  glVertex2f(0.1, 0.05);
  glVertex2f(0.17, 0.02);
  glEnd();

glBegin(GL_TRIANGLES);

 glVertex2f(0.0, -0.18);
  
  glVertex2f(0.1, 0.0);
  glVertex2f(0.12, -0.1);
  glEnd();

glBegin(GL_TRIANGLES);

 glVertex2f(0.17, 0.0);
  
  glVertex2f(0.1, -0.1);
  glVertex2f(0.16, -0.25);
  glEnd();





  glFlush();

}

void init()
{
  glClearColor (1.0, 1.0, 1.0, 0.0);

  glColor3f(1.0, 1.0, 1.0);

  glMatrixMode(GL_PROJECTION);
  glLoadIdentity ();
  gluOrtho2D(-1.0, 1.0, -1.0, 1.0);



}


int main(int argc, char** argv)
{
  glutInit(&argc, argv);
  glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
  glutInitWindowSize(500, 300);
  glutInitWindowPosition(0,0);
  glutCreateWindow("simple");
  glutDisplayFunc(display);
  init();
  glutMainLoop();

      
}

My question is how can I create this map of New England, because most states are not normal shapes? Is there a tutorial someone could direct me too that would help me? Any advice would be greatly appreciated.

Thank you!

If you want to draw a filled 2D area of a state, then ultimately the GPU is going to fill it with triangles. So you might as well feed triangles to OpenGL. To do that, you take the outline of the state and tessellate it into triangles (or find such a pre-tessellated representation online).

If you just want to draw the outline, just take the outline of the state and draw each segment with lines primitives.

Does the map HAVE to be made up of polygons?
Have you considered texture mapping the image of New England onto a quad?
This is how I usually do maps in OpenGL.

Draw your shape in some 2d vector graphic editor (inkscape, illustrator) end export in illustrator format
http://mercator.elte.hu/~saman/hu/okt/AI7FileFormat.pdf
illustrator is trivial to parse if you only need only point shape.
Also .ps format is easy to parse.

Then, apply some ear cutting algorithm to triangulate the shape
http://cgm.cs.mcgill.ca/~godfried/teaching/cg-projects/97/Ian/cutting_ears.html
Save somewhere the triangles.

Load the triangle in your program to create the map. I suggest to load the flags as texture, is quite difficult to render them as polygon. Obviously the illustrator format let you export color too.