Re: GLJPanel and translate
Posted by gsxruk on Dec 21, 2010; 3:25pm
URL: https://forum.jogamp.org/GLJPanel-and-translate-tp2081621p2126439.html
Hi,
I seem to have solved this problem by adding pushMatrix() and popMatrix() as shown in the amended display method below:
@Override
public void display(GLAutoDrawable drawable)
{
GL2 gl = drawable.getGL().getGL2();
gl.glClear(GL2.GL_COLOR_BUFFER_BIT);
gl.glPushMatrix();
//Translate to the centre
gl.glTranslated(200, 200, 0.0);
//Draw a blue square
gl.glBegin(GL2.GL_POLYGON);
gl.glColor4f(0, 0, 1.0f, 1.0f);
gl.glVertex2f(-50, -50);
gl.glVertex2f(-50, 50);
gl.glVertex2f(50, 50);
gl.glVertex2f(50, -50);
gl.glEnd();
gl.glPopMatrix();
gl.glFlush();
}
However, I now seem to have discovered a further issue. If the display() method is amended slightly (just reducing the translation in y and amending the polygon to all positive values), the resize behaviour is strange again. If you drag the window and decrease the size in y, when it gets very small (just before the polygon is about to clip), the polygons right edge disappears to the right and appears to go on forever. No matter how far the window is increased in size in x, the polygon is drawn past that point. Here is the amended method.
@Override
public void display(GLAutoDrawable drawable)
{
GL2 gl = drawable.getGL().getGL2();
gl.glClear(GL2.GL_COLOR_BUFFER_BIT);
gl.glPushMatrix();
//Translate to the centre
gl.glTranslated(200, 50, 0.0);
//Draw a blue square
gl.glBegin(GL2.GL_POLYGON);
gl.glColor4f(0, 0, 1.0f, 1.0f);
gl.glVertex2f(0, 0);
gl.glVertex2f(0, 100);
gl.glVertex2f(100, 100);
gl.glVertex2f(100, 0);
gl.glEnd();
gl.glPopMatrix();
gl.glFlush();
}
Does anyone have any ideas?
Thanks.