Guest User

Untitled

a guest
Jan 18th, 2019
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.26 KB | None | 0 0
  1. public class cube extends JFrame implements GLEventListener, KeyListener
  2. {
  3. private GLUT glut;
  4. private GLCanvas canvas;
  5.  
  6. public cube()
  7. {
  8. super("cube");
  9. //
  10. canvas = new GLCanvas();
  11. canvas.addGLEventListener(this);
  12. canvas.addKeyListener(this);
  13. //
  14. getContentPane().add(canvas);
  15. }
  16.  
  17. public void run()
  18. {
  19. setSize(500, 500);
  20. setLocationRelativeTo(null);
  21. setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  22. setVisible(true);
  23. canvas.requestFocusInWindow();
  24. }
  25.  
  26. public void init(GLAutoDrawable drawable)
  27. {
  28. GL gl = drawable.getGL();
  29. glut = new GLUT();
  30. //
  31. gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
  32. gl.glShadeModel(GL.GL_FLAT);
  33. }
  34.  
  35. /*
  36. * Clear the screen. Set the current color to white. Draw the wire frame cube.
  37. */
  38. public void display(GLAutoDrawable drawable)
  39. {
  40. GL gl = drawable.getGL();
  41. GLU glu = new GLU();
  42. GLUT glut = new GLUT();
  43. //
  44. gl.glClear(GL.GL_COLOR_BUFFER_BIT);
  45. gl.glColor3f(1.0f, 1.0f, 1.0f);
  46. gl.glLoadIdentity(); /* clear the matrix */
  47.  
  48. /* viewing transformation */
  49. glu.gluLookAt(0.0, 0.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
  50. gl.glScalef(1.0f, 2.0f, 1.0f); /* modeling transformation */
  51. glut.glutWireCube(1.0f);
  52. gl.glFlush();
  53.  
  54. }
  55.  
  56. /*
  57. * Called when the window is first opened and whenever the window is
  58. * reconfigured (moved or resized).
  59. */
  60. public void reshape(GLAutoDrawable drawable, int x, int y, int w, int h)
  61. {
  62. GL gl = drawable.getGL();
  63. //
  64. gl.glMatrixMode(GL.GL_PROJECTION); /* prepare for and then */
  65. gl.glLoadIdentity(); /* define the projection */
  66. gl.glFrustum(-1.0, 1.0, -1.0, 1.0, 1.0, 1.0); /* transformation */
  67. gl.glMatrixMode(GL.GL_MODELVIEW); /* back to modelview matrix */
  68. gl.glViewport(0, 0, w, h); /* define the viewport */
  69. }
  70.  
  71. public void displayChanged(GLAutoDrawable drawable, boolean modeChanged,
  72. boolean deviceChanged)
  73. {
  74. }
  75.  
  76. public void keyTyped(KeyEvent arg0)
  77. {
  78. }
  79.  
  80. public void keyPressed(KeyEvent key)
  81. {
  82. switch (key.getKeyCode()) {
  83. case KeyEvent.VK_ESCAPE:
  84. System.exit(0);
  85. default:
  86. break;
  87. }
  88. }
  89.  
  90. public void keyReleased(KeyEvent arg0)
  91. {
  92. }
  93.  
  94. }
Add Comment
Please, Sign In to add comment