Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (107)
games submitted by our members
Games in WIP (535)
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  
  Problem with Split Pane, JOGL, GLCanvas  (Read 1278 times)
0 Members and 1 Guest are viewing this topic.
Offline djlawler

Senior Newbie





« Posted 2009-06-09 20:37:00 »

When I create a simple app with a split pane that contains a tree on the left and a glcanvas on the right everything seems to work ok.  Then, when I go to move the split, as soon as I click on the splitter to move it, the init method gets called on the gllistener.  This seems to imply that the GLContext has changed or gone away??  In order to compensate for this I will have to reload all my textures and display lists everytime someone changes the split.  This is not very good.  Is there a way to avoid this behavior?

I'm doing this in Jython....so to 'prove' that it happens with a normal java project I made the below program starting with the default JOGL GLCanvas project in Netbeans.  The same behavior happens.  Is there a way to initialize and 'hold' a GLContext so that I can make this work?  (I have not included the code for the generated GLRenderer.java because I did not change anything in it).

Thanks

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  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
76  
77  
78  
79  
80  
81  
82  
83  
84  
85  
86  
87  
88  
89  
90  
91  
92  
93  
94  
95  
96  
97  
98  
99  
100  
101  
102  
103  
104  
105  
106  
107  
108  
109  
110  
111  
112  
113  
114  
115  
116  
117  
118  
119  
120  
121  
122  
123  
124  
125  
126  
127  
128  
129  
130  
131  
132  
133  
134  
135  
136  
137  
138  
139  
140  
141  
142  
143  
144  
145  
146  
147  
148  
149  
150  
151  
152  
153  
154  
155  
156  
157  
158  
159  
160  
161  
162  
163  
164  
165  
166  
167  
168  
169  
170  
171  
172  
173  
174  
175  
176  
177  
178  
/*
 * SimpleGLCanvas.java
 *
 * Created on 30. Juli 2008, 16:18
 */


package org.yourorghere;

import com.sun.opengl.util.Animator;
import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.media.opengl.GLCanvas;
import javax.media.opengl.GLCapabilities;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPopupMenu;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.JTree;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.UIManager;
import javax.swing.WindowConstants;

/**
 *
 * @author cylab
 * @author mbien
 */

public class SimpleGLCanvas extends JFrame {

    static {
        // When using a GLCanvas, we have to set the Popup-Menues to be HeavyWeight,
       // so they display properly on top of the GLCanvas
       JPopupMenu.setDefaultLightWeightPopupEnabled(false);
    }

    //private Animator animator;

    /** Creates new form MainFrame */
    public SimpleGLCanvas() {
        initComponents();
        setTitle("Simple JOGL Application");

        canvas.addGLEventListener(new GLRenderer());
        //animator = new Animator(canvas);

        // This is a workaround for the GLCanvas not adjusting its size, when the frame is resized.
       canvas.setMinimumSize(new Dimension());

        this.addWindowListener(new WindowAdapter() {

            @Override
            public void windowClosing(WindowEvent e) {
                // Run this on another thread than the AWT event queue to
               // make sure the call to Animator.stop() completes before
               // exiting
               new Thread(new Runnable() {

                    public void run() {
                        //animator.stop();
                       System.exit(0);
                    }
                }).start();
            }
        });
    }

    @Override
    public void setVisible(boolean show){
        //if(!show)
           //animator.stop();
       super.setVisible(show);
        //if(!show)
           //animator.start();
   }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">
   private void initComponents() {
        JLabel label = new JLabel();
        jSplitPane1 = new JSplitPane();
        canvas = new GLCanvas(createGLCapabilites());
        jScrollPane1 = new JScrollPane();
        jTree1 = new JTree();

        setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);

        label.setText("Below you see a GLCanvas");

        jSplitPane1.setRightComponent(canvas);

        jScrollPane1.setViewportView(jTree1);

        jSplitPane1.setLeftComponent(jScrollPane1);

        GroupLayout layout = new GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(Alignment.LEADING)
                    .addComponent(label)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(10, 10, 10)
                        .addComponent(jSplitPane1, GroupLayout.DEFAULT_SIZE, 627, Short.MAX_VALUE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(label)
                .addPreferredGap(ComponentPlacement.RELATED)
                .addComponent(jSplitPane1, GroupLayout.DEFAULT_SIZE, 447, Short.MAX_VALUE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>

    /**
     * Called from within initComponents().
     * hint: to customize the generated code choose 'Customize Code' in the contextmenu
     * of the selected UI Component you wish to cutomize in design mode.
     * @return Returns customized GLCapabilities.
     */

    private GLCapabilities createGLCapabilites() {

        GLCapabilities capabilities = new GLCapabilities();
        capabilities.setHardwareAccelerated(true);

        // try to enable 2x anti aliasing - should be supported on most hardware
       capabilities.setNumSamples(2);
        capabilities.setSampleBuffers(true);

        return capabilities;
    }

    /**
    * @param args the command line arguments
    */

    public static void main(String args[]) {
        // Run this in the AWT event thread to prevent deadlocks and race conditions
       System.setProperty("sun.awt.noerasebackground", "true");
        EventQueue.invokeLater(new Runnable() {
            public void run() {

                // switch to system l&f for native font rendering etc.
               try{
                    UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
                }catch(Exception ex) {
                    Logger.getLogger(getClass().getName()).log(Level.INFO, "can not enable system look and feel", ex);
                }
                SimpleGLCanvas frame = new SimpleGLCanvas();
                frame.setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify
   private GLCanvas canvas;
    private JScrollPane jScrollPane1;
    private JSplitPane jSplitPane1;
    private JTree jTree1;
    // End of variables declaration

}


David
Offline djlawler

Senior Newbie





« Reply #1 - Posted 2009-06-09 20:42:20 »

DOH!  Changed my search and found an answer in another section......please disregard or delete!

Sorry,

Daivd
Offline djlawler

Senior Newbie





« Reply #2 - Posted 2009-06-10 01:12:04 »

For anyone else who comes across this.....the clue was in this discussion: http://www.java-gaming.org/topics/resizing-a-jsplitpane-causes-gleventlistener-s-quot-init-quot-to-be-called/19147/view.html

I was able to add the GLCanvas to a JScrollPane, change the horizontal and vertical ScrollBarPolicies to Never.  Then I had to change the Listener for the JScrollPane to resize the GLCanvas whenever the JScrollPane is resized.

After that I got the exact behivior that I was hoping for, with init() only called at the appropriate time, but with a fully functional GLCanvas.

Regards,

David
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.

Riven (7 views)
2014-07-29 18:09:19

Riven (5 views)
2014-07-29 18:08:52

Dwinin (8 views)
2014-07-29 10:59:34

E.R. Fleming (25 views)
2014-07-29 03:07:13

E.R. Fleming (10 views)
2014-07-29 03:06:25

pw (39 views)
2014-07-24 01:59:36

Riven (39 views)
2014-07-23 21:16:32

Riven (26 views)
2014-07-23 21:07:15

Riven (28 views)
2014-07-23 20:56:16

ctomni231 (59 views)
2014-07-18 06:55:21
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
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!