Author Topic: Applet flickering with LWJGL  (Read 7763 times)

Offline paulscode

  • double
  • *****
  • Posts: 863
    • View Profile
    • PaulsCode.Com
Re: Applet flickering with LWJGL
« Reply #15 on: January 13, 2009, 07:45:48 am »
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.

Offline ErDetEnAnd?

  • int
  • **
  • Posts: 87
    • View Profile
Re: Applet flickering with LWJGL
« Reply #16 on: January 13, 2009, 08:15:57 pm »
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.

Offline bromokun

  • byte
  • *
  • Posts: 10
    • View Profile
Re: Applet flickering with LWJGL
« Reply #17 on: March 17, 2010, 12:52:45 pm »
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
« Last Edit: March 17, 2010, 01:36:03 pm by bromokun »

Offline bromokun

  • byte
  • *
  • Posts: 10
    • View Profile
Re: Applet flickering with LWJGL
« Reply #18 on: March 17, 2010, 01:47:54 pm »
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

Offline bromokun

  • byte
  • *
  • Posts: 10
    • View Profile
Re: Applet flickering with LWJGL
« Reply #19 on: March 17, 2010, 04:50:32 pm »
Is it possible to use org.lwjgl.opengl.AWTGLCanvas as Canvas to be render by jpct FrameBuffer? ...

Offline paulscode

  • double
  • *****
  • Posts: 863
    • View Profile
    • PaulsCode.Com
Re: Applet flickering with LWJGL
« Reply #20 on: March 17, 2010, 09:00:46 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:
Code: [Select]
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?
« Last Edit: March 17, 2010, 09:13:33 pm by paulscode »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11776
    • View Profile
    • http://www.jpct.net
Re: Applet flickering with LWJGL
« Reply #21 on: March 17, 2010, 09:30:31 pm »
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).

Offline paulscode

  • double
  • *****
  • Posts: 863
    • View Profile
    • PaulsCode.Com
Re: Applet flickering with LWJGL
« Reply #22 on: March 18, 2010, 12:44:15 am »
Good catch, I didn't notice that call to method 'usesRenderer' in your code snippet.  For hardware-accelerated rendering, try this instead:

Code: [Select]
        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:
Code: [Select]
                buffer.disableRenderer( IRenderer.RENDERER_OPENGL );
                buffer.enableRenderer(IRenderer.RENDERER_SOFTWARE );
                this.remove( myCanvas );
                this.validate();

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

Offline bromokun

  • byte
  • *
  • Posts: 10
    • View Profile
Re: Applet flickering with LWJGL
« Reply #23 on: March 23, 2010, 11:22:26 am »
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? ...

Offline paulscode

  • double
  • *****
  • Posts: 863
    • View Profile
    • PaulsCode.Com
Re: Applet flickering with LWJGL
« Reply #24 on: March 23, 2010, 07:04:09 pm »
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).