Hi All,
I am new to JOGL & trying to develop application.
I have this specific requirement where I should be able to draw some 2D stuff on the 3D screen (drawing 3D using canvas).
I am using the Overlay to do so. But I am facing issue with the Overlay. Every time it draws the new object but without clearing old ones. So on the overlay it creates to much mess. It can be seen in the below image.
public void init(GLAutoDrawable autoDrawable) {
//configurations
overlay = new Overlay(autoDrawable);
/other code
}
@Override
public void display(GLAutoDrawable drawable) {
clearCanvas();
//3D drawing code
Graphics2D g2d = overlay.createGraphics();
number = random.nextInt() + 1;
overlay.beginRendering();
g2d.setColor(Color.RED);
g2d.drawRect(number % 400, 0, 50, 50);
overlay.draw(0, 0, width, height);
overlay.markDirty(0, 0, width, height);
overlay.endRendering();
g2d.dispose();
}
To solve this I have tried creating new Overlay object each time it comes in display method. It worked but the CPU usage went to much high. Also after some time it has thrown virtual memory full error.
So can any one please help me out for solving this problem.