/* The only code you need to modify here is in the methods Line, and makeList */ import java.awt.*; import java.awt.event.*; import java.util.*; import java.io.*; import javax.media.opengl.*; import javax.media.opengl.glu.*; import com.sun.opengl.util.*; import java.nio.*; public class HW1 implements GLEventListener, MouseListener, MouseMotionListener, KeyListener { static class ProgramTerminator implements WindowListener { public void windowClosing(WindowEvent event) { System.exit(0); } public void windowActivated(WindowEvent event) {} public void windowClosed(WindowEvent event) {} public void windowDeactivated(WindowEvent event) {} public void windowDeiconified(WindowEvent event) {} public void windowIconified(WindowEvent event) {} public void windowOpened(WindowEvent event) {} } private GLAutoDrawable draw; public static int xres,yres; public static String lineFileName; public static void main(String[] args) { Frame frame = new Frame("HW1"); xres = 801; yres = 801; lineFileName = args[0]; frame.setSize(xres,yres); frame.addWindowListener(new ProgramTerminator()); GLCanvas canvas = new GLCanvas(); canvas.addGLEventListener(new HW1()); frame.add(canvas); frame.setVisible(true); } // Methods required for implementation of GLEventListener public void init(GLAutoDrawable drawable) { draw = drawable; // save this for use by other methods GL gl = drawable.getGL(); GLU glu = new GLU(); gl.glMatrixMode(GL.GL_PROJECTION); gl.glLoadIdentity(); glu.gluOrtho2D((double) -xres/2,(double) xres/2,(double) -yres/2,(double) yres/2); gl.glTranslatef(0.375f, 0.375f, 0.0f); gl.glMatrixMode(GL.GL_MODELVIEW); makeList(lineFileName); drawable.addMouseListener(this); drawable.addMouseMotionListener(this); drawable.addKeyListener(this); } public void display(GLAutoDrawable drawable) { GL gl = drawable.getGL(); gl.glClearColor(1.0f,1.0f,1.0f,0.0f); gl.glClear(GL.GL_COLOR_BUFFER_BIT); // Clear window gl.glCallList(1); // There may be more than one List } public void displayChanged(GLAutoDrawable drawable, boolean modeChanged, boolean deviceChanged) {} public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {} // Methods required for the implementation of MouseListener private int prevMouseX, prevMouseY; private boolean mouseRButtonDown = false; public void mouseEntered(MouseEvent e) {} // not implemented public void mouseExited(MouseEvent e) {} // not implemented public void mousePressed(MouseEvent e) { int x = e.getX(); int y = e.getY(); if ((e.getModifiers() & e.BUTTON3_MASK) != 0) { mouseRButtonDown = true; } } public void mouseReleased(MouseEvent e) { if ((e.getModifiers() & e.BUTTON3_MASK) != 0) { mouseRButtonDown = false; } } public void mouseClicked(MouseEvent e) { int x = e.getX(); int y = e.getY(); } // Methods required for the implementation of MouseMotionListener public void mouseDragged(MouseEvent e) { } public void mouseMoved(MouseEvent e) {} // Methods required for the implementation of KeyListener public void keyPressed(KeyEvent e) {} public void keyReleased(KeyEvent e) {} public void keyTyped(KeyEvent e) { char c = e.getKeyChar(); switch (c) { case 'q': System.exit(0); break; } } // OpenGL graphics public void line(GL gl,int x1, int y1,int x2,int y2,float color[]) { // Implement Bresenham's algorithm here // modified so that it works for all slopes // and both positive and negative dx and dy. // When a pixel (x,y) is found on the line // call setPixel(x,y,color) // Test code that you will remove: for (int i=x1;i