0

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)(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:

What am I doing wrong?

Thanks and best regards

Tobias

Atmocreations
  • 9,923
  • 15
  • 67
  • 102

1 Answers1

1

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:

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

Community
  • 1
  • 1
Robert Massaioli
  • 13,379
  • 7
  • 57
  • 73
  • Thanks, Robert. The device (HTC Desire with Android 2.2) is behaving exactly the same way as the emulator does. And what I posted is basically all that is being called. Will take a look at the other tips and keep you up-to-date. – Atmocreations Jun 13 '11 at 08:41
  • Update: Okay it must have been something in my array arithmetics. Still doesn't work, but you may check Revision 3 at http://stackoverflow.com/posts/6325070/revisions – Atmocreations Jun 13 '11 at 09:32