Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (527)
Games in Android Showcase (127)
games submitted by our members
Games in WIP (593)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  How do I force redraw of GLCanvas from another thread?  (Read 2482 times)
0 Members and 1 Guest are viewing this topic.
Offline tikomir

Junior Newbie





« Posted 2011-04-11 08:30:24 »

I'm developing a scientific application using jogl 2.0. I don't need permanent/animator looping in OGL. GLCanvas has to be redrawn/repainted only on user demand, i.e. the user clicks on the JButton (e.g. Refresh) in main application and GLCanvas gets repainted.

I have read that jogl 2.0 event thread is synchronized with AWT event queue thread, so if I understood it well, I could call e.g.
1  
glCanvas.display();
from main application loop (outside of any GLEventLIsteners) without any problems. I did it that way. Compiled without errors, but nothing happens. It seems that call to dispaly() is ignored.

What is the problem? How can I resolve this?
Offline gouessej
« Reply #1 - Posted 2011-04-11 09:13:34 »

Hi

At first, if you need some help on JOGL, rather post on jogamp.org.

I don't reproduce your problem, I use a modified animator that calls display() only when a flag is set to true (and I disable auto swap mode). Tell me whether you need a more complete example.

Offline tikomir

Junior Newbie





« Reply #2 - Posted 2011-04-11 09:49:45 »

At first, if you need some help on JOGL, rather post on jogamp.org.

I posted here because I have read this in official JOGL Userguide:
Quote
The JOGL forum on javagaming.org is the best place to ask questions about the library. Many users, as well as the Jogl developers, read this forum frequently, and the archived threads contain a lot of useful information (which still needs to be distilled into documentation).

Yes, I would appreciate on more complete example, but first I'll be more concrete with my problem. Maybe you''ll figure out what I did wrong.
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
public class MainFrame extends JFrame implements ActionListener {
  JButton jb_refresh = new JButton("Refresh");
  OpenGLCanvas openGLCanvas;
  ...
  public MainFrame() {
        openGLCanvas = new OpenGLCanvas(this);
        ...
        jb_refresh.addActionListener(this);
        getContentPane().add(jb_refresh, BorderLayout.NORTH);
        getContentPane().add(openGLCanvas.getGlCanvas(), BorderLayout.CENTER);
  }
  ...
  public void actionPerformed(ActionEvent e) {
    // some calcs to set new values in
    ...
    openGLCanvas.getGl_canvas().display();
    openGLCanvas.getGl_canvas().requestFocusInWindow();
  }
  ...
  // main method etc.
}

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
public class OpenGLCanvas implements GLEventListener, KeyListener, MouseListener, MouseMotionListener, MouseWheelListener {
  MainFrame frame;
  GLCanvas glCanvas;

  public OpenGLCanvas(MainFrame frame) {
        this.frame = frame;
        initContent();
    }

    private void initContent() {
        GLProfile glprofile = GLProfile.getDefault();
        GLCapabilities glcapabilities = new GLCapabilities(glprofile);
        glCanvas = new GLCanvas(glcapabilities);
        glCanvas.addGLEventListener(this);
        glCanvas.addKeyListener(this);
        glCanvas.addMouseListener(this);
        glCanvas.addMouseMotionListener(this);
        glCanvas.addMouseWheelListener(this);
    }

    public GLCanvas getGlCanvas() {
        return glCanvas;
    }

   public void init(GLAutoDrawable glAutoDrawable) {
      ...
   }

   public void display(GLAutoDrawable glAutoDrawable) {
      ...
   }

   public void dispose(GLAutoDrawable glAutoDrawable) {
      ...
   }

   public void reshape(GLAutoDrawable glAutoDrawable, int x, int y, int width, int height) {
      ...
   }

   ...

}
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline gouessej
« Reply #3 - Posted 2011-04-11 11:52:32 »

Which build of JOGL do you use? Actually the canvas will be refreshed if you do not disable auto swap buffer mode. You can find some source code in this bug report:
https://jogamp.org/bugzilla/show_bug.cgi?id=455

You can override the class Animator to add a flag to tell whether a redraw is really needed. Then, when you press a button, you could set this flag to true. When the animator is called, it checks the flag, it redraws everything it is set to true and then it sets it back to false. It was working fine in JOGL 1.1.1a but a nasty bug increases the memory consumption in JOGL 2 when calling setAutoSwapBufferMode(true) on a GLCanvas.

Offline tikomir

Junior Newbie





« Reply #4 - Posted 2011-04-11 13:03:53 »

I'm using jogl-2.0-b23-20110303 build.

I added and started animator just to check if it's gonna be of any use, and no, nothing new happend. Sad I'm newbie to jogl, so here is updated code so you can check if I had done everything OK.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
public class OpenGLCanvas implements GLEventListener, KeyListener, MouseListener, MouseMotionListener, MouseWheelListener {
  MainFrame frame;
  GLCanvas glCanvas;
  Animator animator;
 
  public OpenGLCanvas(MainFrame frame) {
        this.frame = frame;
        initContent();
    }
 
    private void initContent() {
        GLProfile glprofile = GLProfile.getDefault();
        GLCapabilities glcapabilities = new GLCapabilities(glprofile);
        glCanvas = new GLCanvas(glcapabilities);
        glCanvas.addGLEventListener(this);
        glCanvas.addKeyListener(this);
        glCanvas.addMouseListener(this);
        glCanvas.addMouseMotionListener(this);
        glCanvas.addMouseWheelListener(this);
        animator = new Animator(glCanvas);
        animator.start();
    }
 
    public GLCanvas getGlCanvas() {
        return glCanvas;
    }
 
   public void init(GLAutoDrawable glAutoDrawable) {
      ...
   }
 
   public void display(GLAutoDrawable glAutoDrawable) {
      ...
   }
 
   public void dispose(GLAutoDrawable glAutoDrawable) {
      ...
      animator.stop();
   }
 
   public void reshape(GLAutoDrawable glAutoDrawable, int x, int y, int width, int height) {
      ...
   }
 
   ...
 
}
Offline lhkbob

JGO Knight


Medals: 32



« Reply #5 - Posted 2011-04-11 13:44:42 »

I did it that way. Compiled without errors, but nothing happens. It seems that call to dispaly() is ignored.
What do you mean by nothing happens? Does no window show up? Or will the window be blank?  Were ever able to get things to show up, before trying to call display() directly? 

You are correct in assuming that you can call display() to make it redraw everything on the AWT thread automatically.

Offline gouessej
« Reply #6 - Posted 2011-04-11 13:46:36 »

Have you looked at the simple example I posted on Wikipedia?
http://en.wikipedia.org/wiki/Java_OpenGL

P.S: please use a more recent build (the build 367 for example).

Offline tikomir

Junior Newbie





« Reply #7 - Posted 2011-04-11 16:08:31 »

Thank you very much. It works with build 367.
Offline gouessej
« Reply #8 - Posted 2011-04-11 19:48:03 »

Thank you very much. It works with build 367.
You're welcome Smiley Your previous build contains some major bugs that have been fixed.

Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

toopeicgaming1999 (73 views)
2014-11-26 15:22:04

toopeicgaming1999 (63 views)
2014-11-26 15:20:36

toopeicgaming1999 (15 views)
2014-11-26 15:20:08

SHC (29 views)
2014-11-25 12:00:59

SHC (27 views)
2014-11-25 11:53:45

Norakomi (32 views)
2014-11-25 11:26:43

Gibbo3771 (27 views)
2014-11-24 19:59:16

trollwarrior1 (40 views)
2014-11-22 12:13:56

xFryIx (78 views)
2014-11-13 12:34:49

digdugdiggy (57 views)
2014-11-12 21:11:50
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!