Hey guys, im very new in Jogl and I have a problem in every Game i made until now (only stuff like Tetris) i used this game loop http://pastebin.com/d4DDnL0T works pretty fine, but now in Jogl I have the problem that there is a FPSAnimator and he calls the render method while my other Thread is doing the update Method so im getting errors because while he renders something its getting deleted in the update Method and so I get errors.
Any Suggestions? |
Administrator
|
Hi
You can create your own animator, use Animator or AnimatorControl. You shouldn't create another thread to do that. There is another simple solution, enable v-sync in JOGL, don't use FPSAnimator at all, keep your loop as is, just add a call of GLAutoDrawable.display() at the end. My loops in my games look like this one: while (!exit) { tick();//update the timer update();//update the data model render();//update the rendering }
Julien Gouesse | Personal blog | Website
|
Hey thank you for your anwser :)
I would prefer to use my old gameloop because in my opinion it works pretty well, but i dont understand how I can call the display method without a Animator, could you give me a short example how to call the display Method without it? :) |
Administrator
|
This is in the documentation:
http://jogamp.org/deployment/jogamp-next/javadoc/jogl/javadoc/javax/media/opengl/GLAutoDrawable.html#display() You can use it with any subclass of GLAutoDrawable, GLCanvas, GLWindow, GLJPanel, ...
Julien Gouesse | Personal blog | Website
|
oh lol its so easy just canvas.display(); thank you :)
But now I have a other Problem because DepthTest dont work and I couldnt find something in Google what helps me because i initialized it in the init Method and I am also clearing the deph buffer bits etc. in the Display Method. Here are the important parts of my Code: http://pastebin.com/BndPCQVG |
Administrator
|
You can call your initialization code only once in your display method but it is a bit ugly.
Maybe you should consider writing your own animator.
Julien Gouesse | Personal blog | Website
|
and why depth test dont work? I dont really understand the problem :( render / update is fixed now.
|
Administrator
|
If you don't use any animator, nothing will call GLEventListener.init(GLAutoDrawable) and then your depth test will never be enabled.
Edit.: You would have less troubles if you put the main operations (tick, update, render) into an animator. @Sven Do we have an example using GLAnimatorControl?
Julien Gouesse | Personal blog | Website
|
Administrator
|
On 02/22/2014 11:15 PM, gouessej [via jogamp] wrote:
> If you don't use any animator, nothing will call > GLEventListener.init(GLAutoDrawable) and then your depth test will never be > enabled. GLEventListener.init(..) is agnostic to animator, it will always be called once for each GLEventListener added to an GLAutoDrawable. ~Sven signature.asc (894 bytes) Download Attachment |
This post was updated on .
Okay I think i understand the Problem but I dont understand why I get the System.out.println of the init Method and not the Depth Test, how can I fix the problem so Depth Test will work?
I only want to use a Animator if I have no problems with it, this means I can say how often the Update Method gets called and the render Method as fast as possible (or limited later) and that the animator dont update and render on the same time. But I dont know how to write my own Animator so I think it's the same work as doing it with my loop. Here is my full main Class: http://pastebin.com/usEX0Gie And btw thank you for helping me I know im very very bad in initializing things etc. in Java or espacially Jogl because I dont know many basic stuff like sub-Interfaces etc. Im much better in coding my final game if the Gameloop etc works :D |
Administrator
|
On 02/23/2014 12:44 AM, Martin128890435 [via jogamp] wrote:
> Okay I think i understand the Problem but I dont understand why I get the > System.out.println of the init Method and not the Depth Test, how can I fix > the problem? I really dont want to use Animator (really dont like them) und > everything else works pretty well with my Loop. > I have not followed your discussion in depth. 'Depth Test' must be invoked from one of your GLEventListener methods where the GLEventListener is added to a GLAutoDrawable. Then your 'Depth Test' shall be invoked accordingly .. Test your code maybe w/ properties '-Djogl.debug.DebugGL' and/or '-Djogl.debug.TraceGL' +++ Also have a close look at: GLAutoDrawable in general: <http://jogamp.org/deployment/jogamp-next/javadoc/jogl/javadoc/javax/media/opengl/GLAutoDrawable.html> GLAutoDrawable / GLAnimatorControl: <http://jogamp.org/deployment/jogamp-next/javadoc/jogl/javadoc/javax/media/opengl/GLAutoDrawable.html#setAnimator%28javax.media.opengl.GLAnimatorControl%29> GLAnimatorControl: <http://jogamp.org/deployment/jogamp-next/javadoc/jogl/javadoc/javax/media/opengl/GLAnimatorControl.html> ^^ GLAnimatorControl helps the GLAutoDrawable implementation to determine whether certain actions shall happen 'now' (no animation) or shall be deferred to be called by the animator thread, besides other issues, it allows a more fluent animation performed on a dedicated thread. If you like to have your own animator / loop, it is advised to implement the GLAnimatorControl interface and attach it to the GLAutoDrawable via setAnimator(..). However .. it is optional, ofc. ~Sven signature.asc (894 bytes) Download Attachment |
Administrator
|
In reply to this post by Sven Gothel
Thank you for "fixing" my explanation. Then, if I call GLAutoDrawable.display(), GLEventListener.init(GLAutoDrawable) will be called once (maybe earlier), and GLEventListener.display(GLAutoDrawable) will be called on the "good" thread (for example the AWT EDT for the AWT GLCanvas), won't it?
Julien Gouesse | Personal blog | Website
|
Well thank you for your anwser's but I still dont get how I can enable Depth test I mean i can remove the FPS limitation in my Init method but I cant enable Depth test?
|
We can't tell from your code why you think depth testing does not work, you don't show any rendering code or shaders. Maybe you render all objects with the same depth, or the wrong depth, or you disable depth testing somewhere else or... This has helped me when tracking down such errors in my code: http://jogamp.org/wiki/index.php/How_to_use_the_Debug_and_Trace_GL_Pipeline_and_Debug_GL_Context Enable tracing, maybe that can give you a clue to what is happening. |
Hey thank you for your anwser, my render code only looks like this :http://pastebin.com/aqjL31At so I only use Vertex3f, Triangles or Quads and color3f nothing more shaders well I dont have shaders yet, and I have no fucking Idea how I shall activate these debug things I mean the site gives me a Line of Code and I have no idea what I shall do with it :/
|
Administrator
|
In reply to this post by gouessej
On 02/23/2014 09:48 AM, gouessej [via jogamp] wrote:
> Sven Gothel wrote > GLEventListener.init(..) is agnostic to animator, > it will always be called once for each GLEventListener added to an > GLAutoDrawable. > > Thank you for "fixing" my explanation. Then, if I call > GLAutoDrawable.display(), GLEventListener.init(GLAutoDrawable) will be called > once (maybe earlier), and GLEventListener.display(GLAutoDrawable) will be > called on the "good" thread (for example the AWT EDT for the AWT GLCanvas), > won't it? GLAD == GLAutoDrawable Yes, 'GLEL.init' is ensured, even if the GLEL is added to the GLAD after it's initialization ('GLAD.addGLEventListener'). It will be called on the animator thread. The AWT-GLAD itself may delegate the task to the AWT-EDT. 'GLEL.dispose' is called either by destroying the GLAD, or by calling 'GLAD.disposeGLEventListener'. 'GLAD.removeGLEventListener' will not issue the dispose due to historical reasons .. All in all, the GLEL init/dispose lifecycle completeness can be guaranteed if the above is called properly. ~Sven signature.asc (894 bytes) Download Attachment |
Could you please give me the Line of Code I need i dont get it im sorry.
|
Free forum by Nabble | Edit this page |