hello,
i am trying write a Paint application using jogl.
when i draw some shape on a canvas, i want it to remain there. but when i begin to draw new shape, old shape is gone.
do you a way of saving the view and drawing new shapes on old view.
the answer may not be related to jogl, i kinda remember something like canvas on canvas that is making old canvas a background of new one.
i modify code from a jogl demo.
class Renderer
implements GLEventListener,
MouseListener, MouseMotionListener {
.
.
.
public void display(GLDrawable gLDrawable) {
final GL gl = gLDrawable.getGL();
gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
gl.glLoadIdentity();
gl.glTranslatef(-2.5f, 0.0f, -10.0f);
gl.glBegin(GL.GL_TRIANGLES); // Drawing Using Triangles
gl.glColor3f(1.0f, 0.0f, 0.0f); // Set the current drawing color to red
gl.glEnd(); // Finished Drawing The Triangle
gl.glTranslatef(1.0f, 0.0f, 0.0f);
gl.glBegin(GL.GL_QUADS); // Draw A Quad
gl.glColor3f(0.5f, 0.5f, 1.0f); // Set the current drawing color to light blue
if (dragPoint != null ){
gl.glVertex3f(-1.0f, 1.0f, 0.0f); // Top Left
gl.glVertex3f(0.0f, 1.0f, 2.0f); // Top Right
gl.glVertex3f(1.0f, -1.0f, 0.0f); // Bottom Right
gl.glVertex3f(-1.0f, -1.0f, 1.0f); // Bottom Left
} else {
gl.glVertex3f(-1.0f, 1.0f, 0.0f); // Top Left
gl.glVertex3f(0.0f, 1.0f, 0.0f); // Top Right
gl.glVertex3f(1.0f, 0.0f, 0.0f); // Bottom Right
gl.glVertex3f(-1.0f, -1.0f, 0.0f); // Bottom Left
}
gl.glEnd(); // Done Drawing The Quad
gl.glFlush();
}
.
.
public void mousePressed(MouseEvent e) {
lastPressed = e.getPoint();
}
public void mouseReleased(MouseEvent e) {
lastPressed = null;
dragPoint = null;
}
.
.
}