Reputation: 145
I'm right now trying to mix LWJGL and Swing so I can have Swing's GUI and LWJGLS Graphics... But it doesn't work, Thanks in advance.
Code :
/**
*
*/
public static TSudioQE TSudio;
private static final long serialVersionUID = -8495077485468477943L;
public static void main(String[] args) {
try {
TSudioQE tsudio = new TSudioQE();
} catch (LWJGLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public TSudioQE() throws LWJGLException {
setTitle("TSudio Quall Engine 1X");
JPanel p = new JPanel();
Canvas c = new Canvas();
Display.create();
Display.setParent(c);
GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
// set the color of the quad (R,G,B,A)
GL11.glColor3f(0.5f, 0.5f, 1.0f);
// draw quad
GL11.glBegin(GL11.GL_QUADS);
GL11.glVertex2f(100, 100);
GL11.glVertex2f(100 + 200, 100);
GL11.glVertex2f(100 + 200, 100 + 200);
GL11.glVertex2f(100, 100 + 200);
GL11.glEnd();
add(p);
setSize(800, 460);
setExtendedState(JFrame.MAXIMIZED_BOTH);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
@Override
public void windowOpened(WindowEvent e) {
// TODO Auto-generated method stub
}
@Override
public void windowClosing(WindowEvent e) {
// TODO Auto-generated method stub
}
@Override
public void windowClosed(WindowEvent e) {
// TODO Auto-generated method stub
}
@Override
public void windowIconified(WindowEvent e) {
// TODO Auto-generated method stub
}
@Override
public void windowDeiconified(WindowEvent e) {
// TODO Auto-generated method stub
}
@Override
public void windowActivated(WindowEvent e) {
// TODO Auto-generated method stub
}
@Override
public void windowDeactivated(WindowEvent e) {
// TODO Auto-generated method stub
}
I get the following error:
org.lwjgl.LWJGLException: Parent.isDisplayable() must be true
at org.lwjgl.opengl.Display.createWindow(Display.java:301)
at org.lwjgl.opengl.Display.setParent(Display.java:451)
at qq.application.TSudioQE.<init>(TSudioQE.java:47)
at qq.application.TSudioQE.main(TSudioQE.java:33)
Anyone who know how to fix it? It could be nice.
Have a great day :-)
Upvotes: 1
Views: 2272
Reputation: 2877
The Canvas you set as parent for your Display has to be visible:
JFrame frame = new JFrame();
Canvas canvas = new Canvas();
frame.add(canvas);
frame.setVisible(true);
try
{
Display.setParent(canvas);
Display.create();
}
catch (LWJGLException e)
{
e.printStackTrace();
}
Upvotes: 2