Newt, Multi-Touch, looking for a Pen Pressure example

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Newt, Multi-Touch, looking for a Pen Pressure example

Andre
This post was updated on .
Hello,

i am working on an early version of a tablet pc drawing program.
i wrote it so far with Swing/Jogl.

1.
While checking out Newt i discovered the multi-touch input which is a great help in paint soft = zoom, pan.
Other frameworks for multi-touch java made me dizzy.

To my disappointment i noticed that the Newt Window closes without animator.

(The prior prototype i wrote only calls display when the mouse is in interaction.
Never in a loop, just refreshing display on mouse modifications, increased performance immensely,
cooled down PC and gave me more ticks for the mouse and so a smoother pen which is crucial.

i figured out to get around the shutdown with starting and stopping the animator and then
running display on my own via mouse again.

                [...]

                animator.start(); // start the animator loop
                animator.pause();
               
                [...]


FEELS dirty.... any better idea? Despite of that NEWT looks great.

2.
Currently i am looking for a Pen Pressure example.... (surface pro 8) and i could not find a self made way so far.
I am using Window (ink) Pen and Wacom.

THX...






I am a Robot
Reply | Threaded
Open this post in threaded view
|

Re: Jogl, Newt, Wondering about shutdown without animator, looking for pen pressure example

mahesh
Not working for me as well  MouseEvent.getPressure(true) always return pressure as 1 in my surface pro6 (jogl2.4 with NEWT windows 11).



Reply | Threaded
Open this post in threaded view
|

Multi-touch, Multitouch

Andre
This post was updated on .
In reply to this post by Andre
Quick&dirty Multitouch... Done!





Import java.awt.Toolkit;
import com.jogamp.newt.event.MouseEvent;
import com.jogamp.newt.event.MouseListener;
import com.jogamp.newt.event.WindowAdapter;
import com.jogamp.newt.event.WindowEvent;
import com.jogamp.newt.opengl.GLWindow;
import com.jogamp.opengl.GL2;
import com.jogamp.opengl.GLAutoDrawable;
import com.jogamp.opengl.GLCapabilities;
import com.jogamp.opengl.GLEventListener;
import com.jogamp.opengl.GLProfile;
import com.jogamp.opengl.util.FPSAnimator;

public class Example_Jogl_NEWT_Multi_Touch {

        private static final int WINDOW_WIDTH = 1280;
        private static final int WINDOW_HEIGHT = 900;
        static int touch = 0;
        static int touch1x = 0;
        static int touch1y = 0;
        static int touch2x = 0;
        static int touch2y = 0;
        static int pointerSize = 150;
        static int window_center_x;
        static int window_center_y;

        public static void main(String[] args) {
                System.setProperty("sun.java2d.uiScale", "1");
                GLProfile glp = GLProfile.getDefault();
                GLCapabilities caps = new GLCapabilities(glp);
                GLWindow window = GLWindow.create(caps);
                final FPSAnimator animator = new FPSAnimator(window, 60, true);
                window_center_y = (int) (Toolkit.getDefaultToolkit().getScreenSize().getHeight() / 2) - WINDOW_HEIGHT / 2;
                window_center_x = (int) (Toolkit.getDefaultToolkit().getScreenSize().getWidth() / 2) - WINDOW_WIDTH / 2;
                window.setPosition(window_center_x, window_center_y);
                window.setSize(WINDOW_WIDTH, WINDOW_HEIGHT);
                window.addGLEventListener(new Listener());
                window.addMouseListener(new Listener2());
                window.setVisible(true);
                window.addWindowListener(new WindowAdapter() {
                        public void windowDestroyNotify(WindowEvent arg0) {
                                new Thread() {

                                        public void run() {
                                                if (animator.isStarted())
                                                        animator.stop();
                                                System.exit(0);
                                        }
                                }.start();
                        }
                });
                animator.start();
        }

        static class Listener implements GLEventListener {

                public void init(GLAutoDrawable d) {
                }

                public void dispose(GLAutoDrawable drawable) {
                }

                public void display(GLAutoDrawable drawable) {
                        GL2 gl = drawable.getGL().getGL2();
                        gl.glClearColor(0f, 0f, 1f, 1f);
                        gl.glClear(GL2.GL_COLOR_BUFFER_BIT);
                        gl.glMatrixMode(GL2.GL_MODELVIEW);
                        gl.glLoadIdentity();
                        gl.glPushMatrix();
                        gl.glColor4f(1f, 0f, 0f, 1f);
                        if (touch == 1) {
                                gl.glBegin(GL2.GL_POLYGON);
                                gl.glVertex3d(touch1x - pointerSize / 2, touch1y - pointerSize / 2, 0);
                                gl.glVertex3d(touch1x - pointerSize / 2, touch1y + pointerSize / 2, 0);
                                gl.glVertex3d(touch1x + pointerSize / 2, touch1y + pointerSize / 2, 0);
                                gl.glVertex3d(touch1x + pointerSize / 2, touch1y - pointerSize / 2, 0);
                                gl.glEnd();
                        } else if (touch == 2) {
                                gl.glBegin(GL2.GL_POLYGON);
                                gl.glVertex3d(touch1x - pointerSize / 2, touch1y - pointerSize / 2, 0);
                                gl.glVertex3d(touch1x - pointerSize / 2, touch1y + pointerSize / 2, 0);
                                gl.glVertex3d(touch1x + pointerSize / 2, touch1y + pointerSize / 2, 0);
                                gl.glVertex3d(touch1x + pointerSize / 2, touch1y - pointerSize / 2, 0);
                                gl.glEnd();
                                gl.glBegin(GL2.GL_POLYGON);
                                gl.glVertex3d(touch2x - pointerSize / 2, touch2y - pointerSize / 2, 0);
                                gl.glVertex3d(touch2x - pointerSize / 2, touch2y + pointerSize / 2, 0);
                                gl.glVertex3d(touch2x + pointerSize / 2, touch2y + pointerSize / 2, 0);
                                gl.glVertex3d(touch2x + pointerSize / 2, touch2y - pointerSize / 2, 0);
                                gl.glEnd();
                        }
                        gl.glPopMatrix();
                        gl.glFlush();
                }

                public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {
                        GL2 gl = drawable.getGL().getGL2();
                        gl.glViewport(0, 0, width, height);
                        gl.glMatrixMode(GL2.GL_PROJECTION);
                        gl.glLoadIdentity();
                        gl.glOrtho(0, width, height, 0, -1000, 10000);
                }

        }

        static class Listener2 implements MouseListener {

                public void mousePressed(MouseEvent e) {
                        touchTransport(e);
                }

                public void mouseDragged(MouseEvent e) {
                        touchTransport(e);
                }

                public void mouseReleased(MouseEvent e) {
                        touch = 0;
                }

                public void mouseClicked(MouseEvent e) {
                }

                public void mouseEntered(MouseEvent e) {
                }

                public void mouseExited(MouseEvent e) {
                }

                public void mouseMoved(MouseEvent e) {
                }

                public void mouseWheelMoved(MouseEvent e) {
                }

                private void touchTransport(MouseEvent e) {
                        if (e.getPointerCount() == 1) {
                                touch = 1;
                                touch1x = e.getX(0);
                                touch1y = e.getY(0);
                        } else if (e.getPointerCount() == 2) {
                                touch = 2;
                                touch1x = e.getX(0);
                                touch1y = e.getY(0);
                                touch2x = e.getX(1);
                                touch2y = e.getY(1);
                        } else if (e.getPointerCount() >= 2) {
                                touch = 0;
                        }
                }

        }

}
I am a Robot
Reply | Threaded
Open this post in threaded view
|

Pen Support

Andre
This post was updated on .
This corner here in com.jogamp.newt.event.MouseEvent.java made me aware of Stylus support. Win11 here.... still looking.
Another Detail: (Bamboo Stylus ink Plus) i am just getting button 1 and 3. And 3 is inutile because its not draggable.
The pen has 3 buttons and in some Applications like WhiteBoard or Mischief i can see that they have it done.

The Wacom Tablet on the other side runs fine with the Buttons 1 2 3 but no pressure as well.

I am a Robot
Reply | Threaded
Open this post in threaded view
|

Newt Events

Andre
This post was updated on .
In reply to this post by mahesh
@Mahesh
it's probably the case that the pen is recognized as Touch input



Still testing here ....
I am a Robot
Reply | Threaded
Open this post in threaded view
|

Newt & jPen

Andre
Reply | Threaded
Open this post in threaded view
|

Re: Newt & jPen

Andre
nope :/

I am a Robot