Подскажите пожалуйста, вот здесь:
http://stackoverflow.com/questions/6072 ... -opengl-es
нашел пример рисования сферы. Попробовал прорисовать сферу инициализировав в конструкторе рендерера Sphere = new Sphere(10,10) дописав в конце метода onDrawFrame строку mSphere.draw(gl);
public class Sphere {
static private FloatBuffer sphereVertex;
static private FloatBuffer sphereNormal;
static float sphere_parms[]=new float[3];
double mRaduis;
double mStep;
float mVertices[];
private static double DEG = Math.PI/180;
int mPoints;
/**
* The value of step will define the size of each facet as well as the number of facets
*
* @param radius
* @param step
*/
public Sphere( float radius, double step) {
this.mRaduis = radius;
this.mStep = step;
sphereVertex = FloatBuffer.allocate(40000);
mPoints = build();
Log.d("ALIS CHECK!!!!!!", " COUNT:" + mPoints);
}
public void draw(GL10 gl) {
gl.glFrontFace(GL10.GL_CW);
gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
gl.glVertexPointer(3, GL10.GL_FLOAT, 0, sphereVertex);
gl.glColor4f(1.0f, 0.0f, 0.0f, 1.0f);
gl.glDrawArrays(GL10.GL_POINTS, 0, mPoints);
gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
}
private int build() {
/**
* x = p * sin(phi) * cos(theta)
* y = p * sin(phi) * sin(theta)
* z = p * cos(phi)
*/
double dTheta = mStep * DEG;
double dPhi = dTheta;
int points = 0;
for(double phi = -(Math.PI/2); phi <= Math.PI/2; phi+=dPhi) {
//for each stage calculating the slices
for(double theta = 0.0; theta <= (Math.PI * 2); theta+=dTheta) {
sphereVertex.put((float) (mRaduis * Math.sin(phi) * Math.cos(theta)) );
sphereVertex.put((float) (mRaduis * Math.sin(phi) * Math.sin(theta)) );
sphereVertex.put((float) (mRaduis * Math.cos(phi)) );
points++;
}
}
sphereVertex.position(0);
return points;
}
}
В итоге выдало ошибку:
Application maestro.firstopengl (SDK target 23) called a GL11 Pointer method with an indirect Buffer.
02-15 11:04:57.147 16844-16858/maestro.firstopengl E/AndroidRuntime﹕ FATAL EXCEPTION: GLThread 6309
java.lang.IllegalArgumentException: Must use a native order direct Buffer
at com.google.android.gles_jni.GLImpl.glVertexPointerBounds(Native Method)
at com.google.android.gles_jni.GLImpl.glVertexPointer(GLImpl.java:1122)
at maestro.firstopengl.Sphere.draw(Sphere.java:42)
at maestro.firstopengl.OpenGLRenderer3D_anim.onDrawFrame(OpenGLRenderer3D_anim.java:284)