Java-Gaming.org Java4K winners: [ by our judges | by the community ]         
Featured games (67)
games approved by the League of Dukes
Games in Showcase (∞)
games submitted by our members



News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  Print  
  2 glCanvas in a JFrame  (Read 799 times)
0 Members and 2 Guests are viewing this topic.
Offline Bobza

JGO n00b
*

Posts: 16



« on: 2011-01-26 10:46:02 »

Hi all,

I built a JFrame containing 2 glCanvases.
I linked each canvas with a different renderer, implementing the GLEventListener interface. Each renderer has its own Animator.

It doesn't work : rendering is weird. It looks like parts of rendering are past to the other glCanvas.

Any ideas ? is this GLContext or multi-threading issue ?

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  
48  
49  
50  
51  
52  
53  
/* Generated with neatbeans */
public class SelectorDialog extends javax.swing.JDialog {
....

    private GLCanvas canvas1;
    private GLCanvas canvas2;

    public GLCanvas getCanvas1() {
        return canvas1;
    }

    public GLCanvas getCanvas2() {
        return canvas2;
    }

}

public View1 implements GLEventListener {
...
}

public View2 implements GLEventListener {
...
}

public class MySelector extends Selector {

public MySelector() {

   GLCanvas canvas1 = getCanvas1();
   canvas1.setAutoSwapBufferMode(true);

   View1 view1 = new View1();
   canvas1.addGLEventListener(view1);
     
        FPSAnimator animator = new FPSAnimator( canvas1 , 60 );
        animator.setRunAsFastAsPossible(false);
        animator.start();
       
        GLCanvas canvas2 = getCanvas2();
        canvas2.setAutoSwapBufferMode(true);

   View2 view2 = new View2();
   canvas2.addGLEventListener(view2);
     
        FPSAnimator animator2 = new FPSAnimator( canvas2, 60 );
        animator2.setRunAsFastAsPossible(false);
        animator2.start();
       
        setVisible(true);
}

}


Offline gouessej

JGO Kernel
*****

Posts: 3557
Medals: 30


TUER


« Reply #1 on: 2011-01-26 13:43:53 »

Which version of JOGL do you use? Have you tried to do the same thing with NEWT?

Julien Gouesse
Offline lhkbob

JGO Neuromancer
****

Posts: 1174
Medals: 35



« Reply #2 on: 2011-01-26 21:20:07 »

If you're using GLEventListeners it shouldn't be a multi-threading issue, the two canvases would just take turns.  It's likely that the two GLCanvases are being laid out incorrectly (and then overlapping heavy-weight components == bad) or the implementation of GLCanvas assumes that it can take over the entire window when it's rendering (but I don't know).

Can you post the actual code that adds the canvases to your JDialog? I'll give it a shot on my computer.

Games published by our own members! Go get 'em!
Offline bobjob

JGO Ninja
***

Posts: 646
Medals: 14


David Aaron Muhar


« Reply #3 on: 2011-01-26 23:24:04 »

do you need to use 2 canvas's? Why not just use multiple view ports?

My Projects
Games, Webcam chat, Video screencast, PDF tools.

Javagaming.org with chat room
Offline Bobza

JGO n00b
*

Posts: 16



« Reply #4 on: 2011-01-27 06:35:49 »

Thanks all for your replies (and sorry for my approximate english writing)

It looks ok now ; my renderers were wrong and not dealing properly shared datas ; no troubles with multi-threading or so ! The code in my first post is ok. I'm sorry for making you waste your time.

I saw a previous thread on the same kind of trouble ; it was said in it to use a single animator for many canvases, and to deactivate autoSwapBuffering.
By the way, my GUI works with autoSwapBuffering enabled and with 2 animators, but that was an interesting way to explore.
However, I dont really understand the behaviour of all this. Where could I find some ressources on the subject ? How buffer swaping works or should work in a multi canvases context ?


do you need to use 2 canvas's? Why not just use multiple view ports?
I worked and thought on such a solution. However technics are much more complicated (i'm quite a beginner using opengl and dont want to go to far in it for now). And in my case, the idea was to create a GUI that mixes 3d rendering and other swing components (buttons, trees ... ) so that i dont have to re-create a 3d JTree-like component. I searched for a kind of jogl GUI "library", but couldn't find one.

Another question I cant find no response is about the "theory and technics" on the popup windows and dialogs in games.
Let's take Minecraft for example ; when you open the main menu, or the "material" menu : how does it work ? I guess he doesnt use a JFrame or JDialog ... Does he render the menu or dialog in a texture and rendering this texture over the main scene ? But with non modal dialogs how should this work ?

Thanks in advance
Offline gouessej

JGO Kernel
*****

Posts: 3557
Medals: 30


TUER


« Reply #5 on: 2011-01-27 13:00:41 »

Don't disable auto swap buffer mode if you use JOGL 2.0 beta as it hugely increases the memory consumption.

Julien Gouesse
Pages: [1]
  Print  
 
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.16 | SMF © 2011, Simple Machines Valid XHTML 1.0! Valid CSS!
Page created in 0.079 seconds with 20 queries.