summaryrefslogtreecommitdiffstats
path: root/src/jogl/classes/jogamp/opengl/awt/VersionApplet.java
blob: 2f87f01a92a9cfba44c4129e585423d22264998d (plain)
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
179
180
181
182
183
package jogamp.opengl.awt;

import java.applet.Applet;
import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.Frame;
import java.awt.GridLayout;
import java.awt.TextArea;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import java.util.List;

import javax.media.opengl.GLProfile;
import javax.media.opengl.awt.GLCanvas;
import javax.media.opengl.GL;
import javax.media.opengl.GLAutoDrawable;
import javax.media.opengl.GLCapabilities;
import javax.media.opengl.GLCapabilitiesImmutable;
import javax.media.opengl.GLDrawableFactory;
import javax.media.opengl.GLEventListener;

import com.jogamp.common.GlueGenVersion;
import com.jogamp.common.os.Platform;
import com.jogamp.common.util.VersionUtil;
import com.jogamp.opengl.JoglVersion;

@SuppressWarnings("serial")
public class VersionApplet extends Applet {
  TextArea tareaVersion;
  TextArea tareaCaps;
  GLCanvas canvas;

  public static void main(final String[] args) {
    final Frame frame = new Frame("JOGL Version Applet");
    frame.setSize(800, 600);
    frame.setLayout(new BorderLayout());

    final VersionApplet va = new VersionApplet();
    frame.addWindowListener(new ClosingWindowAdapter(frame, va));

    va.init();
    frame.add(va, BorderLayout.CENTER);
    frame.validate();

    frame.setVisible(true);
    va.start();
  }

  static class ClosingWindowAdapter extends WindowAdapter {
    Frame f;
    VersionApplet va;
    public ClosingWindowAdapter(final Frame f, final VersionApplet va) {
        this.f = f;
        this.va = va;
    }
    @Override
    public void windowClosing(final WindowEvent ev) {
        f.setVisible(false);
        va.stop();
        va.destroy();
        f.remove(va);
        f.dispose();
        System.exit(0);
    }
  }

  private synchronized void my_init() {
    if(null != canvas) { return; }

    setEnabled(true);

    final GLProfile glp = GLProfile.getDefault();
    final GLCapabilities glcaps = new GLCapabilities(glp);

    setLayout(new BorderLayout());
    String s;

    tareaVersion = new TextArea(120, 60);
    s = VersionUtil.getPlatformInfo().toString();
    System.err.println(s);
    tareaVersion.append(s);

    s = GlueGenVersion.getInstance().toString();
    System.err.println(s);
    tareaVersion.append(s);

    /*
    s = NativeWindowVersion.getInstance().toString();
    System.err.println(s);
    tareaVersion.append(NativeWindowVersion.getInstance().toString());
    */

    s = JoglVersion.getInstance().toString();
    System.err.println(s);
    tareaVersion.append(s);

    tareaCaps = new TextArea(120, 20);
    final GLDrawableFactory factory = GLDrawableFactory.getFactory(glp);
    final List<GLCapabilitiesImmutable> availCaps = factory.getAvailableCapabilities(null);
    for(int i=0; i<availCaps.size(); i++) {
        s = availCaps.get(i).toString();
        System.err.println(s);
        tareaCaps.append(s);
        tareaCaps.append(Platform.getNewline());
    }

    final Container grid = new Container();
    grid.setLayout(new GridLayout(2, 1));
    grid.add(tareaVersion);
    grid.add(tareaCaps);
    add(grid, BorderLayout.CENTER);

    canvas = new GLCanvas(glcaps);
    canvas.addGLEventListener(new GLInfo());
    canvas.setSize(10, 10);
    add(canvas, BorderLayout.SOUTH);
    validate();
  }

  private synchronized void my_release() {
      if(null!=canvas) {
          remove(canvas);
          canvas.destroy();
          canvas = null;
          remove(tareaVersion.getParent()); // remove the grid
          tareaVersion = null;
          tareaCaps = null;
          setEnabled(false);
      }
  }

  @Override
  public void init() {
    System.err.println("VersionApplet: init() - begin");
    my_init();
    System.err.println("VersionApplet: init() - end");
  }

  @Override
  public void start() {
    System.err.println("VersionApplet: start() - begin");
    canvas.setVisible(true);
    System.err.println("VersionApplet: start() - end");
  }

  @Override
  public void stop() {
    System.err.println("VersionApplet: stop() - begin");
    canvas.setVisible(false);
    System.err.println("VersionApplet: stop() - end");
  }

  @Override
  public void destroy() {
    System.err.println("VersionApplet: destroy() - start");
    my_release();
    System.err.println("VersionApplet: destroy() - end");
  }

  class GLInfo implements GLEventListener {
    @Override
    public void init(final GLAutoDrawable drawable) {
        final GL gl = drawable.getGL();
        final String s = JoglVersion.getGLInfo(gl, null).toString();
        System.err.println(s);
        tareaVersion.append(s);
    }

    @Override
    public void reshape(final GLAutoDrawable drawable, final int x, final int y, final int width, final int height) {
    }

    @Override
    public void display(final GLAutoDrawable drawable) {
    }

    @Override
    public void dispose(final GLAutoDrawable drawable) {
    }
  }

}