How do I draw the same polygon in two different viewports?

How do I draw the same polygon in two different viewports?

I have defined two viewports in my reshape() method but my polygon only appears in the right one.
So how do I do to make the polygon to also appear on the left viewport?

public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {
        GL gl = drawable.getGL();
        

        gl.glViewport (0, 0,  width/2, height);
        gl.glMatrixMode (GL.GL_PROJECTION);
        gl.glLoadIdentity ();
        glu.gluPerspective(60.0f, 3.0f, 1.5f, 20.0f);
        gl.glMatrixMode (GL.GL_MODELVIEW);
        gl.glMultMatrixf(new float[]{4.1f, 4.1f, 6.1f}, 0);
        
        
        gl.glViewport (width/2, 0, width/2, height);
        gl.glMatrixMode (GL.GL_PROJECTION);
        gl.glLoadIdentity ();
        glu.gluPerspective(60.0f, 3.0f, 1.5f, 20.0f);
        gl.glMatrixMode (GL.GL_MODELVIEW);
        gl.glMultMatrixf(new float[]{4.1f, 4.1f, 6.1f}, 0);
    }

Opengl is a state machine, so when you call something like glViewport, you’re changing opengl’s current viewport. There is no way to have two simultaneous viewports and let opengl choose which one to render into to.

Instead what you need to do is set up the 1st viewport, do your rendering there. Then set up your 2nd viewport, and do the rest of the rendering. By the time the frame is complete, it will look like there are two independent viewports to the user.

I made a try but couldn´t get it working. Just the circles on the first viewpoint are beeing displayed, but not the one drawn after the second viewpoint has beeing specified.

First I specified the first viewpoint in the reshape() method;

 public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {

        this.width = width;
        this.height = height;

        gl.glViewport (0, 0,  width/2, height);
        gl.glMatrixMode (GL.GL_PROJECTION);
        gl.glLoadIdentity ();
        glu.gluPerspective(60.0f, 3.0f, 1.0f, 20.0f);
        gl.glMatrixMode (GL.GL_MODELVIEW);
        gl.glMultMatrixf(new float[]{4.1f, 4.1f, 6.1f}, 0);
        gl.glLoadIdentity();
        glu.gluLookAt(0.0f, 0.0f, 5.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f);
}

Then I specified the other viewpoint in the display() method;

public void display(GLAutoDrawable drawable) {
        gl = drawable.getGL();

        gl.glClear (GL.GL_COLOR_BUFFER_BIT);
        gl.glColor3f (1.0f, 1.0f, 1.0f);
        gl.glPushMatrix();
        drawCircle(2.5f);

        gl.glRotatef (year, 0.0f, 1.0f, 0.0f);
        gl.glTranslatef (2.0f, 0.0f, 0.0f);
        gl.glRotatef (day, 0.0f, 1.0f, 0.0f);
        drawCircle(1.5f);

        gl.glPopMatrix();

        // The second viewpoint
        gl.glViewport (width/2, 0, width/2, height);
        gl.glMatrixMode (GL.GL_PROJECTION);
        gl.glLoadIdentity ();
        glu.gluPerspective(60.0f, 3.0f, 1.5f, 20.0f);
        gl.glMatrixMode (GL.GL_MODELVIEW);

        // A circle in the second viewpoint
        drawCircle(2.5f);

        gl.glFlush ();
}

What have I missed?