I'm going to creat a little program which has two viewports. One shows the perspective view, the other shows the top view. I wrote the program like this:
public class NewJFrame extends javax.swing.JFrame {
private static JmeCanvasContext context;
private static JmeCanvasContext context2;
private static Canvas canvas;
private static Canvas canvas2;
private static Application app;
private static Application app2;
private static AppSettings settings;
private static AppSettings settings2;
/** Creates new form NewJFrame */
public NewJFrame() {
initComponents();
settings = new AppSettings(true);
settings.setWidth(jPanel1.getWidth());
settings.setHeight(jPanel1.getHeight());
settings2 = new AppSettings(true);
settings2.setWidth(jPanel2.getWidth());
settings2.setHeight(jPanel2.getHeight());
JmeSystem.setLowPermissions(true);
app = new TestBumpModel();
app2 = new TestSimpleLighting();
app.setSettings(settings);
app.createCanvas();
app2.setSettings(settings2);
app2.createCanvas();
context = (JmeCanvasContext) app.getContext();
canvas = context.getCanvas();
canvas.setSize(settings.getWidth(), settings.getHeight());
context2 = (JmeCanvasContext) app2.getContext();
canvas2 = context2.getCanvas();
canvas2.setSize(settings2.getWidth(), settings2.getHeight());
jPanel1.add(canvas);
app.startCanvas();
jPanel2.add(canvas2);
app2.startCanvas();
setLocationRelativeTo(null);
}
/** 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() {
jPanel1 = new javax.swing.JPanel();
jPanel2 = new javax.swing.JPanel();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("View1"));
jPanel1.setToolTipText("null");
jPanel1.setPreferredSize(new java.awt.Dimension(280, 280));
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 268, Short.MAX_VALUE)
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 255, Short.MAX_VALUE)
);
jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("View2"));
javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
jPanel2.setLayout(jPanel2Layout);
jPanel2Layout.setHorizontalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 116, Short.MAX_VALUE)
);
jPanel2Layout.setVerticalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 122, Short.MAX_VALUE)
);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addContainerGap())
);
pack();
}// </editor-fold>
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new NewJFrame().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JPanel jPanel1;
private javax.swing.JPanel jPanel2;
// End of variables declaration
}
The TestBumpModel class and TestSimpleLighting class are the sample codes given by JME3.
The program can olny show one viewport which created by the app, the viewport of app2 can not work.
Informations in the log
run:
2010-6-11 18:57:22 com.jme3.asset.DesktopAssetManager <init>
信息: DesktopAssetManager created.
2010-6-11 18:57:22 com.jme3.asset.DesktopAssetManager <init>
信息: DesktopAssetManager created.
2010-6-11 18:57:22 com.jme3.system.JmeSystem initialize
信息: Running on jMonkey Engine 3 ALPHA 0.50
2010-6-11 18:57:22 com.jme3.system.lwjgl.LwjglAbstractDisplay run
信息: Using LWJGL 2.4.2
2010-6-11 18:57:22 com.jme3.system.lwjgl.LwjglAbstractDisplay run
信息: Using LWJGL 2.4.2
Exception in thread "LWJGL Renderer Thread" 2010-6-11 18:57:22 com.jme3.system.lwjgl.LwjglAbstractDisplay initInThread
信息: Display created.
java.lang.IllegalStateException: From thread Thread[LWJGL Renderer Thread,6,main]: Thread[LWJGL Renderer Thread,6,main] already has the context current
at org.lwjgl.opengl.Context.checkAccess(Context.java:172)
at org.lwjgl.opengl.Context.forceDestroy(Context.java:228)
at org.lwjgl.opengl.Display.destroyContext(Display.java:983)
at org.lwjgl.opengl.Display.destroy(Display.java:966)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.initInThread(LwjglAbstractDisplay.java:98)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:147)
at java.lang.Thread.run(Thread.java:619)
2010-6-11 18:57:22 com.jme3.system.lwjgl.LwjglAbstractDisplay initInThread
信息: Adapter: ati2dvag
2010-6-11 18:57:22 com.jme3.system.lwjgl.LwjglAbstractDisplay initInThread
信息: Driver Version: 6.14.10.6806
2010-6-11 18:57:22 com.jme3.system.lwjgl.LwjglAbstractDisplay initInThread
信息: Vendor: ATI Technologies Inc.
2010-6-11 18:57:22 com.jme3.system.lwjgl.LwjglAbstractDisplay initInThread
信息: OpenGL Version: 2.1.7537 Release
2010-6-11 18:57:22 com.jme3.system.lwjgl.LwjglAbstractDisplay initInThread
信息: Renderer: ATI Mobility Radeon HD 2300
2010-6-11 18:57:22 com.jme3.system.lwjgl.LwjglAbstractDisplay initInThread
信息: GLSL Ver: 1.20
2010-6-11 18:57:22 com.jme3.system.lwjgl.LwjglTimer <init>
信息: Timer resolution: 1000 ticks per second
2010-6-11 18:57:22 com.jme3.renderer.Camera <init>
信息: Camera created (W: 640, H: 480)
2010-6-11 18:57:22 com.jme3.input.lwjgl.LwjglMouseInput initialize
信息: Mouse created.
2010-6-11 18:57:22 com.jme3.input.lwjgl.LwjglKeyInput initialize
信息: Keyboard created.
2010-6-11 18:57:23 com.jme3.scene.Node attachChild
信息: Child (BitmapFont) attached to this node (Gui Node)
2010-6-11 18:57:23 com.jme3.scene.Node attachChild
信息: Child (BitmapFont) attached to this node (Statistics View)
2010-6-11 18:57:23 com.jme3.scene.Node attachChild
信息: Child (BitmapFont) attached to this node (Statistics View)
2010-6-11 18:57:23 com.jme3.scene.Node attachChild
信息: Child (BitmapFont) attached to this node (Statistics View)
2010-6-11 18:57:23 com.jme3.scene.Node attachChild
信息: Child (BitmapFont) attached to this node (Statistics View)
2010-6-11 18:57:23 com.jme3.scene.Node attachChild
信息: Child (BitmapFont) attached to this node (Statistics View)
2010-6-11 18:57:23 com.jme3.scene.Node attachChild
信息: Child (BitmapFont) attached to this node (Statistics View)
2010-6-11 18:57:23 com.jme3.scene.Node attachChild
信息: Child (BitmapFont) attached to this node (Statistics View)
2010-6-11 18:57:23 com.jme3.scene.Node attachChild
信息: Child (BitmapFont) attached to this node (Statistics View)
2010-6-11 18:57:23 com.jme3.scene.Node attachChild
信息: Child (BitmapFont) attached to this node (Statistics View)
2010-6-11 18:57:23 com.jme3.scene.Node attachChild
信息: Child (BitmapFont) attached to this node (Statistics View)
2010-6-11 18:57:23 com.jme3.scene.Node attachChild
信息: Child (BitmapFont) attached to this node (Statistics View)
2010-6-11 18:57:23 com.jme3.scene.Node attachChild
信息: Child (BitmapFont) attached to this node (Statistics View)
2010-6-11 18:57:23 com.jme3.scene.Node attachChild
信息: Child (BitmapFont) attached to this node (Statistics View)
2010-6-11 18:57:23 com.jme3.scene.Node attachChild
信息: Child (Statistics View) attached to this node (Gui Node)
2010-6-11 18:57:23 com.jme3.scene.Node attachChild
信息: Child (Models/Teapot/Teapot.obj) attached to this node (Root Node)
2010-6-11 18:57:23 com.jme3.scene.Node attachChild
信息: Child (Light) attached to this node (Root Node)
2010-6-11 18:57:23 com.jme3.renderer.lwjgl.LwjglRenderer updateUniformLocation
警告: Uniform m_VertexColor is not declared in shader.
成功生成(总时间:16 秒)