Hello,
I'm a Java developer who's been building high-performance Java applications for a while now and thought it would interesting to try something new. The LWJGL seemed to be a good option. Computer resources are becoming so cheep that at some point I think that gaming on Java will become more and more pervasive.
That being said, I'm trying to run a simple test program but I'm getting an error as such:
Quote#
# EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x00b8d6df, pid=2804, tid=3880
#
# Java VM: Java HotSpot(TM) Client VM (1.5.0_06-b05 mixed mode)
# Problematic frame:
# j org.lwjgl.opengl.GL11.glViewport(IIII)V+3
I believe I'm using the latest LWJGL and I just downloaded and installed the latest Nvidia drivers to no avail. The offending code is as follows:
private static int width = 800;
private static int height = 600;
private static void init(boolean fullscreen) throws Exception {
// find out what the current bits per pixel of the desktop is
int currentBpp = Display.getDisplayMode().getBitsPerPixel();
// find a display mode at 800x600
DisplayMode mode = null;
try {
mode = findDisplayMode(800, 600, currentBpp);
} catch (LWJGLException e1) {
e1.printStackTrace();
System.exit(1);
}
// if can't find a mode, notify the user the give up
if (mode == null) {
Sys.alert("Error", "800x600x"+currentBpp+" display mode unavailable");
return;
}
// Create a fullscreen window with 1:1 orthographic 2D projection (default)
Display.setTitle(GAME_TITLE);
Display.setFullscreen(fullscreen);
Display.setDisplayMode(mode);
GL11.glViewport(0, 0, width, height);
GL11.glMatrixMode(GL11.GL_PROJECTION);
float aspect = width/height;
GLU.gluPerspective(45.0f,aspect,0.1f,100.0f);
GL11.glMatrixMode(GL11.GL_MODELVIEW);
GL11.glShadeModel(GL11.GL_SMOOTH); // Enable Smooth Shading
GL11.glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // Black Background
GL11.glClearDepth(1.0f); // Depth Buffer Setup
GL11.glEnable(GL11.GL_DEPTH_TEST); // Enables Depth Testing
GL11.glDepthFunc(GL11.GL_LEQUAL); // The Type Of Depth Testing To Do
// Really Nice Perspective Calculations
GL11.glHint(GL11.GL_PERSPECTIVE_CORRECTION_HINT, GL11.GL_NICEST);
// Create default display of 640x480
Display.create();
}
I was able to get LWJGL to work with a simple 2D animation, but this code is part of a 3D box example and happens each time. It's
possible that this is a bug in the the JNI interface or something along those lines but since this is something new for me I'm more inclined to blame human error on my part.
Any idea what the cause could be?
you need to create display before calling opengl commands
Well, gee...
This may be something usefull just for beginner LWGL programmers but it would be nice to have Display.create() throw an exception rather than allow the VM throw an access violation. Would have made debugging a little easier. Now I know but I'm sure there will be other hapless programmers like me who wouldn't have thought of that.
I think you mean that the offending gl call (glViewport) should throw. And it does, but you're actually running into a bug in the JVM (http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6342951).
- elias
Well, gee, again.
On another similar note, is there a book that one of our LWJGL friends could recommend to help get started with this? Trial and errir is fun and all but it's nice to have some guidance.
well, there are two things:
LWJGL stuff:
- http://lwjgl.org/wiki/doku.php/lwjgl/tutorials/index
- http://www.cokeandcode.com/node/10
- http://www.cokeandcode.com/asteroidstutorial
and then OpenGL stuff, which the tutorials above also touch, but you should consider using:
- http://nehe.gamedev.net/ (c++ code, but has lwjgl code at the bottom - and OpenGL commands is the same across languages)
- http://www.gamedev.net/download/redbook.pdf
just off the top of my head...