2

Does anyone knows a generic way to apply glTexCoord2f to generic polygons? For circles, triangles and quads, it was quite intuitive, but polygons is kind a mess.

For example, my equilateral triangle render is:

void Triangulo::RenderizaPontos(){
    glColor3f(red, green, blue);
    glLineWidth(grafite);

    glBegin(GL_TRIANGLES);
        glTexCoord2f(0.0f, 0.0f); glVertex2f(cantoesq.x, cantoesq.y);
        glTexCoord2f(0.5f, 1.0f); glVertex2f(cantoesq.x + base , altura + cantoesq.y);
        glTexCoord2f(1.0f, 0.0f); glVertex2f(cantoesq.x + 2*base, cantoesq.y);

    glEnd();
}

The problem is for the generic polygon. His class is below:

Poligno::Poligno(std::deque<Ponto> pontos):
ponto(pontos)
{
    prox = NULL;
    grafite = 1.0;
}

void Poligno::RenderizaPontos(){
    int tamanho, i;

    tamanho = ponto.size();

    glColor3f(red, green, blue);
    glLineWidth(grafite);

    glBegin(GL_POLYGON);
    for(i = 0; i < tamanho; i++)
        glVertex2f(ponto[i].x, ponto[i].y);  
    glEnd();
}

Any idea?

Sinayra
  • 175
  • 1
  • 13
  • 1
    Err, you are calling `glTexCoord` and `glVertex` in the wrong order... `glVertex` essentially takes all the vertex parameters (color, normal, texcoord, weight, etc.) and creates a new vertex at the specific position. You need to set everything I just mentioned ***before*** you call it. – Andon M. Coleman Jan 16 '14 at 01:07
  • Ups! My bad. x) Now the coordinates makes sense, thank you! – Sinayra Jan 16 '14 at 01:20

0 Answers0