感谢您的代码,我使它在 iOS 上的 2D OGLes1.1 项目上工作。
效果很好,有点乱,但可能对学习者有好处。
谢谢。
-(void) MakeCircle2d:(int)points pos:(CGPoint)pos rad:(GLfloat)rad texName:(GLuint)texName
{
float verts[(points*2)+2];
float txtcord[(points*2)+2];
verts[0]=pos.x;
verts[1]=pos.y;
txtcord[0]=0.5f;
txtcord[1]=0.5f;
int c=2;
for (int i = 0; i < points; i++)
{
float fi = 2.0*M_PI*((float)i/(float)(points-2.0));
float x = sinf(fi + M_PI) ;
float y = cosf(fi + M_PI) ;
verts[c]=pos.x+(x*rad);
verts[c+1]=pos.y+(y*rad);
txtcord[c]=x*0.5f+0.5f;//scale the circle to 0.5f radius and plus 0.5f because we want the center of the circle tex cordinates to be at 0.5f,0.5f
txtcord[c+1]=y*0.5f+0.5f;
c+=2;
}
glColor4f(1.0,1.0,1.0,1.0);
//glColor4f(0.0,0.0,0.0, 0.0);
glEnable(GL_TEXTURE_2D);
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glPushMatrix();
glBindTexture(GL_TEXTURE_2D, texName);
glTexCoordPointer(2, GL_FLOAT, 0, txtcord);
glVertexPointer(2, GL_FLOAT, 0, verts);
glDrawArrays(GL_TRIANGLE_FAN, 0, points);
//glBindTexture(GL_TEXTURE_2D, 0);
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glPopMatrix();
}