As a beginner , I'm trying to understand why we have to use EventListener instead of writing codes outside of it
I wrote some codes in attempt to render a triangle without using EvenListener, as I understanding that EventListener provides functions for Drawable to call, but the core rendering process is independent from it , having things only to do with the Drawable . After I clicked run button , my screen turned white and the program lost response . I had to terminate it to end this eternal loop . May I ask is there problem with my codes ? Why I shouldn't write them in this way ? What's the reason for my program to be dead ? Thanks for all your replies . Additional information : 0 error 1 warning (GL_TRIANGLES should be accessed in a static way) JFrame frame = new JFrame("title"); frame.setSize(new Dimension(1200,1200)); frame.getContentPane().add(canvas); frame.setVisible(true); GLContext temp = canvas.createContext(null); temp.setGLDrawable(canvas.getDelegatedDrawable(), false); GLContext ctx = canvas.getContext(); canvas.setRealized(true); System.out.print(canvas.isRealized()); //true ctx.makeCurrent(); MyOpenGL myglobj = new MyOpenGL(); OpenGL.part1 test = myglobj.new part1(ctx.getGL().getGL3()); test.test();//It's just a bunch of glGenBuffers glBindBuffer glEnableVertexAttribArray to set up my rendering environment canvas.getGL().getGL3().glDrawArrays(canvas.getGL().GL_TRIANGLES, 0, 12); |
Administrator
|
Put a simple test code somewhere, link it here and then I may look at it.
We should also have a few non GLEventListener examples in our unit tests. I.e. the NativeSurface you use shall be valid and the GLDrawable (your canvas?) locked to be valid. |
Administrator
|
In reply to this post by HamudHaa
Hello
GL_TRIANGLES is static, you don't need an instance to use it. Using a GLEventListener and an animator is simpler and less error prone. If you think that it would be easier to get rid of them, you'll be completely wrong, it's supported, it's doable, JogAmp's Ardor3D Continuation based on JOGL uses GLEventListener but no animator. However, I advise you to use our abstractions especially as you're a beginner, getting rid of them is allowed in order not to patronize our user base and to be flexible to support particular cases. Maybe this example can help: https://jogamp.org/cgit/jogl-demos.git/tree/src/demos/es2/RawGL2ES2demo.java?id=HEAD
Julien Gouesse | Personal blog | Website
|
Administrator
|
Utilizing GLEventListener surely would be easy - if possible.
It is the recommended no-pain path forward :) Problem might not be the GLEventListener model itself, but implementing your own GLAutoDrawable type which works with your other framework? An GLAutoDrawable is NEWT's GLWindow for example. For this you could have a look at GLAutoDrawableDelegate, allowing an ad-hoc implementation as shown in JOGL's unit tests: - https://jogamp.org/cgit/jogl.git/tree/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestGLAutoDrawableDelegateNEWT.java - https://jogamp.org/cgit/jogl.git/tree/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestGLAutoDrawableDelegateOnOffscrnCapsNEWT.java +++ If the self-coded GLAutoDrawable is also not possible, just look at the GLAutoDrawableDelegate code and GLDrawable + NativeSurface + GLContext to dive into all the well documented details. In case this work is company related, you may also contact me or others for more support. https://jogamp.org/wiki/index.php?title=Maintainer_and_Contacts#Commercial_Support |
In reply to this post by Sven Gothel
Here is the link .
https://codeshare.io/nz6xXM It consists of two parts . The main part which is struggling with Event Listener(I didn't use it in this case though) and Canvas , the another part which is a bunch of core profile binding . |
In reply to this post by gouessej
It's simpler for real . In my case , I want my frame rate updated on higher frequency when I'm inputting keyboard actions . So I guess I have to go outside animator and put draw functions in a self-designed thread . I wonder from GLAutoDrawable.invoke() , makeCurrent() , Canvas.display() which is the best option should I use to draw something outside animator ?
|
Administrator
|
It isn't, what you describe is probably doable with a plain Animator or FPSAnimator. However, yes, you're on the right path with GLAutoDrawable.display() and GLAutoDrawable.invoke(), you can use them when you really want to avoid using an animator, this is what I do in JogAmp's Ardor3D Continuation. Your use case looks like something related to scientific visualization, I had to implement something very similar to mimic OpenInventor many years ago. Why would you need a self-designed thread? The events would come from AWT and the drawing could be done on the AWT EDT too.
Julien Gouesse | Personal blog | Website
|
Description error. Yes I will use KeyListener . How can I do it with FPSAnimator ? I've seen a post on stackoverflow that he stops the animator first and then changes the framerate , and starts the animator again . In my case I want to call the display function every tick my finger hasn't been released from the button . And when I do nothing to keyboard , it should render the scene with a low framerate like around 1~2, or completely ceased . I would think FPSAnimator not a good choice to do it .
|
Administrator
|
What you describe should work, you can call setFPS() to modify the frame rate but don't forget to pause it before using this method.
Julien Gouesse | Personal blog | Website
|
Free forum by Nabble | Edit this page |