/** Initializes the canvas by setting the viewport, lighting, etc. */ public void init() { glShadeModel(GL_SMOOTH); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); sphere=new Sphere(); cylinder=new Cylinder(); disk=new Disk(); //GL_LIGHT0 is a very dim backlight; with it I can only see silhouetted spheres against oblique walls. //GL_LIGHT0 is enabled only in 3D mode. floatBuffer = toBuffer(new float[] {0.3f, 0.3f, 0.3f, 1.0f}); floatBuffer.flip(); //glLight(GL_LIGHT0, GL_AMBIENT_AND_DIFFUSE, floatBuffer); // RGBA values glLight(GL_LIGHT0, GL_AMBIENT, floatBuffer); // RGBA values glLight(GL_LIGHT0, GL_DIFFUSE, floatBuffer); // RGBA values floatBuffer = toBuffer(new float[] {0.6f, 0.6f, 0.6f, 0.3f}); floatBuffer.flip(); glLight(GL_LIGHT0, GL_SPECULAR, floatBuffer); floatBuffer = toBuffer(new float[] {0.0f, 0.0f, -1.0f, 0.0f}); floatBuffer.flip(); glLight(GL_LIGHT0, GL_POSITION, floatBuffer); // position (directional if last coord is 0) //GL_LIGHT1 is enabled only in 3D mode, and its position is set elsewhere floatBuffer = toBuffer(new float[] {0.3f, 0.3f, 0.3f, 1.0f}); floatBuffer.flip(); glLight(GL_LIGHT1, GL_AMBIENT, floatBuffer); // very dim gray walls; spheres invisible floatBuffer = toBuffer(new float[] {0.8f, 0.8f, 0.8f, 1.0f}); floatBuffer.flip(); glLight(GL_LIGHT1, GL_DIFFUSE, floatBuffer); // this is most of what we see floatBuffer = toBuffer(new float[] {1.0f, 1.0f, 1.0f, 1.0f}); floatBuffer.flip(); glLight(GL_LIGHT1, GL_SPECULAR, floatBuffer); // no noticeable contribution - it looks black! floatBuffer = toBuffer(new float[] {0.0f, 0.0f, -1.0f, 1.0f}); floatBuffer.flip(); glLight(GL_LIGHT1, GL_SPOT_DIRECTION, floatBuffer); glLightf(GL_LIGHT1, GL_SPOT_CUTOFF, 180); glLightf(GL_LIGHT1, GL_LINEAR_ATTENUATION, 0.5E-5f); glLightf(GL_LIGHT1, GL_SPOT_EXPONENT, 64); //GL_LIGHT2 is only enabled in 1D and 2D modes. floatBuffer = toBuffer(new float[] {0.1f, 0.1f, 0.1f, 1.0f}); floatBuffer.flip(); glLight(GL_LIGHT2, GL_AMBIENT, floatBuffer); floatBuffer = toBuffer(new float[] {1.0f, 1.0f, 1.0f, 1.0f}); floatBuffer.flip(); glLight(GL_LIGHT2, GL_DIFFUSE, floatBuffer); floatBuffer = toBuffer(new float[] {0.0f, 0.0f, 0.0f, 1.0f}); floatBuffer.flip(); glLight(GL_LIGHT2, GL_SPECULAR, floatBuffer); floatBuffer = toBuffer(new float[] {0.0f, 0.0f, 1.0f, 0.0f}); floatBuffer.flip(); glLight(GL_LIGHT2, GL_POSITION, floatBuffer); glEnable(GL_LIGHTING); glColorMaterial(GL_FRONT, GL_DIFFUSE); glEnable(GL_COLOR_MATERIAL); glEnable(GL_DEPTH_TEST); glEnable(GL_NORMALIZE); glCullFace(GL_BACK); glEnable(GL_CULL_FACE); glEnable(GL_POLYGON_SMOOTH); glEnable(GL_LINE_SMOOTH); glEnable(GL_POINT_SMOOTH); glEnable(GL_BLEND); glEnable(GL_DITHER); glPointSize(tracePointSize); curPointSize=tracePointSize; //Print valuable OpenGL driver info to the console for debugging. System.out.println(glGetString(GL_VENDOR)); System.out.println(glGetString(GL_RENDERER)); System.out.println(glGetString(GL_VERSION)); makeCube(); }