我在opengl android中渲染3d对象,我不断渲染这些对象以实现平滑旋转。代码片段如下:
public synchronized void render(GL10 gl) {
calculate();
if ( mVertexCount == 0 ) return;
gl.glVertexPointer(3, GL10.GL_FLOAT, 0, mVertices); //3:Specifies the number of coordinates per vertex
gl.glColorPointer(4, GL10.GL_UNSIGNED_BYTE, 0, mColors);
int elementVertices = VERTICES_ELEMENT * mRows * mCols;
for ( int j = 0; j < elementVertices; j += VERTICES_ELEMENT ) {
gl.glDrawArrays(GL10.GL_TRIANGLE_FAN, j, VERTICES_ELEMENT);
}
if ( mShowBorder ) {
gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, elementVertices, VERTICES_BORDER);
}
if ( mShowGrid && mRows != 0 && mCols != 0 ) {
int j = elementVertices + VERTICES_BORDER;
for ( int r = 0; r <= mRows; ++r ) {
int colCount = mCols * 2 + 1;
gl.glDrawArrays(GL10.GL_LINE_STRIP, j, colCount);
j += colCount;
}
for ( int c = 0; c <= mCols; ++c ) {
int rowCount = mRows * 2 + 1;
gl.glDrawArrays(GL10.GL_LINE_STRIP, j, rowCount);
j += rowCount;
}
}
}