Re: glBegin/glEnd inside methods of MouseListener
Posted by Xfel on Dec 06, 2010; 7:09am
URL: https://forum.jogamp.org/glBegin-glEnd-inside-methods-of-MouseListener-tp2023145p2025739.html
The GLContext has to be current on the thread you are rendering in. It automatically is in display, init, reshape and dispose.
so you would have to code:
public void mousePressed(MouseEvent me) {
context.makeCurrent();
gl.glBegin(GL.GL_LINE_STRIP);
gl.glVertex3f(0,0,0);
gl.glVertex3f(100,50,0);
gl.glVertex3f(200,100,0);
gl.glVertex3f(100,150,0);
gl.glEnd();
gl.glFlush();
context.release();
}
but this is also no good cone in general, because wif your scene is rendered for other reasons, like a system-repaint, your vertices will not be drawn.
it is better if you just handle the information provided by the mouse event (eg. where the mouse points to), save it and call repaint() or display();
in display(..) you render your scene and nowhere else.
This is a part of my trackball implementation:
@Override
public void mouseWheelMoved(MouseWheelEvent e)
{
transZ += e.getWheelRotation() * 6f;
if(transZ<0) {
transZ=0;
}
drawable.display();
}
@Override
public void display(GLAutoDrawable drawable)
{
...
gl.glTranslatef(-transX, transY, transZ);
gl.glRotatef(rotX, 1, 0, 0);
gl.glRotatef(rotY, 0, 1, 0);
gl.glScalef(scale, scale, scale);
//Now you may render
...
}