Resizing GLJPanel with JOGL causes my model to disappear

I switched to using GLJPanel from GLCanvas to avoid some flickering problems, however this created some unforeseen consequences for this.

From what I got so far, GLJPanel calls GLEventListener.init () with every resize, which either discards the various openGL functions that I included in init () (checking depth, lighting, etc.) if I Iโ€™m lucky, or completely erases my model, if I donโ€™t.

I tried to debug it, but I cannot fix this behavior. This is my init () function:

gl.glShadeModel( GL.GL_SMOOTH ); gl.glEnable( GL.GL_DEPTH_TEST ); gl.glDepthFunc( GL.GL_LEQUAL ); gl.glDepthRange( zNear, zFar ); gl.glDisable( GL.GL_LINE_SMOOTH ); gl.glEnable(GL.GL_NORMALIZE); gl.glEnable( GL.GL_BLEND ); gl.glBlendFunc( GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA ); // set up the background color gl.glClearColor( ((float)backColor.getRed () / 255.0f), ((float)backColor.getGreen() / 255.0f), ((float)backColor.getBlue () / 255.0f), 1.0f); gl.glEnable ( GL.GL_LIGHTING ); gl.glLightfv( GL.GL_LIGHT0, GL.GL_AMBIENT, Constants.AMBIENT_LIGHT, 0 ); gl.glLightfv( GL.GL_LIGHT0, GL.GL_DIFFUSE, Constants.DIFFUSE_LIGHT, 0 ); gl.glEnable ( GL.GL_LIGHT0 ); gl.glTexEnvf( GL.GL_TEXTURE_ENV, GL.GL_TEXTURE_ENV_MODE, GL.GL_MODULATE ); gl.glHint( GL.GL_PERSPECTIVE_CORRECTION_HINT, GL.GL_NICEST ); // code to generate model 

Is there any way around this, other than removing everything from init () by adding it to my display () function? Given the behavior of init () and reshape () for GLJPanel, I'm not sure if this will fix this.

+4
source share
2 answers

GLJPanel and CLCanvas are essentially identical in function with respect to JOGL. The only difference is that GLJPanel is JComponent and lightweight, while GLCanvas is Component and Heavyweight. It is likely that any problems you see are not related to these differences (although JOGL is not the most stable part of Java, and there may be an โ€œundocumentedโ€ difference).

The disappearing model is probably due either to the fact that it does not actually call the drawing code, or it incorrectly sets something in the GL initialization (very easy to do). I would recommend passing all the display () functions. If this fixes, it moves things back one at a time (this is just a performance issue).

Having said that, I don't see how you set the viewport size to init (). This is one of the things you need to do every time you resize a window.

+3
source

From the glqpanel doc :

Note that since this component attempts to use pbuffers for rendering, and since pbuffers cannot be resized, somewhat unexpected behavior may occur during resize operations; The GLEventListener.init method (net.java.games.jogl.GLDrawable) can be called several times as the pbuffer resizes to be able to cover the size of the GLJPanel. This is correct because textures and display lists for the GLJPanel will be lost during the resize operation . An application should try to make its GLEventListener.init () methods as free of side effects as possible.

Yes, He sucks . Because you need to store vertex data and stuff in a small JVM memory. Actually, I am looking for why they are not using the same context.

+3
source

Source: https://habr.com/ru/post/1303295/


All Articles