Herkules has informed me that the following code generates (on NT4) this error message:
ava.lang.IllegalStateException: Keyboard must be created before you can enable buffering
at org.lwjgl.input.Keyboard.enableBuffer(Unknown Source)
at LWJGL.initGL(LWJGL.java:129)
at LWJGL.init(LWJGL.java:122)
at LWJGL.start(LWJGL.java:93)
at BasicGame.main(BasicGame.java:56)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.sun.javaws.Launcher.executeApplication(Unknown Source)
at com.sun.javaws.Launcher.executeMainClass(Unknown Source)
at com.sun.javaws.Launcher.continueLaunch(Unknown Source)
at com.sun.javaws.Launcher.handleApplicationDesc(Unknown Source)
at com.sun.javaws.Launcher.handleLaunchFile(Unknown Source)
at com.sun.javaws.Launcher.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
There’s no error message on my winxp system
Here’s my code:
import static org.lwjgl.opengl.GL11.*;
import static org.lwjgl.opengl.glu.GLU.*;
public final class BasicGame extends LWJGL
{
/** Some stuff I added for fun **/
private float translation=0.0f;
private float velocity=0.02f;
private float rot=0;
/** Lwjgl constructor.
*/
public BasicGame()
{
super("BasicGame", false);
}
/** Rendering method.
*/
protected final void render()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
// Draw here...
glTranslatef(-1.5f,0.0f,-6.0f); // Move Left 1.5 Units And Into The Screen 6.0
glRotatef(rot,1.0f,1.0f,0.0f);
glBegin(GL_QUADS); // Drawing Using Triangles
glColor3f(1.0f,0.0f,0.0f);
glVertex3f( 0.0f+translation, 1.0f, 0.0f); // Top
glColor3f(0.0f,1.0f,0.0f);
glVertex3f(-1.0f+translation,-1.0f, 0.0f); // Bottom Left
glColor3f(0.0f,0.0f,1.0f);
glVertex3f( 1.0f+translation,-1.0f, 0.0f); // Bottom Right
glColor3f(1.0f,1.0f,1.0f);
glVertex3f( 1.0f+translation,0.0f, 1.0f);
glEnd();
rot+=3.0f;
translation+=velocity;
if (translation < 0.0f || translation > 3.0f)
velocity=-velocity;
}
/** Main method.
*/
public static void main(String args[])
{
(new BasicGame()).start();
}
}
/* Standard imports.
*/
import org.lwjgl.*;
import org.lwjgl.input.*;
import org.lwjgl.opengl.*;
import java.io.BufferedInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import org.lwjgl.fmod.FMOD;
import org.lwjgl.fmod.FMODException;
import org.lwjgl.fmod.FSound;
import org.lwjgl.fmod.FSoundStream;
/* Static imports.
*/
import static org.lwjgl.opengl.GL11.*;
import static org.lwjgl.opengl.glu.GLU.*;
import static org.lwjgl.fmod.FMOD.*;
import static org.lwjgl.fmod.FSound.*;
public abstract class LWJGL {
/** Is game finished ? **/
protected boolean finished;
/** Parameters **/
protected boolean fullscreen;
protected String title;
/** Lwjgl constructor.
*/
public LWJGL(String title, boolean fullscreen)
{
this.title = title;
this.fullscreen = fullscreen;
createWindow();
}
protected void createWindow()
{
try
{
if (fullscreen)
{
int mode = -1;
DisplayMode modes[] = Display.getAvailableDisplayModes();
for(int i = 0; i < modes.length; i++)
{
if(modes[i].width == 1024
&& modes[i].height == 768
&& modes[i].bpp >= 32)
{
mode = i;
break;
}
}
if(mode != -1)
{
System.out.println("Setting display mode to " + modes[mode]);
Display.setDisplayMode(modes[mode]);
}
Window.create(title, 32, 0, 0, 0);
}
else
Window.create(title, 0, 0, 800, 600, 32, 0, 8, 0);
}
catch(Exception e)
{
System.err.println("Failed to create display/OpenGL mode due to " + e);
System.exit(1);
}
}
/** Start OpenGL application.
*/
protected void start()
{
try
{
init();
while(!finished)
{
if(Window.isCloseRequested())
System.exit(0);
process_keyboard();
render();
Window.update();
}
}
catch(Throwable t)
{
t.printStackTrace();
}
finally
{
cleanup();
}
}
/** Init OpenGL and FMOD.
*/
protected void init() throws Exception
{
initGL();
initFMOD();
}
protected void initGL() throws Exception
{
// Enable keyboard buffer.
Keyboard.enableBuffer();
// Go into 3D projection mode.
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0f, (float)Display.getWidth() / (float)Display.getHeight(), 1.0f, 200.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glClearColor(0.0f, 0.0f, 0.0f, 0.0f); //Background color (r,g,b,alpha)
}
protected void initFMOD() {}
/** Rendering method.
*/
abstract void render();
/** Process keyboard events.
*/
protected void process_keyboard()
{
for(int i = 0; i < Keyboard.getNumKeyboardEvents(); i++)
{
Keyboard.next();
if(Keyboard.getEventKey() == Keyboard.KEY_ESCAPE && Keyboard.getEventKeyState())
finished = true;
if(Keyboard.getEventKey() == Keyboard.KEY_F1 && Keyboard.getEventKeyState())
{
Window.destroy();
fullscreen = !fullscreen;
createWindow();
try
{
initGL();
}
catch (Throwable t)
{
t.printStackTrace();
System.exit(0);
}
}
}
}
/** Cleanup.
*/
protected void cleanup()
{
Keyboard.destroy();
Window.destroy();
cleanupFMOD();
try
{
Display.resetDisplayMode();
}
catch(Exception e)
{
e.printStackTrace();
}
}
protected void cleanupFMOD() {}
}
Does anyone no what the problem and maybe how to solve it?
It can be found as a web start app at www.projektrandom.frac.dk
