本文介绍了在OpenGL ES 1.1中用切出的扇形画一个圆的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用OpenGL ES 1.1绘制以下形状.好吧,我被困住了,我真的不知道该怎么做.
I'm trying to draw the following shape using OpenGL ES 1.1. And well, I'm stuck, I don't really know how to go about it.
我的游戏当前使用的是Android的Canvas API,该API并未通过硬件加速,因此我将使用OpenGL ES对其进行重写. Canvas类具有一个名为drawArc的方法,该方法使绘制此形状变得非常容易. Canvas.drawArc
My game currently uses Android's Canvas API, which isn't hardware accelerated, so I'm rewriting it with OpenGL ES. The Canvas class has a method called drawArc which makes drawing this shape very very easy; Canvas.drawArc
是否有关于使用OpenGL ES的建议/提示?
Any advice/hints on doing the same with OpenGL ES?
感谢您的阅读.
推荐答案
void gltDrawArc(unsigned int const segments, float angle_start, float angle_stop)
{
int i;
float const angle_step = (angle_stop - angle_start)/segments;
GLfloat *arc_vertices;
arc_vertices = malloc(2*sizeof(GLfloat) * (segments+2));
arc_vertices[0] = arc_vertices[1] = 0.
for(i=0; i<segments+1; i++) {
arc_vertices[2 + 2*i ] = cos(angle_start + i*angle_step);
arc_vertices[2 + 2*i + 1] = sin(angle_start + i*angle_step);
}
glVertexPointer(2, GL_FLOAT, 0, arc_vertices);
glEnableClientState(GL_VERTEX_ARRAY);
glDrawArrays(GL_TRIANGLE_FAN, 0, segments+2);
free(arc_vertices);
}
这篇关于在OpenGL ES 1.1中用切出的扇形画一个圆的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!