import java.applet.Applet; import java.awt.Graphics; import java.awt.event.ComponentEvent; import java.awt.event.ComponentListener; // must import jgl.GL.... import jgl.GL; import jgl.GLAUX; public class light extends Applet implements ComponentListener { // must use GL to use jGL..... // and use GLAUX to use the aux functions..... // remember to give GL to initialize GLAUX GL myGL = new GL (); GLAUX myAUX = new GLAUX (myGL); private void myinit () { float mat_specular[] = { 1.0f, 1.0f, 1.0f, 1.0f }; float mat_shininess[] = { 50.0f }; float light_position[] = { 1.0f, 1.0f, 1.0f, 0.0f }; myGL.glMaterialfv (GL.GL_FRONT, GL.GL_SPECULAR, mat_specular); myGL.glMaterialfv (GL.GL_FRONT, GL.GL_SHININESS, mat_shininess); myGL.glLightfv (GL.GL_LIGHT0, GL.GL_POSITION, light_position); myGL.glEnable (GL.GL_LIGHTING); myGL.glEnable (GL.GL_LIGHT0); myGL.glDepthFunc (GL.GL_LEQUAL); myGL.glEnable (GL.GL_DEPTH_TEST); } private void display () { myGL.glClear (GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); myAUX.auxSolidSphere (1.0); myGL.glFlush (); } public void componentMoved (ComponentEvent e) {} public void componentShown (ComponentEvent e) {} public void componentHidden (ComponentEvent e) {} public void componentResized (ComponentEvent e) { // get window width and height by myself myReshape (getSize ().width, getSize ().height); display (); repaint (); } private void myReshape (int w, int h) { myGL.glViewport (0, 0, w, h); myGL.glMatrixMode (GL.GL_PROJECTION); myGL.glLoadIdentity (); if (w <= h) { myGL.glOrtho (-1.5f, 1.5f, -1.5f*(float)h/(float)w, 1.5f*(float)h/(float)w, -10.0f, 10.0f); } else { myGL.glOrtho ( -1.5f*(float)w/(float)h, 1.5f*(float)w/(float)h, -1.5f, 1.5f, -10.0f, 10.0f); } myGL.glMatrixMode (GL.GL_MODELVIEW); myGL.glLoadIdentity (); } public void update (Graphics g) { // skip the clear screen command.... paint (g); } public void paint (Graphics g) { myGL.glXSwapBuffers (g, this); } public void init () { myAUX.auxInitPosition (0, 0, 500, 500); myAUX.auxInitWindow (this); myinit (); // as call auxReshapeFunc() addComponentListener (this); myReshape (getSize ().width, getSize ().height); // call display as call auxMainLoop(display); display (); } }