Hi,
playing around with the nifty-gui, I wanted to put all the theory in a practical example and see how it performs/looks like.. I choose something simple, the frozen bubble game I am trying to set up a basic scenario, I dont want to have an animator, I want to update the screen on explicit command So far this is the main class /* * To change this template, choose Tools | Templates * and open the template in the editor. */ package core; /** * * @author gbarbieri */ public class FrozenBubble { /** * @param args the command line arguments */ public static void main(String[] args) { Rendering rendering = new Rendering(); } } And the rendering class /* * To change this template, choose Tools | Templates * and open the template in the editor. */ package core; import com.jogamp.newt.opengl.GLWindow; import javax.media.opengl.GLAutoDrawable; import javax.media.opengl.GLCapabilities; import javax.media.opengl.GLEventListener; import javax.media.opengl.GLProfile; /** * * @author gbarbieri */ public class Rendering implements GLEventListener{ private GLWindow glWindow; public Rendering() { initGL(); } private void initGL() { GLProfile profile = GLProfile.get(GLProfile.GL3); GLCapabilities capabilities = new GLCapabilities(profile); glWindow = GLWindow.create(capabilities); glWindow.setAutoSwapBufferMode(true); glWindow.setSize(800, 600); glWindow.addGLEventListener(this); glWindow.setTitle("Frozen Bubble"); glWindow.setVisible(true); } @Override public void init(GLAutoDrawable drawable) { System.out.println("init"); } @Override public void dispose(GLAutoDrawable drawable) { System.out.println("dispose"); } @Override public void display(GLAutoDrawable drawable) { System.out.println("display"); } @Override public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) { System.out.println("reshape"); } } The program shows the windows and shutdowns, obviously The called methods are init, display and dispose How can I set up in order the system to wait (on some user actions through the nifty-gui?) |
Administrator
|
Hi
If you don't use an animator, you'll have to call display() by yourself which is exactly what an animator does. Therefore, I advise you to use an animator. You can add some listeners into the GLWindow to get user's input.
Julien Gouesse | Personal blog | Website
|
I guess there are 2 ways of doing this, a gl-centric, where the class extending the glEventListener will execute everything, in that case we need an animator. Or, we use a modulized approach, where the main program doent know what lie in the renderer, it just call the render method, offer by the renderer... Something like this /* * To change this template, choose Tools | Templates * and open the template in the editor. */ package core; /** * * @author gbarbieri */ public class FrozenBubble implements Runnable{ /** * @param args the command line arguments */ public static void main(String[] args) { FrozenBubble frozenBubble = new FrozenBubble(); new Thread(frozenBubble).start(); } private Rendering rendering; private boolean running; public FrozenBubble(){ rendering = new Rendering(); running = true; } @Override public void run() { while(running){ rendering.render(); } } } Where render() is nothing else than public void render(){ glWindow.display(); } What do you think? If this is one way of doing this right, is it also right that when I instantiate the rendering, it fires automatically, init(), reshape() and display()? Theoretically, shouldn't it call just the init()? |
Administrator
|
If you really want to do that, rather create a GLRunnable that just calls GLWindow.display() and pass it to GLWindow.invoke(), put that code into your render() method.
You can look at a robust framework supporting JOGL without Animator like Ardor3D: https://github.com/Renanse/Ardor3D/blob/master/ardor3d-examples/src/main/java/com/ardor3d/example/ExampleBase.java#L144 https://github.com/Renanse/Ardor3D/blob/master/ardor3d-jogl/src/main/java/com/ardor3d/framework/jogl/JoglAwtCanvas.java#L92 https://github.com/Renanse/Ardor3D/blob/master/ardor3d-jogl/src/main/java/com/ardor3d/framework/jogl/JoglNewtWindow.java#L201 You have to call JOGL methods on the right thread, when the OpenGL context is current (use invoke()). If you try to reinvent the wheel, you will have the same problems than me when I ported Ardor3D to JOGL 2.x but the difference is that: - maybe it will be impossible to fix some of them without breaking your code design - your framework is your problem, your responsibility Don't use animators if and only if you really know what you're doing.
Julien Gouesse | Personal blog | Website
|
The main reason why I want to avoid using an animator, is because I want to avoid useless rendering if nothing changes, I know that for this project is pretty useless, but I would like to have a solid layout for more complex projects. I wonder why the animator is so diffuse |
Administrator
|
On 11/12/2013 11:05 AM, elect [via jogamp] wrote:
> gouessej wrote > You have to call JOGL methods on the right thread, when the OpenGL context > is current (use invoke()). If you try to reinvent the wheel, you will have > the same problems than me when I ported Ardor3D to JOGL 2.x but the > difference is that: > - maybe it will be impossible to fix some of them without breaking your > code design > - your framework is your problem, your responsibility > > Don't use animators if and only if you really know what you're doing. > > The main reason why I want to avoid using an animator, is because I want to > avoid useless rendering if nothing changes, I know that for this project is > pretty useless, but I would like to have a solid layout for more complex > projects. > 'GLAutoDrawable.display()' if you need to update the scene on the screen. Then 'GLAutoDrawable.display()' is also being called when the (native) window needs a refresh (resize .. whatever). Of course, you could also use an animator if you like to animate for a period of time and then pause animation, hence there is a 'pause()' and 'resume()' method in GLAnimatorControl. In short: Animator is optional of course. > I wonder why the animator is so diffuse I don't understand this statement. What is not clear about it ? ~Sven signature.asc (911 bytes) Download Attachment |
This is what I had in mind at the begin.. Which are shortly pro and con of this vs the Arcor3D approach? Ps: regarding the animator, I meant that it just seems to me something "quick and dirty", when you dont want to take care about updating, then you just let it run all the time, but this is just my insignificant opinion :D |
Administrator
|
On 11/12/2013 11:40 AM, elect [via jogamp] wrote:
> Sven Gothel wrote > > Well, you simply can do things w/o an animator and just call > 'GLAutoDrawable.display()' if you need to update the scene on the screen. > > This is what I had in mind at the begin.. > > Which are shortly pro and con of this vs the Arcor3D approach? If this doesn't work - it is a bug, plain and simple. > > Ps: regarding the animator, I meant that it just seems to me something "quick > and dirty", when you dont want to take care about updating, then you just let > it run all the time, but this is just my insignificant opinion :D Ofc .. it's an opt-in. However, folks who have animated scenes most of the time should use an GLAnimatorControl to have more fluent animation. GLAutoDrawable does respect the animator state for example in quite a few cases. GLAnimatorControl is just an interface and can be implemented by anybody and attached to an GLAutoDrawable - pls double check the remarks/requirements in GLAnimatorControl and GLAutoDrawable. Animator and FPSAnimator shall work out of the box .. but one is not limited to them. ~Sven signature.asc (911 bytes) Download Attachment |
Administrator
|
In reply to this post by elect
It's doable with an animator, you can write your own one and add a flag to indicate whether it should really call display(). Animators are optional but I agree with Sven, they work out of the box. Don't use animators if and only if you really know what you're doing because you might waste a lot of time in some particular cases if it doesn't work as expected. I "wasted" about 2 months on several bugs in the JOGL 2.x renderer because of my choice of dropping animators in Ardor3D to comply with its own framework (FrameHandler, ...).
Julien Gouesse | Personal blog | Website
|
In reply to this post by elect
This tutorial assumes that you have sufficient knowledge on OpenGL, but new .... I shall discuss NEWT later...............
|
In reply to this post by elect
This tutorial assumes that you have sufficient knowledge on OpenGL
|
Administrator
|
His example is really minimal. What's wrong with that?
Julien Gouesse | Personal blog | Website
|
Free forum by Nabble | Edit this page |