Author Topic: mouse responsiveness with AWTGL renderer?  (Read 2733 times)

Offline slenkar

  • byte
  • *
  • Posts: 20
    • View Profile
mouse responsiveness with AWTGL renderer?
« on: June 01, 2009, 04:59:46 pm »
Has anyone noticed a lack of mouse-button responsiveness with the AWTGL renderer?
The mouse movements and keyboard work fine but the mouse button isnt always registered.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11776
    • View Profile
    • http://www.jpct.net
Re: mouse responsiveness with AWTGL renderer?
« Reply #1 on: June 01, 2009, 05:42:17 pm »
No idea. jPCT doesn't do anything with the mouse...it's all done by LWJGL. You may try to add a Thread.yield() or Thread.sleep(1) to your main loop and/or implement an IPaintListener and add the yield/sleep in either before- or afterPainting-method, but that's just a wild guess...i've no idea if it helps.

Offline slenkar

  • byte
  • *
  • Posts: 20
    • View Profile
Re: mouse responsiveness with AWTGL renderer?
« Reply #2 on: June 01, 2009, 05:44:11 pm »
Im using AWT to handle mouse and keyboard events ,is this the reason?

When I use Lwjgl to handle events the screen goes blank, is there a different renderer that allows lwjgl mouse handling?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11776
    • View Profile
    • http://www.jpct.net
Re: mouse responsiveness with AWTGL renderer?
« Reply #3 on: June 01, 2009, 08:46:38 pm »
Depends on your needs. If you need AWT/Swing integration, you have to use the AWTGLRenderer and the AWT events for mouse and keyboard. If you don't need that, you can use the native GLRenderer instead. There's a HelloWorld for this one too.
You can't use LWJGL's mouse and keyboard implementations with the AWTGLRenderer. One last option, if nothing else helps, is to use the JOGL-renderer instead.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11776
    • View Profile
    • http://www.jpct.net
Re: mouse responsiveness with AWTGL renderer?
« Reply #4 on: June 01, 2009, 09:03:13 pm »
The mouse movements and keyboard work fine but the mouse button isnt always registered.
If the movements work fine, i would expect the buttons to be responsive too. Are you 100% sure that it's not your code's fault? Do you have a simple test case that shows the problem? Maybe it's related to your machine only somehow!?

Offline slenkar

  • byte
  • *
  • Posts: 20
    • View Profile
Re: mouse responsiveness with AWTGL renderer?
« Reply #5 on: June 02, 2009, 04:11:14 pm »
I did some tests and realised it happens when moving the mouse and pressing the button at the same time.

Code: [Select]
import com.threed.jpct.*;

//import javax.swing.*;
import java.awt.*;
import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.awt.event.KeyListener;
//import java.awt.Insets;
import javax.swing.JFrame;

public class mousebutton extends JFrame implements MouseListener,
MouseMotionListener,KeyListener {
public static World world;
private FrameBuffer buffer;
public JFrame frame;
   
public void keyPressed(KeyEvent e)
{}

public void keyTyped(KeyEvent e)
{
if (e.getKeyCode()==KeyEvent.VK_A)
{
//System.out.println("typed a");
}
//nothing
}
public void keyReleased(KeyEvent e)
{
if (e.getKeyCode()==KeyEvent.VK_W)
{
    //System.out.println("released a");
}
//nothing
}

public static void main(String[] args) throws Exception {
new mousebutton().loop();
}

 public void mouseEntered( MouseEvent e ) {}
    public void mouseExited( MouseEvent e ) {}
    public void mouseReleased( MouseEvent e ){
   
    System.out.println("mouse released");
    }
    public void mouseClicked( MouseEvent e ){
   
    System.out.println("mouse clicked");
    }
    public void mousePressed( MouseEvent e )
    {
     
      }



  public void mouseMoved( MouseEvent e ) {
 
        int x = e.getX();
        int y = e.getY();
 
  }
    public void mouseDragged( MouseEvent e )
    {
   
        // get the mouse's coordinates:

    }


public mousebutton() throws Exception {

frame=new JFrame("Hello world");
frame.setSize(800, 600);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
}



private void loop() throws Exception {
FrameBuffer buffer = new FrameBuffer(800, 600, FrameBuffer.SAMPLINGMODE_NORMAL);
Canvas canvas=buffer.enableGLCanvasRenderer();
buffer.disableRenderer(IRenderer.RENDERER_SOFTWARE);
frame.add(canvas);
canvas.addMouseListener( this );
        canvas.addMouseMotionListener( this );
        canvas.addKeyListener(this);
while (frame.isShowing()) {


buffer.clear(java.awt.Color.BLACK);
world.renderScene(buffer);
world.draw(buffer);
buffer.update();
buffer.displayGLOnly();

canvas.repaint();

//Bullet.update_bullets();
Thread.sleep(10);
//System.out.println(Mouse.getDX());
}
//buffer.disableRenderer(IRenderer.RENDERER_OPENGL);
// buffer.dispose();
frame.dispose();
System.exit(0);
}

}

notice only mouse release events are generated, when moving the mouse

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11776
    • View Profile
    • http://www.jpct.net
Re: mouse responsiveness with AWTGL renderer?
« Reply #6 on: June 02, 2009, 08:01:42 pm »
I would say that this is correct behaviour. When pressing at x and releasing at y, it's not a click, because you haven't clicked on something. Compare mousePressed() to mouseReleased() instead and you'll see that both events will be fired no matter if you drag the mouse or not.

Offline slenkar

  • byte
  • *
  • Posts: 20
    • View Profile
Re: mouse responsiveness with AWTGL renderer?
« Reply #7 on: June 02, 2009, 08:23:51 pm »
ah ok thanks,

I switched to the normal gl renderer in the end

Ill keep that in mind if i have to switch back for some reason.