Guest User

Untitled

a guest
Oct 21st, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. import static org.lwjgl.opengl.GL11.*;
  2. import java.util.Random;
  3. import org.lwjgl.opengl.*;
  4. import org.lwjgl.*;
  5. import org.lwjgl.input.Keyboard;
  6.  
  7. public class Input {
  8.  
  9. static int displayHeight = 480;
  10. static int displayWidth = 640;
  11.  
  12. public Input() {
  13. try {
  14. Display.setDisplayMode(new DisplayMode(displayWidth, displayHeight));
  15. Display.setTitle("Input");
  16. Display.create();
  17. } catch (LWJGLException e) {
  18. e.printStackTrace();
  19. }
  20.  
  21.  
  22. glMatrixMode(GL_PROJECTION);
  23. glLoadIdentity();
  24. glOrtho(0, displayWidth, displayHeight, 0, 1, -1);
  25. glMatrixMode(GL_MODELVIEW);
  26.  
  27. Display.update();
  28.  
  29. while (!Display.isCloseRequested()) {
  30. glClear(GL_COLOR_BUFFER_BIT);
  31.  
  32. if (Keyboard.isKeyDown(Keyboard.KEY_ESCAPE)) {
  33. Display.destroy();
  34. }
  35.  
  36. for(int i=1; i<=displayWidth; i+=10){
  37. Box.draw(i);
  38. }
  39. Display.update();
  40. Display.sync(60);
  41. }
  42.  
  43. Display.destroy();
  44.  
  45. }
  46.  
  47. private static class Box {
  48. public static int height;
  49.  
  50. public static void draw(int b) {
  51. Random randomHeight = new Random();
  52. height = randomHeight.nextInt(30) + 300;
  53. glBegin(GL_QUADS);
  54. glVertex2f(b, height); // Upper Left
  55. glVertex2f(b, displayHeight); // Bottom Left
  56. glVertex2f(b + 10, displayHeight); // Bottom Right
  57. glVertex2f(b + 10, height); // Upper Right
  58. glEnd();
  59.  
  60. }
  61.  
  62. }
  63.  
  64. public static void main(String[] args) {
  65. new Input();
  66. }
  67. }
Add Comment
Please, Sign In to add comment