Display.setDisplayMode(new DisplayMode(300, 300));
Display.setTitle("Gears");
Display.create();
// setup ogl
FloatBuffer pos = BufferUtils.createFloatBuffer(4).put(new float[] { 5.0f, 5.0f, 10.0f, 0.0f});
FloatBuffer red = BufferUtils.createFloatBuffer(4).put(new float[] { 0.8f, 0.1f, 0.0f, 1.0f});
FloatBuffer green = BufferUtils.createFloatBuffer(4).put(new float[] { 0.0f, 0.8f, 0.2f, 1.0f});
FloatBuffer blue = BufferUtils.createFloatBuffer(4).put(new float[] { 0.2f, 0.2f, 1.0f, 1.0f});
pos.flip();
red.flip();
green.flip();
blue.flip();
glLight(GL_LIGHT0, GL_POSITION, pos);
glEnable(GL_CULL_FACE);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_DEPTH_TEST);
/* make the gears */
gear1 = glGenLists(1);
glNewList(gear1, GL_COMPILE);
glMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, red);
gear(1.0f, 4.0f, 1.0f, 20, 0.7f);
glEndList();
gear2 = glGenLists(1);
glNewList(gear2, GL_COMPILE);
glMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, green);
gear(0.5f, 2.0f, 2.0f, 10, 0.7f);
glEndList();
gear3 = glGenLists(1);
glNewList(gear3, GL_COMPILE);
glMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, blue);
gear(1.3f, 2.0f, 0.5f, 10, 0.7f);
glEndList();
glEnable(GL_NORMALIZE);
glMatrixMode(GL_PROJECTION);
System.err.println("LWJGL: " + Sys.getVersion() + " / " + LWJGLUtil.getPlatformName());
System.err.println("GL_VENDOR: " + glGetString(GL_VENDOR));
System.err.println("GL_RENDERER: " + glGetString(GL_RENDERER));
System.err.println("GL_VERSION: " + glGetString(GL_VERSION));
System.err.println();
System.err.println("glLoadTransposeMatrixfARB() supported: " + GLContext.getCapabilities().GL_ARB_transpose_matrix);
if (!GLContext.getCapabilities().GL_ARB_transpose_matrix) {
// --- not using extensions
glLoadIdentity();
} else {
// --- using extensions
final FloatBuffer identityTranspose = BufferUtils.createFloatBuffer(16).put(
new float[] { 1, 0, 0, 0, 0, 1, 0, 0,
0, 0, 1, 0, 0, 0, 0, 1});
identityTranspose.flip();
glLoadTransposeMatrixARB(identityTranspose);
}
float h = (float) 300 / (float) 300;
glFrustum(-1.0f, 1.0f, -h, h, 5.0f, 60.0f);