jts3304

Untitled

May 30th, 2017
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. package me.smorce.project;
  2.  
  3. import static org.lwjgl.glfw.GLFW.*;
  4. import static org.lwjgl.opengl.GL11.*;
  5. import static org.lwjgl.system.MemoryUtil.*;
  6. import org.lwjgl.glfw.GLFWVidMode;
  7. import me.smorce.project.input.Input;
  8.  
  9. public class Game
  10. {
  11. public boolean running = false;
  12. private long window;
  13. public int windowWidth = 1280;
  14. public int windowHeight = windowWidth / 16 * 9;
  15.  
  16. public void start()
  17. {
  18. running = true;
  19. init();
  20. while(running)
  21. {
  22. update();
  23. render();
  24. if(glfwWindowShouldClose(window)) running = false;
  25. }
  26. }
  27.  
  28. private void init()
  29. {
  30. if(!glfwInit())
  31. {
  32. System.err.println("GLFW failed to initialize!");
  33. return;
  34. }
  35. glfwWindowHint(GLFW_RESIZABLE, GL_TRUE);
  36. window = glfwCreateWindow(windowWidth, windowHeight, "Game", NULL, NULL);
  37. if(window == NULL)
  38. {
  39. System.err.println("GLFW failed to create the window");
  40. return;
  41. }
  42. GLFWVidMode videoMode = glfwGetVideoMode(glfwGetPrimaryMonitor());
  43. glfwSetWindowPos(window, (videoMode.width() - windowWidth) / 2, (videoMode.height() - windowHeight) / 2);
  44. glfwSetKeyCallback(window, new Input());
  45. glfwMakeContextCurrent(window);
  46. glEnable(GL_DEPTH_TEST);
  47. System.out.println("OpenGL: " + glGetString(GL_VERSION));
  48. glfwShowWindow(window);
  49. glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
  50. }
  51.  
  52. private void update()
  53. {
  54. glfwPollEvents();
  55. if(Input.keys[GLFW_KEY_SPACE])
  56. {
  57. System.out.println("SPACE BAR");
  58. }
  59. }
  60.  
  61. private void render()
  62. {
  63. glfwSwapBuffers(window);
  64. }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment