Main Menu

Applet how?

Started by ErDetEnAnd?, February 25, 2010, 04:24:46 PM

Previous topic - Next topic

ErDetEnAnd?

Hi.

How is an JPCT applet using LWJGL correct painted without using a render loop?
I cannot construct an applet that renders on mouse event, and dont flicker when paint(g) is called (e.g. when another window is dragged on top of it, and applet area is revealed).

Please help.

.jayderyu

hmm, well you can try adding a JPanel to the JApplet. The new JPanel will be your canvas that you will be drawing on. Then just make sure to update both the JApplet and JPanel each frame.

Raft knows best for getting guis overlapping and making sure the graphics are update accordingly.

paulscode

#2
I remember you mentioning a similar problem last year in this thread.  I'm surprised there hasn't been a good solution yet.  This seems like an applet issue to me, not specifically a jPCT issue.  I've played around with it for a while, but I can't find a solution for the flickering either when moving windows around.

--EDIT--  Just to comment what on .jayderyu posted, the goal here is to not need to update something every frame, but only when something changes (in this case when there is mouse input).

raft

Quote from: .jayderyu on February 25, 2010, 06:36:41 PM
Raft knows best for getting guis overlapping and making sure the graphics are update accordingly.
i never used LWJGL in an applet. but it sounds like it may be a threading issue. with software renderer, paint(..) method should be called in AWT thread in order to use a Swing GUI.

paulscode

Normally, the paint() method is not called directly, but rather a suggestion to paint is made via repaint(), which is thread safe.  I suspect the flickering behavior is related to this.  It's been a while since I tinkered around with this problem, so I can't remember what the issue was with calling paint() directly, but I do recall that there was one.  If I find a little free time, I might play around with this some more.

raft

right, you cant call paint(..) directly. many things go weird and wrong if you do so. you can call repaint() but it's only a suggestion as you said. it's not suitable for game loop. you must call paintImmediately(..) which in turn calls paint in current thread and hence must be called in AWT thread. this is what i do in karga and also is the only realiable way i found..

anyway, these only apply if you would use a swing/awt gui. otherwise doing active rendering -as in jPCT's samples- in any thread is also possible