本文介绍了如何绘制基本圈的OpenGL ES 2.0的Android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是新的的OpenGL ES 2,我已经了解了多少话题绘制的OpenGL ES 2 Android上的圆。基于绘制图形和这code发现gamedev.net ,我可以画三角形和quares,但我还是不知道该怎么画了一个圈。我现在有三种方式来画一个圆圈:
I'm new in OpenGL ES 2, and I have read many topics about how to draw a circle in OpenGL ES 2 on Android. Based on Drawing Shapes and this code found on gamedev.net, I can draw triangles and quares, but I still don't know how to draw a circle. I now have three ways to draw a circle:
- 生成了一圈顶点和使用glDrawArray(GL_LINES,...)。根据你产生多少个顶点,这将产生一个很好的和清晰的结果。
- 使用pgenerated质感圆(与阿尔法透明度)的$ P $并将其映射在四。这将导致非常流畅的图形,并允许一个'thick'一圈,但它不会那么灵活。即使有纹理映射,你会希望你的纹理大致相同大小正进行渲染四
- 使用一个片段着色器。
但我怎么实施呢?
推荐答案
如果你想创建几何圆,做这样的事情:
If you want to create geometry for the circle, do something like this:
int vertexCount = 30;
float radius = 1.0f;
float center_x = 0.0f;
float center_y = 0.0f;
// Create a buffer for vertex data
float buffer[] = new float[vertexCount*2]; // (x,y) for each vertex
int idx = 0;
// Center vertex for triangle fan
buffer[idx++] = center_x;
buffer[idx++] = center_y;
// Outer vertices of the circle
int outerVertexCount = vertexCount-1;
for (int i = 0; i < outerVertexCount; ++i){
float percent = (i / (float) (outerVertexCount-1));
float rad = percent * 2*Math.PI;
//Vertex position
float outer_x = center_x + radius * cos(rad);
float outer_y = center_y + radius * sin(rad);
buffer[idx++] = outer_x;
buffer[idx++] = outer_y;
}
//Create VBO from buffer with glBufferData()
然后就可以使用调用glDrawArrays绘制()无论是作为:
Then you can draw using glDrawArrays() either as:
- GL_LINE_LOOP (轮廓只),或
- GL_TRIANGLE_FAN (填入形状)
- GL_LINE_LOOP(contour only) or
- GL_TRIANGLE_FAN(filled shape)
// Draw circle contours (skip center vertex at start of the buffer)
glDrawArrays(GL_LINE_LOOP, 2, outerVertexCount);
// Draw circle as a filled shape
glDrawArrays(GL_TRIANGLE_FAN, 0, vertexCount);
这篇关于如何绘制基本圈的OpenGL ES 2.0的Android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!