Author Topic: Applet how?  (Read 3574 times)

Offline ErDetEnAnd?

  • int
  • **
  • Posts: 87
    • View Profile
Applet how?
« on: February 25, 2010, 04:24:46 pm »
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.

Offline .jayderyu

  • long
  • ***
  • Posts: 116
    • View Profile
Re: Applet how?
« Reply #1 on: February 25, 2010, 06:36:41 pm »
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.

Offline paulscode

  • double
  • *****
  • Posts: 863
    • View Profile
    • PaulsCode.Com
Re: Applet how?
« Reply #2 on: February 25, 2010, 11:05:16 pm »
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).
« Last Edit: February 25, 2010, 11:09:01 pm by paulscode »

Offline raft

  • quad
  • ******
  • Posts: 1993
    • View Profile
    • http://www.aptalkarga.com
Re: Applet how?
« Reply #3 on: February 25, 2010, 11:57:00 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.

Offline paulscode

  • double
  • *****
  • Posts: 863
    • View Profile
    • PaulsCode.Com
Re: Applet how?
« Reply #4 on: February 26, 2010, 12:27:07 am »
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.

Offline raft

  • quad
  • ******
  • Posts: 1993
    • View Profile
    • http://www.aptalkarga.com
Re: Applet how?
« Reply #5 on: February 26, 2010, 12:57:06 am »
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