[英]OpenGL to OpenGL-ES - Changing color of triangles in a strip
在opengl中使用glBegin()和glEnd()时,您可以设置和更改每个glVertex3f()之间的颜色。 如何在使用顶点数组和glDrawArrays()时重新创建此行为。 这是常规opengl。
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);
}
使用glDrawArrays,您必须启用glVertexPointer来设置顶点数据。
以同样的方式,您还可以为颜色设置客户端内存指针。
归结为这些调用:
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
顺便说一句 - 纹理坐标以相同的方式处理。 只需使用GL_TEXCOORD_ARRAY和glTexCoordPointer即可。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.