He is currently experimenting with OpenGL in Java. After running the following test code for several cycles in NetBeans, I get a low memory error and the program exits. This problem occurs some time after starting the application after several successful cycles.
Why is this happening and how can it be fixed?
the code:
package test3d;
import org.lwjgl.LWJGLException;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.DisplayMode;
import org.lwjgl.opengl.GL11;
import org.lwjgl.input.Keyboard;
class ColoredTriangle {
public void start() {
try {
Display.setFullscreen(true);
DisplayMode dm = new DisplayMode(34,34);
Display.create();
} catch (LWJGLException e) {
e.printStackTrace();
System.exit(0);
}
GL11.glMatrixMode(GL11.GL_PROJECTION);
GL11.glLoadIdentity();
GL11.glOrtho(-3, 3, -2.4, 2.4, -1, 1);
GL11.glRotatef(0.0f,5.0f,1.0f,0.0f);
GL11.glMatrixMode(GL11.GL_MODELVIEW);
boolean quit = false;
while (!quit) {
GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
GL11.glBegin(GL11.GL_QUADS);
GL11.glColor3f(1.0f,0.0f,0.0f);
GL11.glVertex3f(1.0f,0.0f, -1f);
GL11.glVertex3f(1.0f,1.0f, -1f);
GL11.glVertex3f(2.0f,1.0f, -1f);
GL11.glVertex3f(2.0f,0.0f, -1f);
GL11.glEnd();
Display.update();
if (Display.isCloseRequested() || Keyboard.isKeyDown(Keyboard.KEY_ESCAPE))
quit = true;
}
Display.destroy();
System.exit(0);
}
}
class Test3d
{
public static void main(String args[]) {
ColoredTriangle ct = new ColoredTriangle();
ct.start();
}
}
source
share