title: OpenGL tessellation of a car made from a polygon
body: <p>im learning to use openGL and iv been told that because my wheel arches are concave i have to tessellate them. So here is my code for the front wheel arch... </p>
  
  <pre><code>GLdouble car[7][2] = { {-1.93,0.3}, {-1.95,0.4}, {-2.2,0.6}, {-2.6,0.6}, {-2.82,0.4}, {-2.8,0.3}, {-2.78,0.0} };
  GLUtesselator *tess = gluNewTess(); // create a tessellator
  
  glEnable(GL_TEXTURE_2D);
  glBindTexture(GL_TEXTURE_2D, textureLib[textureindex]);
  
  glBegin(GL_POLYGON);
  
  glTexCoord2f( 0.0 , 0.0 ); glVertex2f(-1.0 , 0.0 );
  glTexCoord2f(-0.97, 0.0 ); glVertex2f(-1.97, 0.0 );
  
  // Wheel arch
  gluTessBeginContour(tess);
  {
      gluTessVertex(tess, car[0], car[0]);
      gluTessVertex(tess, car[1], car[1]);
      gluTessVertex(tess, car[2], car[2]);
      gluTessVertex(tess, car[3], car[3]);
      gluTessVertex(tess, car[4], car[4]);
      gluTessVertex(tess, car[5], car[5]);
      gluTessVertex(tess, car[6], car[6]);
  }
  gluTessEndContour(tess);
  </code></pre>
  
  <p>And the car looks like this:</p>
  
  <p><img src="https://i378.photobucket.com/albums/oo230/tcc_hellgate/carcurrent.png" alt="car"></p>
  
  <p>{i know the texturing is wrong atm too) but as you can see the front wheel arch hasnt changed even with the tessellation, so i guess im tessellating wrong.. or need to tessellate more of it.. or something? if someone could please help me with this massive problem im having with the wheel arches and rectify it i would be eternally gratefully as i have been struggling to get past this point for a while. thanks :) </p>
  
  <p>The whole drawBody function code can be found here: <a href="http://pastebin.com/s9RpzMsd" rel="nofollow noreferrer">http://pastebin.com/s9RpzMsd</a></p>
  
  <p>Update: Thanks for all the help: my object now looks like this thanks to the tessellation help. Now just to texture :) </p>
  
  <p><img src="https://i378.photobucket.com/albums/oo230/tcc_hellgate/Capture-1.png" alt="car better"></p>
  
  <p>Update 2: Ok so I used the same code roughly as PeterT suggested and this is what it ended up (had to make changes for it to compile. Point it out if its wrong)</p>
  
  <pre><code>glEnable(GL_TEXTURE_2D);
  glBindTexture(GL_TEXTURE_2D, textureLib[textureindex]);
  
  GLUtesselator *tess = gluNewTess(); // create a tessellator
  
  gluTessCallback(tess, GLU_TESS_VERTEX,
                 (void (__stdcall *)  ()) &amp;putvertex);
  gluTessCallback(tess, GLU_TESS_BEGIN,
                 (void (__stdcall *)  ()) &amp;glBegin);
  gluTessCallback(tess, GLU_TESS_END,
                 (void (__stdcall *)  ()) &amp;glEnd);
  
  
  gluTessBeginPolygon(tess, NULL);
  gluTessBeginContour(tess);
      for(int i=0; i&lt;29;i++)
          gluTessVertex(tess, car[i], car[i]);
          //call gluTessVertex for EVERY vertex in the polygon here 
      gluTessEndContour(tess);
  gluTessEndPolygon(tess);
  glDisable(GL_TEXTURE_2D);
  </code></pre>
  
  <p>With the putvertex code being:</p>
  
  <pre><code>void CALLBACK putvertex(GLdouble *verts)
  {
  //filled according to you texture coordinates:
  GLdouble scalefacx = 1.0;
  GLdouble scalefacy = 1.0;
  GLdouble offsetx = -1.0;
  GLdouble offsety = 0.0;
  glVertex2dv(verts);
  glTexCoord2d(verts[0]*scalefacx - offsetx,verts[1]*scalefacy - offsety);
  }
  </code></pre>
  
  <p>It then looks like this:</p>
  
  <p><img src="https://i378.photobucket.com/albums/oo230/tcc_hellgate/Capture-2.png" alt="car texture"></p>
  
  <p>Have i gone wrong somewhere? :/</p>
  
  <p>Thanks for all your help, the final image looks like this: </p>
  
  <p><img src="https://i378.photobucket.com/albums/oo230/tcc_hellgate/Capture-3.png" alt="car finished"></p>
  
  <p>Again thanks for all your help! Especially PeterT :) </p>