Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (711)
Games in Android Showcase (213)
games submitted by our members
Games in WIP (785)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  glOrtho and wacky Mouse  (Read 1591 times)
0 Members and 1 Guest are viewing this topic.
Offline ajaskey

Junior Newbie

« Posted 2006-11-02 21:37:14 »

Hi.  I've found lotsa info close to what I want, but what I need is very simple.  I started with the SimpleJOGL program from the Netbeans template and created a virtual coordinate test program.  My program will draw a rectangle and a line within the virtual system (-1000,-1000 to 15000,15000), but I can't figure out how to get the mouse to return X,Y based on the virtual system.  Currently this program returns the X,Y of the screen with 0,0 in the upper left hand corner and with lower right as 600,400.  What call do I need to make to tell the mouse to return virtual coordinates in with the getX and getY?


import java.awt.*;
import java.awt.event.*;
import com.sun.opengl.util.*;
 * <BR>
 * author: Brian Paul (converted to Java by Ron Cemer and Sven Goethel) <P>
 * This version is equal to Brian Paul's version 1.2 1999/10/21

public class VirtualJOGL implements GLEventListener {   
    private static final int SIZE = 160;
    private MouseMotionAdapter mouseMotionListener = new MouseMotionAdapter() {
        public void mouseDragged(MouseEvent e) {
            motionMethod(e, e.getX(), e.getY());
        public void mouseMoved(MouseEvent e) {
            passiveMotionMethod(e, e.getX(), e.getY());
    private MouseAdapter mouseListener = new MouseAdapter() {
        public void mousePressed(MouseEvent e) {
            mouseMethod(e, e.getModifiers(), true, e.getX(), e.getY());
        public void mouseReleased(MouseEvent e) {
            mouseMethod(e, e.getModifiers(), false, e.getX(), e.getY());
    private void passiveMotionMethod(MouseEvent e, int x, int y) {
    private void motionMethod(MouseEvent e, int x, int y) {
    private void mouseMethod(MouseEvent e, int mods, boolean press,
            int x, int y) {
        if (press) {
            System.out.print("Mouse Clicked : ");
            System.out.print(" ");
            System.out.println(" ");
    public static void main(String[] args) {
        Frame frame = new Frame("Virtual JOGL Application");
        GLCanvas canvas = new GLCanvas();
        canvas.addGLEventListener(new VirtualJOGL());
        frame.setSize(600, 400);
        final Animator animator = new Animator(canvas);
        frame.addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent e) {
                // Run this on another thread than the AWT event queue to
                // make sure the call to Animator.stop() completes before
                // exiting
                new Thread(new Runnable() {
                    public void run() {
        // Center frame
    public void init(GLAutoDrawable drawable) {
        // Use debug pipeline
        // drawable.setGL(new DebugGL(drawable.getGL()));
        GL gl = drawable.getGL();
        System.err.println("INIT GL IS: " + gl.getClass().getName());
        gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
     * @param drawable
     * @param x
     * @param y
     * @param width
     * @param height
    public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {
        GL gl = drawable.getGL();
        gl.glViewport(0, 0, width, height);
    public void display(GLAutoDrawable drawable) {
        GL gl = drawable.getGL();
        gl.glColor3f(1, 0, 0);
        gl.glRecti(100, 100, 1500, 1500);
        gl.glColor3f(0.0f, 0.0f, 0.0f);
    public void displayChanged(GLAutoDrawable drawable, boolean modeChanged, boolean deviceChanged) {

Offline turquoise3232

Junior Devvie

Java (games) rock!

« Reply #1 - Posted 2006-11-03 17:19:53 »


Since you have a simple glOrtho projection you can do the math yourself. You can also use gluUnproject routine do make the conversion. Search this forum to find some samples.
Hope it helps.
Offline ajaskey

Junior Newbie

« Reply #2 - Posted 2006-11-06 01:20:26 »


Since you have a simple glOrtho projection you can do the math yourself. You can also use gluUnproject routine do make the conversion. Search this forum to find some samples.
Hope it helps.

Turquoise - thanx for the gluUnproject help.  I found an example and got it working.

Pages: [1]
  ignore  |  Print  
You cannot reply to this message, because it is very, very old.

numerical (247 views)
2017-02-21 07:32:16

numerical (246 views)
2017-02-21 07:31:46

theagentd (359 views)
2017-02-18 13:42:33

theagentd (358 views)
2017-02-18 13:35:16

h.pernpeintner (1524 views)
2017-01-24 22:39:11

h.pernpeintner (1512 views)
2017-01-24 22:38:32

Galdo (2076 views)
2017-01-12 13:44:09

Archive (2090 views)
2017-01-02 05:31:41

0AndrewShepherd0 (2627 views)
2016-12-16 03:58:39

0AndrewShepherd0 (2342 views)
2016-12-15 21:50:57
List of Learning Resources
by elect
2016-09-09 09:47:55

List of Learning Resources
by elect
2016-09-08 09:47:20

List of Learning Resources
by elect
2016-09-08 09:46:51

List of Learning Resources
by elect
2016-09-08 09:46:27

List of Learning Resources
by elect
2016-09-08 09:45:41

List of Learning Resources
by elect
2016-09-08 08:39:20

List of Learning Resources
by elect
2016-09-08 08:38:19

Rendering resources
by Roquen
2016-08-08 05:55:21 is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!