aboutsummaryrefslogtreecommitdiffstats
path: root/src/newt/classes/com/jogamp/newt/util/applet/VersionApplet3.java
blob: 90c8c3572ae7d4aa724582a2df1a1bd91356c800 (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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
package com.jogamp.newt.util.applet;

import com.jogamp.plugin.applet.Applet3;
import com.jogamp.plugin.applet.Applet3Context;
import com.jogamp.plugin.ui.NativeWindowDownstream;
import com.jogamp.plugin.ui.NativeWindowUpstream;

import java.util.List;
import java.util.Locale;

import javax.media.opengl.GLProfile;
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.util.VersionUtil;
import com.jogamp.newt.NewtFactory;
import com.jogamp.newt.Window;
import com.jogamp.newt.opengl.GLWindow;
import com.jogamp.opengl.JoglVersion;

public class VersionApplet3 implements Applet3 {

    public static void main(String[] args) {
        VersionApplet3 va = new VersionApplet3();

        final NativeWindowDownstream nwc = va.createNativeWindow(null, new NativeWindowUpstream() {
            @Override
            public long getWindowHandle() {
                return 0;
            }
            @Override
            public int getWidth() {
                return 64;
            }
            @Override
            public int getHeight() {
                return 64;
            }
            @Override
            public String getDisplayConnection() {
                return null; // default
            }
            @Override
            public int getScreenIndex() {
                return 0; // default
            }
            @Override
            public void notifySurfaceUpdated(NativeWindowDownstream swappedWin) {
                // NOP
            }

        });
        va.init(null);
        va.start();
        va.stop();
        va.destroy();
        nwc.destroy();
    }

    GLWindow canvas;

    @Override
    public NativeWindowDownstream createNativeWindow(final Applet3Context ctx, final NativeWindowUpstream parentWin) {
        final GLCapabilities caps = new GLCapabilities(GLProfile.getDefault());
        final Window w = NewtFactory.createWindow(parentWin.getDisplayConnection(), parentWin.getScreenIndex(), parentWin.getWindowHandle(), caps);
        canvas = GLWindow.create(w);
        canvas.setSize(parentWin.getWidth(), parentWin.getHeight());

        return new NativeWindowDownstream() {
            @Override
            public void setVisible(boolean v) {
                if( null != canvas ) {
                    canvas.setVisible(v);
                }
            }

            @Override
            public void setSize(int width, int height) {
                if( null != canvas ) {
                    canvas.setSize(width, height);
                }
            }

            @Override
            public void requestFocus() {
                if( null != canvas ) {
                    canvas.requestFocus();
                }
            }

            @Override
            public void destroy() {
                if( null != canvas ) {
                    canvas.destroy();
                }
            }

            @Override
            public NativeWindowUpstream getParent() {
                return parentWin;
            }

            @Override
            public long getWindowHandle() {
                if( null != canvas ) {
                    return canvas.getWindowHandle();
                } else {
                    return 0;
                }
            }

            @Override
            public void display() {
                if( null != canvas ) {
                    canvas.display();
                }
            }
        };
    }

    @Override
    public void init(Applet3Context ctx) {
        System.err.println("VersionApplet: init() - begin");
        canvas.addGLEventListener(new GLInfo());
        System.err.println("VersionApplet: init() - end");
    }

    @Override
    public void start() {
        System.err.println("VersionApplet: start() - begin");

        String s;

        s = VersionUtil.getPlatformInfo().toString();
        System.err.println(s);

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

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

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

        GLDrawableFactory factory = GLDrawableFactory.getFactory(canvas.getGLProfile());
        List<GLCapabilitiesImmutable> availCaps = factory.getAvailableCapabilities(null);
        for(int i=0; i<availCaps.size(); i++) {
            s = availCaps.get(i).toString();
            System.err.println(s);
        }
        canvas.display();
        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");
        if(null!=canvas) {
            canvas.destroy();
            canvas = null;
        }
        System.err.println("VersionApplet: destroy() - end");
    }

    @Override
    public String getAppletInfo() {
        return null;
    }

    @Override
    public Locale getLocale() {
        return null;
    }

    @Override
    public String[][] getParameterInfo() {
        return null;
    }

    class GLInfo implements GLEventListener {
        @Override
        public void init(GLAutoDrawable drawable) {
            GL gl = drawable.getGL();
            String s = JoglVersion.getGLInfo(gl, null).toString();
            System.err.println(s);
        }
        @Override
        public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {
        }
        @Override
        public void display(GLAutoDrawable drawable) {
        }
        @Override
        public void dispose(GLAutoDrawable drawable) {
        }
    }
}