OpenGL para OpenGL-ES - A alteração de cor de triângulos em uma tira
Pergunta
Ao usar glBegin () e glEnd () em OpenGL você é capaz de definir e alterar a cor entre cada glVertex3f (). Como você pode recriar esse comportamento ao usar uma matriz de vértice e glDrawArrays (). Aqui está em OpenGL regular.
for(angle = 0.0f; angle < (2.0f*GL_PI); angle += (GL_PI/8.0f))
{
// Calculate x and y position of the next vertex
x = 50.0f*sin(angle);
y = 50.0f*cos(angle);
// Alternate color between red and green
if((iPivot %2) == 0)
glColor3f(0.0f, 1.0f, 0.0f);
else
glColor3f(1.0f, 0.0f, 0.0f);
// Increment pivot to change color next time
iPivot++;
// Specify the next vertex for the triangle fan
glVertex2f(x, y);
}
Solução
Com glDrawArrays você tem que permitir que o glVertexPointer para definir os dados de vértice.
Da mesma forma você também pode definir um ponteiro-memória do cliente para as cores.
Tudo se resume a essas chamadas:
glEnableClientState (GL_VERTEX_ARRAY);
glEnableClientState (GL_COLOR_ARRAY); // enables the color-array.
glVertexPointer (... // set your vertex-coordinates here..
glColorPointer (... // set your color-coorinates here..
glDrawArrays (... // draw your triangles
Entre - textura coordenadas são tratadas da mesma forma. Basta usar GL_TEXCOORD_ARRAY e glTexCoordPointer para isso.
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow