[SOLVED] GLHandler refuse to init

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

[SOLVED] GLHandler refuse to init

Teapot
This post was updated on .
The program runs normally but GLHandler will not init and its display method will never get invoked unless I tab to desktop then back. Complete source: http://pastebin.com/SaYYAuxP

I'm pretty sure something broke somewhere, but what?
Reply | Threaded
Open this post in threaded view
|

Re: GLHandler refuse to init

Xerxes Rånby
Teapot wrote
The program runs normally but GLHandler will not init and its display method will never get invoked unless I tab to desktop then back. Complete source: http://pastebin.com/SaYYAuxP

I'm pretty sure something broke somewhere, but what?
The GLCanvas components will only initialize after they have become visible.

your application needs to follow the swing coding guidelines:
1. all swing components has to be manipulated from the "event dispatch thread"
http://docs.oracle.com/javase/tutorial/uiswing/concurrency/initial.html
rewrite your main to use the SwingUtils like this in order to satisfy this Swing/AWT "event patch thread" rule:
  public static void main(String[] args)
  {
    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            JFrame frame = new test();
        }
    }
  }

2. after you have added canvas using add(canvas); you need to re-validate the JFrame in order for it to relayout its components and make the newly added canvas visible.
you can re-validate the JFrame by calling its pack() or validate() method.
http://docs.oracle.com/javase/6/docs/api/java/awt/Container.html#validate%28%29 
This should make the component visible and initialize the JogAmp GLCanvas.


If you want to make your application more portable then i recommend you to stop using all swing & awt components and simply use a JogAmp NEWT GLWindow.

Cheers
Xerxes
Reply | Threaded
Open this post in threaded view
|

Re: GLHandler refuse to init

Teapot
 1. all swing components has to be manipulated from the "event dispatch thread"
I've tested both invokeAndWait and invokeLater and they didnt seem to have any effects (from an user POV). I'm keep it in mind but for now I'll stick to my "dont add stuff that does nothing" guideline.

 2. you need to re-validate the JFrame
Just what I need! validate() works but pack() doesnt. Probably has something to do with my "screw Java guidelines, I" approach. Case closed.

 Simply use a JogAmp NEWT GLWindow
I've considered but I have a fairly big code base and I'm not really comfortable with opengl/jogl yet so I'll hybridize for now. Sorry for my stubbornness for I'll continue troubling the forum with my problems.

Off-topic: How do I quote username like you did?
Reply | Threaded
Open this post in threaded view
|

Re: GLHandler refuse to init

gouessej
Administrator
Please follow at least Swing guidelines in order to avoid causing much more troubles in the future. Don't wait to do that, otherwise you might have some problems whose root cause will be difficult to identify in a few months when you forget our advice. For example, the OpenGL context won't be created on some hardware and JOGL will crash if you call setVisible(true) on the wrong thread.
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|

Re: GLHandler refuse to init

Teapot
Don't wait to do that, otherwise you might have some problems whose root cause will be difficult to identify in a few months when you forget our advice. For example, the OpenGL context won't be created on some hardware and JOGL will crash if you call setVisible(true) on the wrong thread.
 Thank you for the advice. See, if I havent waited, no one would drop by and explain why (or in a way my little mind can comprehend).
Reply | Threaded
Open this post in threaded view
|

Re: GLHandler refuse to init

gouessej
Administrator
You're welcome. This problem occurs with Intel GPUs under Windows but any other less tolerant drivers of any other vendor might behave like this one day.
Julien Gouesse | Personal blog | Website