Login  Register

Re: Setting render loop without using FPSAnimator

Posted by Sven Gothel on Jun 13, 2012; 11:21pm
URL: https://forum.jogamp.org/Setting-render-loop-without-using-FPSAnimator-tp4025143p4025213.html

On 06/05/2012 09:49 AM, sasmaster [via jogamp] wrote:

> Hi All. I am not a Java or JOGL pro and come from other languages .What I see
> here in most of the demos is that the GLCanvas
> is passed to the animator  and the init() method if the main class that
> implements GLEventListener is triggered only after the animator starts .This
> pipeline creates some restrictions like that I need to wait for the GL3
> context to be made in that method .I tried to call init () explicitly without
> using animator and the context is invalid .My problem here is that I have a
> Main.java which doesn't implement GLEventListener but  serves only as an entry
> point for the app.Then I have another class which does implement
> GLEventListener  called View3d.So I want to init() the  View3D in the
> Main.java without using any animator and then just add a render loop like this :
>
> while (true){
>    view.render()
> }
>
> Currently if I add any GL calls after I start the animator the context is
> still not created .It seems like even when animator.start() is called  the
> call to init() of View doesn't happen immediately and any code fallowing the
> animator.start() is executed  . Is it asynchronous ? Or happens on separate
> thread ?  I mean in C++ it is synchronous and  procedural and I really have a
> hard time with all this init process in Java .
>
Julien already hinted the benefits of using the GLEventListener (GLEL) model.
Using it allows you to impl. your own GLEL and attach it to an
GLAutoDrawable (GLAD) implementation like GLCanvas (AWT, SWT)
or GLWindow (NEWT).

Supporting such an easy to use mechanism in JOGL doesn't mean at all
to being forced to use it.

Look at the following unit tests how you can use the lower level
JOGL API to create your own GLDrawable and GLContext instance using NEWT:

+++

NEWT-1:
[1] http://jogamp.org/git/?p=jogl.git;a=blob;f=src/test/com/jogamp/opengl/test/junit/jogl/drawable/TestDrawable01NEWT.java;hb=HEAD#l75

Simple manual creation of NEWT window and creating a GLDrawable/GLContext on top of it
while issuing simple GL commands.

+++

NEWT-2:
[2] http://jogamp.org/git/?p=jogl.git;a=blob;f=src/test/com/jogamp/opengl/test/junit/util/NEWTGLContext.java;hb=HEAD#l92
[3] http://jogamp.org/git/?p=jogl.git;a=blob;f=src/test/com/jogamp/opengl/test/junit/jogl/glsl/TestRulerNEWT01.java;hb=HEAD#l66

[2] uses [3] to create a NEWT window and creating a GLDrawable/GLContext on top of it.
This example [2] also utilizes GLSL rendering.

+++

It is quite complicated to do the above w/ AWT or SWT
since a lot of 'timing' and information has to be passed.
If you look at the AWT GLCanvas implementation you may understand.

So if you like to have a 'view.render()' thingy here for NEWT and AWT,
I would recommend to simply use a GLAD implementation (see above)
and attach you GLEventListener implementation to it:

  GLCanvas glad = ... ; // or GLWindow glad = .. ;
  ...
  while(true) {
     glad.display();
  }

+++

As Julien mentioned, we don't restrict you of anything in our API,
but sometimes it's just easier to use the so called 'managed path'.

Of course, one can always implement their own GLAutoDrawable
and/or GLAnimatorControl (Animator, FPSAnimator).

[4] http://jogamp.org/deployment/jogamp-next/javadoc/jogl/javadoc/javax/media/opengl/GLAutoDrawable.html

To implement your own GLAnimatorCtrl, don't forget to attach
it to your GLAutoDrawable of your choice.

[5] http://jogamp.org/deployment/jogamp-next/javadoc/jogl/javadoc/javax/media/opengl/GLAutoDrawable.html#setAnimator%28javax.media.opengl.GLAnimatorControl%29

~Sven

> Thanks for help.
>
>
>


signature.asc (910 bytes) Download Attachment