Question

Ok so im seperating my problem up because i need a depthy answer cos im nooby with it and will fail if i have just a generalisation answer.

I have a car body which i originally drew using line_loop and have changed it to polygon so i can texture it. however it ignores the wheel arches like so.

car wrong

(ignore the texturing for now, i need to figure that one out another time ;) )

This is what my car looks like with line_loop

car shape

If the way to make the wheel arches with polygon makes it a smoother circle then even better :)

This is my current code, (ignore the texture stuff) I did start tessellation with a prod in that direction from an earlier question but not sure exactly how to use it and which coords to pass etc etc. Thanks for all your help!!

void drawBody(int textureindex)
{
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, textureLib[textureindex]);

GLUtesselator *tess = gluNewTess(); // create a tessellator
      if(!tess) return 0;  // failed to create tessellation object, return 0

glBegin(GL_POLYGON);

glTexCoord2f(0.0F, 0.0F);
      glVertex2f(-1.0f, 0.0f);
glTexCoord2f(-0.97, 0.0);
      glVertex2f(-1.97f, 0.0f);
//wheel arch begin.
glTexCoord2f(-0.93, 0.3);
      glVertex2f(-1.93f, 0.3f);
glTexCoord2f(-0.95, 0.4);
glVertex2f(-1.95f, 0.4f);
glTexCoord2f(-1.2, 0.6);
glVertex2f(-2.2f, 0.6f);
glTexCoord2f(-1.6, 0.6);
glVertex2f(-2.6f, 0.6f);
glTexCoord2f(-1.82, 0.4);
glVertex2f(-2.82f, 0.4f);
glTexCoord2f(-1.8, 0.3);
glVertex2f(-2.8f, 0.3f);
glTexCoord2f(-1.78, 0.0);
glVertex2f(-2.78f, 0.0f);
//end wheel arch.
//Front of car.
glTexCoord2f(0.0, 0.0);
glVertex2f(-3.8f, 0.0f);
glTexCoord2f(0.0, 0.2);
glVertex2f(-3.7f, 0.2f);
glTexCoord2f(0.0, 0.4);
glVertex2f(-3.8f, 0.4f);
glTexCoord2f(0.0, 0.7);
glVertex2f(-2.8f, 0.7f);
glTexCoord2f(0.0, 0.7);
glVertex2f(-2.4f, 0.7f);
//Windscreen.
glTexCoord2f(0.0, 1.0);
glVertex2f(-1.0f, 1.0f);
glTexCoord2f(1.0, 1.0);
glVertex2f(0.5f, 1.05f);
glTexCoord2f(1.0, 0.8);
glVertex2f(2.3f, 0.8f);
//rear bumper.
glTexCoord2f(1.0, 0.5);
glVertex2f(2.15f, 0.5f);
glTexCoord2f(1.0, 0.3);
glVertex2f(2.15f, 0.3f);
glTexCoord2f(1.0, 0.3);
glVertex2f(2.35f, 0.3f);
glTexCoord2f(1.0, 0.0);
glVertex2f(2.0f, 0.0f);
glTexCoord2f(1.0, 0.0);
glVertex2f(1.83f, 0.0f);
//wheel arch begin.
glTexCoord2f(1.0, 0.3);
      glVertex2f(1.85f, 0.3f);
glTexCoord2f(1.0, 0.4);
      glVertex2f(1.86f, 0.4f);
glTexCoord2f(1.0, 0.6);
glVertex2f(1.6f, 0.6f);
glTexCoord2f(1.0, 0.6);
glVertex2f(1.2f, 0.6f);
glTexCoord2f(1.0, 0.4);
glVertex2f(1.0f, 0.4f);
glTexCoord2f(1.0, 0.3);
glVertex2f(1.0f, 0.3f);
glTexCoord2f(1.0, 0.0);
glVertex2f(1.05f, 0.0f);
//end wheel arch.
glEnd();
glDisable(GL_TEXTURE_2D);
}

Revised code for tessellation, (only attempted on one wheel arch so far and has had no affect).

    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
gluTessBeginPolygon(tess, 0);  
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);
gluTessEndPolygon(tess);

Thanks for all your help, the final image looks like this:

car finished

Again thanks for all your help! Especially PeterT :)

Was it helpful?

Solution

You are not using the tessellator at all. Feeding the coordinates to the tessellator will look something like this

    gluTessBeginContour(tess);
        :
        gluTessVertex(tess, v[i], v[i]);
        :
    gluTessEndContour(tess);

Read here and grab the examples http://www.songho.ca/opengl/gl_tessellation.html

OTHER TIPS

GL_POLYGON is used for drawing convex polygons. Your car is not convex, so you can't draw everything in one go (glBegin.. glEnd). Split car into multiple parts that have different primitive types. GL_POLYGON can't be used for everything.

You aren't even using your tesselator.

Bottom line is that your question is very basic. Before going further with OpenGL, finish "OpenGL red book", that covers pretty much all basic information. Version 1.1 is available online for free in several different places.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top