AWTGLCanvas Responsiveness

Started by Lagz, March 18, 2007, 02:01:40

Previous topic - Next topic

Lagz

Hi,

I'm new to LWJGL and I'm trying to set up a LWJGL canvas which can be resized and dragged around (like a normal window). At the moment I have extended AWTGLCanvas and added an instance of this class to a JFrame:

public class MyTest  {
  
	public static void main(String[] iArgs)
	{
		try
		{
		JFrame lFrame = new JFrame();
		Canvas canvas = new MyCanvas();
		canvas.setPreferredSize(new Dimension(400,400));
		lFrame.add(canvas);
		lFrame.pack();
		lFrame.setVisible(true);
		}
		catch(Exception e)
		{
			e.printStackTrace();
		}
	}
	
  public static class MyCanvas extends AWTGLCanvas {
        
    public MyCanvas() throws LWJGLException {
      Thread t = new Thread() {
        public void run() {
          while (true) {
            if (isVisible()) {
              repaint();
          	  Thread.yield();
            }
          }
        }
      };
      t.setDaemon(true);
      t.start();      
    }
    
    public void paintGL() {
      //Render some stuff here
      try {
        swapBuffers();
      } catch (Exception e) {
      }
    }   
  }


The only problem that the frame seems very unresponsive when it is dragged and resized. The Thread.yield() helps quite a lot (without it dragging will only move the window about 1 time per second!), but I feel this isn't the correct way to do things...

What is the best way to setup LWJGL in a resizable window and what am I doing wrong in the code above? Any sample code would be excellent.

Lagz

It seems that this problem occurs when vsync is enabled. With vsync disabled the window is responsive.

Presumably this means that the thread which is in charge of moving and resizing the window is somewhere being blocked to wait for vsync? Would probably make sense to avoid this in the next release if possible (and if this is whats going on).