How can I draw navigator button on GLcanvas

hi, I want to make navigator button like upright corner in google earth program. I use java jogl. How can I do this.

First of, for JOGL questions go to this forum:

http://www.javagaming.org/index.php?board=25.0

Now on to your question regarding the button. I don’t know what Google Earth has per se so I’m going to be guessing here. I’m guessing you want some kind of overlay functionality which looks like a button that you can press it and based on your screen coordinates you could figure out if you are over a button and then you perform some kind of response.

I think in strict OpenGL you would have to affect your view matrix so that you were effectively display onto the 2D screen and then you would have to draw your own button and then do your own checking whether you clicked on the button. I can’t comment on this because I never did this beyond displaying text on the screen as an overlay using glRasterPos2?? (or something like this)

In regards to the JOGL GLCanvas, you would have to do something similar to the OpenGL solution, but I’m not sure you want this per se. I think you probably would want the capabilities of Java to override the paintComponent() of your panel and to draw your button using the paintComponent()…and using a mouse listener to determine mouse coordinates and mouse clicks to determine if you are over the buttons, etc.

This last option would be possible with GLCanvas as it is a Heavyweight component and I don’t believe you can even override the paintComponent…and if you could, it would not display the image of the button on top because of the heavyweight issue.

Instead, you need to use GLJPanel, as it is a lightweight component and you can override the paint component of the panel to draw button on top. For example you would have the following code:


    ...
    canvas = new GLJPanel(caps) {

      public void paintComponent( Graphics g ) {
        super.paintComponent(g);

        g.setColor(Color.WHITE);

        ... other drawing commands here ...
      }
    }
    ...

Then you would have those mouse listeners to determine if your mouse was over any of the buttons you drew. You might even be able to mix SWING buttons in the GLJPanel, but I’m not sure about this.

For an example of the overlays, not buttons per se, but effectively the same thing…think overlays as buttons without the button listener implemented…anyway, for an example, check out the JGears example code available with JOGL. (Note Gears is the GLCanvas example, JGears is the GLJPanel example)