add item

In OpenGl, I want to add some shapes (Cylinders) on an already drawn jpanel…In particular, I want to draw a cylinder, based on a value aquired from the user (the value corresponds to the height of the cylinder).
But each time, I want to add a new cylinder on the previously painted jpanel
Do I have to repaint the whole jpanel, or is there a way to add only the specific object (cylinder) on the previously painted jpanel?

What is a “jpanel”?

java use jpanel and canvas for drawing the items…i dont know where c does the same…Opengl is the same for both of them

In a single-buffered context you only have to add the cylinder, and it’s recommended that you call glFlush or glFinish after doing so.

In a double-buffered context you can either (1) use glDrawBuffer (GL_FRONT) and just add the cylinder as above, or (2) redraw the entire scene, including the cylinder.

(1) is NOT recommended as it can cause certain graphics cards to explode. Well, not explode, but they could hang your OS or cause the Windows Vista/7 DWM to restart. This is mainly Intel, so if you need to run on Intel be aware of it.

(2) should not be a big problem for you if you have your main scene manager/render loop set up correctly. At the most basic level you should be maintaining a list of objects to be drawn, so all you would need to do is create a cylinder object and insert it in the right place, then call your redraw method.

my problem is that when i call my function which is


       public void cylinder() {
        gl = drawable.getGL();
        gl.glScaled(0.7, 0.7, 0.7);
        gl.glColor4f(1f, 0.5f, 1f, 1f);
        gl.glTranslatef(1f, 0f, 1f);
        GLUquadric jog = glu.gluNewQuadric();
        gl.glRotatef(-90.0f, 1.0f, 0.0f, 0.0f);
        glu.gluDisk(jog, 0.0, 1.0, 32, 1);
        glu.gluCylinder(jog, 1.0f, 1.0, 2.0, 32, 1);
        gl.glTranslatef(0.0f, 0.0f, 2.0f);
        glu.gluDisk(jog, 0.0, 1.0, 32, 1);
        gl.glTranslatef(0.0f, 0.0f, -2.0f);
        gl.glRotatef(90.0f, 1.0f, 0.0f, 0.0f);
        glu.gluDeleteQuadric(jog);
    }

i have exception here gl = drawable.getGL();

java.lang.NullPointerException

i cant really understant where is the problem…i try to fix it but i have no result.