Overlay and Window Resizing

Dear All,

I’ve been recoding my overlay example to use JOGL’s Overlay class. The overlay appears nicely at first (it’s just a text message), but when I resize the window the overlay is drawn at random spots on screen, and even off screen.

Here’s the code:


  private void gameOverMessage()
  {
    Graphics2D g2d = endOverlay.createGraphics();
    if (endOverlay.contentsLost())
      System.out.println("Contents Lost");

    String msg = "Game Over. Your Score: " + score;
 
    // get message dimensions
    FontRenderContext frc = g2d.getFontRenderContext();
    GlyphVector gv = font.createGlyphVector(frc, msg);
    Rectangle msgBounds = gv.getPixelBounds(frc, 0, 0);

    // get (x,y) for centering the text on screen
    int x = (panelWidth - msgBounds.width)/2;   
    int y = (panelHeight + msgBounds.height)/2;

    // write the message in the center of the screen
    g2d.setColor(Color.WHITE);
    g2d.setFont(font);
    g2d.drawString(msg, x, y);

    endOverlay.sync(0, 0, panelWidth, panelHeight);

    endOverlay.drawAll();

    g2d.dispose();
  }  // end of gameOverMessage()

Any suggestions on what the problem may be?

  • Andrew

Do you have a self-contained test case? Does the demos.j2d.TestOverlay demo work properly? Does the problem occur after the first resize or only after several resizes?