Applet works on Safari and IE, but not Firefox

Started by BatKid, November 06, 2009, 21:29:44

Previous topic - Next topic

BatKid

Hi guys!

Excellent work on the new version of LWJGL, and I am now experimenting with the AppletLoader. 

The problem that I'm having is that the applet seems to work fine on Safari and IE.  However, on Firefox (under Mac in particular), I cannot seem to get keyboard control.  This is very odd as it only affects Firefox, is this more of a browser thing?

You can test the applet at http://cyrix.capilanou.ca/~jmadar/monster_demo/appletloader.html.

Thanks
Projects: 
   Env3D (http://env3d.org): Learn Java in 3D
   WhaleChat (http://whalechat.com): A 3D social programming experiment

kappa

applet works fine (with keyboard controls) on firefox linux. What type of canvas are you using? (AWTGLCanvas or Native Display Canvas)

BatKid

Native canvas.

On my linux machine, the applet loads fine but the camera is off.  Do you have problem with your camera angle?  (i.e. does it centered on the monster?)

Thanks a million.

Jason
Projects: 
   Env3D (http://env3d.org): Learn Java in 3D
   WhaleChat (http://whalechat.com): A 3D social programming experiment

kappa

yes i do have a camera problem, its probably something to do with the way your setting it up.

BatKid

Ok, now I have more problems to fix  :-\

I don't have a windows machine at the moment, I wanted to see if the keyboard and camera problem exist on windows as well. 

This is driving me nuts... I really don't want to tell people to not use firefox   :P
Projects: 
   Env3D (http://env3d.org): Learn Java in 3D
   WhaleChat (http://whalechat.com): A 3D social programming experiment

kappa

hmm, it should work, are you basing you applet loop on the basic example lwjgl applet http://java-game-lib.svn.sourceforge.net/viewvc/java-game-lib/trunk/LWJGL/src/java/org/lwjgl/test/applet/GearsApplet.java?view=markup ?

do you have keyboard problems with all lwjgl applets or only your applet?

try some other lwjgl applets example1 or example2

BatKid

Well, my code is essentially an exact copy of the lwjgl example code.  The only difference is that I incorporated my own rendering library.  You'll notice that the default play method doesn't do much except displays 1 object. 

The intent of this class is for others to inherit from it and override the play method, to add their own objects and logic into the environment. 

I realized that there is a similar issue a few months ago regrading the applet not getting focus.  However, I believe this is a different problem.  When I look at minecraft.net website, I simply cannot get keyboard working at all on either Safari or Firefox.  My current problem only happens on Firefox.

Anyway, for whatever it's worth, here is my code.

public class EnvApplet extends Applet {

    Canvas display_parent;
    Thread gameThread;
    private boolean running;
    protected Game game;
    private EnvCamera camera;
    private EnvInputManager input;
    protected Env env;

    public void destroy() {
        remove(display_parent);
        super.destroy();
        System.out.println("Clear up");
    }

    private void destroyLWJGL() {
        stopApplet();
        try {
            gameThread.join();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    /**
     * @see java.applet.Applet#start()
     */
    @Override
    public void start() {
        
        gameThread = new Thread() {

            public void run() {

                setRunning(true);
                try {

                    
                    Display.setParent(display_parent);

                    env = new Env();


                } catch (LWJGLException e) {
                    e.printStackTrace();
                }
                play();
            }
        };
        gameThread.start();
    }

    public void stop() {
    }

    public void stopApplet() {
        setRunning(false);
    }

    public void init() {
        setLayout(new BorderLayout());
        try {
            display_parent = new Canvas() {

                public final void removeNotify() {
                    destroyLWJGL();
                    super.removeNotify();
                }
            };
            display_parent.setSize(getWidth(), getHeight());
            add(display_parent);
            display_parent.setFocusable(true);
            display_parent.requestFocus();
            display_parent.setIgnoreRepaint(true);
            //setResizable(true);
            setVisible(true);
        } catch (Exception e) {
            System.err.println(e);
            throw new RuntimeException("Unable to create display");
        }
    }

    /**
     * Contains the game loop.
     **/
    public void play() {
        env.setDefaultControl(false);
        env.addObject(new test.Doll());

        while (isRunning()) {
            env.advanceOneFrame();
        }
    }

    /**
     * @return the running
     */
    public boolean isRunning() {
        return running;
    }

    /**
     * @param running the running to set
     */
    public void setRunning(boolean running) {
        this.running = running;
    }
}
Projects: 
   Env3D (http://env3d.org): Learn Java in 3D
   WhaleChat (http://whalechat.com): A 3D social programming experiment

broumbroum

Try adding (Component).requestFocusInWindow() within ignition.

BatKid

Ok, an update for those who are interested in things on the mac side:

After hours of experimentation, I realized that if the java console is set to "show" under "Java Preferences", then the keyboard would work.  If the java console is set to either hide or "do not show", then the keyboard would never be detected by the applet.  This only happens in Firefox.  Should we chalk it up as a Firefox bug under OS X? 

BTW, I also managed to fix the linux camera bug.  It turns out to be the resolution being wrongly set under linux. 

Thanks for all the help guys!  I really appreciate it. 

Jason
Projects: 
   Env3D (http://env3d.org): Learn Java in 3D
   WhaleChat (http://whalechat.com): A 3D social programming experiment