Applet flickering with LWJGL

Started by ErDetEnAnd?, January 08, 2009, 10:51:42 PM

Previous topic - Next topic

paulscode

I read that thread you mentioned in your first post about overriding the update() method to remove flickering, and I had a thought.  This is just a shot in the dark, but perhaps the problem is coming from the Canvas - it's update() method is not being overridden.  That might explain why you only saw the problem in hardware rendering mode.  If that is what's going on, I don't really see any way around it, since you cannot override that Canvas.

ErDetEnAnd?

Thank you for testing and for looking into this.

You're right about the size of the problem, if you're making a game. But thats not the case here :)

I've almost eliminated the flickering by calling canvas.paint(worldFrame.getGraphics()), and drawing several times when requested by the OS. I (hardly) cant get any flicker now. Ugly, but it works, and as written not done when rendering.

bromokun

#17
Hi ErDetEnAnd?

I'm experiencing the same flickering on my applet when I enable Hardware rendering ... btw .. I'm using the applet samples (HelloWorld) which posted on WIKI by paulscode in http://www.jpct.net/wiki/index.php/Applets.

So mr. ErDetEnAnd .... can you please share your code in order to eliminate this problem.

BTW .. I'm using a pretty stupid graphic card on my laptop which is: Intel Graphics Media Accelerator driver for Mobile ... is this the caused of my problem?

Thank you in advanced

Bromo

bromokun

Okay,

Still using HelloWorld.java like in the wiki

I did set FrameBuffer in my init() method like this:

buffer = new FrameBuffer(getWidth(), getHeight(), FrameBuffer.SAMPLINGMODE_HARDWARE_ONLY);
buffer.usesRenderer(IRenderer.RENDERER_OPENGL);


but then in my paint(Graphic g) method I changed to become like this:

// buffer.displayGLOnly(); --> I commeted this line
buffer.display(myCanvas.getGraphics(), 0, 0); //--> my changed
myCanvas.repaint();


And my flickering has gone ... but my question is: by doing this ... is my Applet using Hardware rendering? or it returned to Software rendering?

Please advice

bromokun

Is it possible to use org.lwjgl.opengl.AWTGLCanvas as Canvas to be render by jpct FrameBuffer? ...

paulscode

#20
Quote from: bromokun on March 17, 2010, 01:47:54 PM// buffer.displayGLOnly(); --> I commeted this line
buffer.display(myCanvas.getGraphics(), 0, 0); //--> my changed
myCanvas.repaint();

And my flickering has gone ... but my question is: by doing this ... is my Applet using Hardware rendering? or it returned to Software rendering?
In hardware mode, calling buffer.display( Graphics, x, y ) supposedly does exactly the same thing as buffer.displayGLOnly() (i.e. the arguments are ignored).  EDIT: See the JavaDoc for reference.

But if using a different display() method magically fixes the flickering, then hell - go for it!  Maybe that call to getGraphics() is doing something unexpectedly behind the scenes which results in the flicker disappearing.  One possible way to test if that is what's happening would be to try something like this to see if it also stops the flickering:
myCanvas.getGraphics();
buffer.displayGLOnly();


As I mentioned in an earlier post, I don't experience this flicker on my computers here (perhaps the cpus/graphics cards are just too fast).  Does this flicker happen all the time, or just while moving the browser window around?

EgonOlsen

However, judging from the code snippets you've posted, i assume that both renderers are active in your setup, which is not what you want (btw: FrameBuffer.useRenderer(...) just returns if the buffer uses this renderer, it doesn't change anything so your call to it is pointless at this stage). Create the FrameBuffer, disable the software renderer and enable the GL-Canvas renderer. Have a look at the HelloWorldAWTGL-example's source for this.

And btw: enableGLCanvasRenderer returns an org.lwjgl.opengl.AWTGLCanvas (or a subclass of it to be more precise).

paulscode

Good catch, I didn't notice that call to method 'usesRenderer' in your code snippet.  For hardware-accelerated rendering, try this instead:

        buffer = new FrameBuffer( width, height, FrameBuffer.SAMPLINGMODE_HARDWARE_ONLY );
        buffer.disableRenderer( IRenderer.RENDERER_SOFTWARE );
        myCanvas = buffer.enableGLCanvasRenderer();
        add( myCanvas, BorderLayout.CENTER);
        myCanvas.setVisible( true );


Then switching between software and hardware rendering modes can be done like this:

For software rendering:
                buffer.disableRenderer( IRenderer.RENDERER_OPENGL );
                buffer.enableRenderer(IRenderer.RENDERER_SOFTWARE );
                this.remove( myCanvas );
                this.validate();


For hardware-accelerated rendering:
                buffer.disableRenderer( IRenderer.RENDERER_SOFTWARE );
                myCanvas = buffer.enableGLCanvasRenderer();
                this.add( myCanvas, BorderLayout.CENTER);
                this.validate();
                myCanvas.setVisible( true );
                myCanvas.validate();


bromokun

HELLLLPPPPPP ....

I accidently delete my HelloWorld project .... so I try to recreate the applet I did ...
but now it doesn't work ... I believe its not my code (wishing) ...
But the error message is:

An error occured while loading the applet
Please contact support to resolve this issue
Fatal error occured(7): HelloWorld


What happened? ...

paulscode

Fatal Error (7) means your applet crashed during initialization (i.e. before it started to run).  This usually means a typo in your appletloader html file (misspelled class names, filenames, or paths are most common reasons).  Some other common reasons are forgetting to compile the classes into a .jar or forgetting to include it in the al_jars parameter of the applet-loader.  Sometimes there is more useful information in the Java Console, could you please copy that and post it?  Also, post a copy of your html source (use [code] [\code] tags around it to make it readable -- not that you wouldn't, but just a reminder).