Can’t set VSync or FrameRate with LWJLG loader - Resolved!

I am having difficulties with controlling a frame rate. I found out that TPF in simpleUpdate is not reliable, so I started using the application setVSync settings. Which worked great when the program runs as an application, even slowing the FPS down when it makes sense under heavy load. However, it does not work when the program is loaded by LWJGL as an applet. The frame rate stays around 400, while I’d prefer a slower rate of around 60 (or whatever the screen allows). I have also tried to setFrameRate(60) but it does not work either. LWJGL insists on running the web applet at its own preferred rate. Any ideas?



(By the way - I have finally found the solution, see at the bottom of this thread)

It should work fine, how do you initialize it?

In a very “standard” way in the main, with the app settings. Here is the code:



pre type="java"
    // Application set up


    public static void main(String[] args){


        AppSettings settings = new AppSettings(true);


        GalleryMain app = new GalleryMain();


        app.setSettings(settings);


        settings.setTitle(“FPA Light Gallery”);


        settings.setSettingsDialogImage("/Textures/SplashCover.png");


        settings.setResolution(1280, 720);


        settings.setVSync(true);


        //settings.setFrameRate(60);


        app.setShowSettings(true);


        app.start();


    }


    



/pre



Note my other attempts in comments, i.e. setting the frame rate to 60.

Well, you enable the “show settings” window although you set the values before, I guess vsync is disabled in the settings dialog then.

No, it does not seem to make any difference. I had setShowSetting(false), I had it before and after settings.setVSync(true), and I had it commented out. When the program runs in a stand-alone mode, the setVSync applies. When setShowSettings is set, the splash window simply shows the VSync option turned on. However, when you run the same program through the LWJGL loader, the VSync setting is ignored. Perhaps in the applet context, the screen refresh rate is not detectable by JMonkey?

Maybe someone knows this… but does main() even run when running an applet? Does JME do some magic to make that happen?



I haven’t done applet programming in like 15 years almost… so maybe I’m just misremembering something.

@pspeed - you are absolutely right! I am now certain that AppletHarness does not touch the main method. Having checked the source, I can see that in fact it creates and defines its own application settings. So the only way to have some consistency between the application and the applet (via LWJGL loader) is to move (or replicate) all settings from the main method to the simpleInitApp as follows:



pre type="java"
// Get application or applet settings and define them


AppSettings settings = this.getContext().getSettings();


settings.setTitle(“FPA Light Gallery”);


settings.setSettingsDialogImage("/Textures/SplashCover.png");


settings.setResolution(1280, 720);


settings.setVSync(true);



/pre



I think jMonkeyPlatform attempts to hide a bit too much. The way it is done with the AndroidHarness is much nicer. There you actually need to define your own subclass of AndroidHarness and it is passed for further processing. It could be done that way with the current AppletHarness setup but the HTML would have to be modified by hand! May be the JMonkey Platform options for Applet creation could be fiddled with in the future?

You can modify anything in the build process as its based on a normal ant build environment. I agree that we have to add more flexibility for the applet via code and the UI tho.