Can some one show me simple lwjgl applet that uses Display.setParent()?
Or help find me error in this sample, i have only black screen:
import java.applet.Applet;
import java.awt.BorderLayout;
import java.awt.Canvas;
import org.lwjgl.LWJGLException;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.GL11;
public class LWJGLapplet extends Applet {
Canvas display_parent;
Thread gameThread;
boolean running = false;
public void destroy() {
super.destroy();
running = false;
System.out.println("*** destroy ***");
}
public void start()
{
super.start();
System.out.println("*** start ***");
gameThread = new Thread()
{
public void run()
{
running = true;
try
{
System.out.println("display_parent.isDisplayable() = " + display_parent.isDisplayable());
Display.setParent(display_parent);
//Display.setVSyncEnabled(true);
Display.create();
}
catch (LWJGLException e)
{
e.printStackTrace();
}
//gameLoop();
while(true)
{
Display.update();
render();
}
}
};
gameThread.start();
}
private void render()
{
// clear the screen
GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_STENCIL_BUFFER_BIT);
// center square according to screen size
GL11.glPushMatrix();
GL11.glTranslatef(Display.getDisplayMode().getWidth() / 2, Display.getDisplayMode().getHeight() / 2, 0.0f);
// rotate square according to angle
GL11.glRotatef(0.05f, 0, 0, 1.0f);
GL11.glBegin(GL11.GL_QUADS);
GL11.glVertex2i(-50, -50);
GL11.glVertex2i(50, -50);
GL11.glVertex2i(50, 50);
GL11.glVertex2i(-50, 50);
GL11.glEnd();
GL11.glPopMatrix();
}
public void stop() {
super.stop();
System.out.println("*** stop ***");
}
public void init()
{
setLayout(new BorderLayout());
try {
display_parent = new Canvas() {
public final void removeNotify() {
super.removeNotify();
}
};
display_parent.setSize(getWidth(),getHeight());
add(display_parent);
display_parent.setFocusable(true);
display_parent.requestFocus();
//display_parent.setIgnoreRepaint(true);
//setResizable(true);
setVisible(true);
} catch (Exception e) {
System.err.println(e);
throw new RuntimeException("Unable to create display");
}
}
}