我试图同时显示两个显示器,使用线程并将它们显示在 2 个不同的画布上。
软件统计:
- 操作系统名称 Linux
- 操作系统版本 3.16.0-34-generic
- LWJGL 版本 2.9.3
- OpenGL 3.3 版(核心配置文件)Mesa 10.1.3
我试图运行的 GUI 类中的代码:
public UIMain2() {
initComponents();
canvas1 = new Canvas();
canvas1.setSize(700, 350);
canvas1.setBackground(Color.WHITE);
canvas1.isDisplayable();
canvas1.setVisible(true);
jPanel2.add(canvas1);
dt1 = new DisplayThread(canvas1);
dt1.start();
canvas2 = new Canvas();
canvas2.setSize(700, 350);
canvas2.setBackground(Color.WHITE);
canvas2.isDisplayable();
canvas2.setVisible(true);
jPanel3.add(canvas2);
dt2 = new DisplayThread(canvas2);
dt2.start();
}
我的线程类的示例代码:
public class DisplayThread extends Thread {
Canvas canvas;
String modelString = "";
Player player;
Camera camera;
DisplayManager m;
public DisplayThread(Canvas canvas) {
this.canvas = canvas;
}
public void run() {
m = new DisplayManager();
m.createDisplayJFrame(canvas);
...
}
...
}
我的 DisplayManager 类的示例代码:
public class DisplayManager {
private static final int WIDTH = 700;
private static final int HEIGHT = 350;
private static final int FPS_CAP = 120;
private static long lastFrameTime;
private static float delta;
//Display d = new Display();
public void createDisplayJFrame(Canvas canvas) {
ContextAttribs attribs = new ContextAttribs(3, 2)
.withForwardCompatible(true).withProfileCore(true);
try {
Display.setDisplayMode(new DisplayMode(WIDTH, HEIGHT));
Display.setParent(canvas);
Display.create(new PixelFormat(), attribs);
Display.setTitle("Potato");
} catch (LWJGLException ex) {
}
GL11.glViewport(0, 0, WIDTH, HEIGHT);
}
...
}
我得到的错误是:“任何时候只能实例化一个 LWJGL 上下文”
有没有办法解决这个问题来显示每个线程所做的显示?目前只有一个画布显示。