开发者

Android / OpenGL ES: Draw primitive doesn't do anything

Trying to draw a solid cylinder doesn't do what I want it to. Here's my code:

public static void solidCylinder(GL10 gl, float radius, float height, int slices, int steps)
{
    float zStep = height/steps;
    float alphaStep = (float)((2*Math.PI) / slices);
    float crtZ = -height/2;
    float[] vdata = new float[6 * steps * (slices+1)];
    for(int iStep = 0; iStep < steps; iStep++)
    {   
        float crtAlpha = 0;
        int iAlpha;
        for (iAlpha = 0; iAlpha <= slices; iAlpha++)
        { 
            vdata[iStep * (iAlpha*6)+0] = (float)(radius * -Math.sin(crtAlpha));
            vdata[iStep * (iAlpha*6)+1] = crtZ;
            vdata[iStep * (iAlpha*6)+2] = (float)(radius * Math.cos(crtAlpha));
            vdata[iStep * (iAlpha*6)+3] = (float)(radius * -Math.sin(crtAlpha));
            vdata[iStep * (iAlpha*6)+4] = crtZ + zStep;
            vdata[iStep * (iAlpha*6)+5] = (float开发者_JS百科)(radius * Math.cos(crtAlpha));

            crtAlpha += alphaStep;
        }
        gl.glShadeModel(GL10.GL_SMOOTH);
        gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
        gl.glVertexPointer(3, GL10.GL_FLOAT, 0, FloatBuffer.wrap(vdata));
        gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 0, 2*(slices+1) );
        gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
        crtZ += zStep;                        
    } 

}

Here's where I call the method:

@Override
public void onDrawFrame(GL10 gl) {
    // IN MY DRAWING FUNCTION:
    gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
    gl.glMatrixMode(GL10.GL_MODELVIEW);
    gl.glColor4f(1.0f,1.0f,1.0f, 1.0f); 
    gl.glPushMatrix();
        Primitives.solidCylinder(gl, 2.0f, 2.0f, 8, 3);
    gl.glPopMatrix();

}

When I had the same in C/C++ (though directly with glVertex*()- functions) it worked.

Edit: On the emulator it stays all black as without calling solidCylinder(..)

Result:

Android / OpenGL ES: Draw primitive doesn't do anything

What am I doing wrong?

Thanks and best regards

Tobias


Your problem sounds very similar to the one that happened here: Android -- OpenGL doesn't display w/ emulator?

If I were you I would complete the two tutorials that he did to make sure that you are not missing anything that is required for OpenGL development and to make sure that you emulator is working like it should. Here are the tutorials for your convenience:

  • Tutorial 1 - Is OpenGL working on my Emulator
  • Tutorial 2 - Am I drawing objects to my screen correctly

Let me know if that works for you in the comments.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜