Advertisement
Guest User

Untitled

a guest
Jun 30th, 2014
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.47 KB | None | 0 0
  1. package passage.games;
  2.  
  3. import static org.lwjgl.opengl.GL11.*;
  4. import static org.lwjgl.opengl.GL20.*;
  5.  
  6. import java.lang.reflect.Field;
  7.  
  8. import org.lwjgl.LWJGLException;
  9. import org.lwjgl.input.Keyboard;
  10. import org.lwjgl.input.Mouse;
  11. import org.lwjgl.opengl.Display;
  12. import org.lwjgl.opengl.DisplayMode;
  13. import org.lwjgl.opengl.PixelFormat;
  14. import org.lwjgl.util.glu.GLU;
  15. import org.lwjgl.util.vector.Vector3f;
  16.  
  17. public class Game {
  18. public Game() throws LWJGLException {init();}
  19.  
  20. public DisplayMode displayMode = null;
  21. public PixelFormat pixelFormat = null;
  22.  
  23. public Camera camera = new Camera();
  24. public Block block = new Block();
  25. public Block block2 = new Block();
  26.  
  27. public Shader shader;
  28.  
  29. public void init() throws LWJGLException{
  30. displayMode = new DisplayMode(800, 600);
  31. pixelFormat = new PixelFormat(8, 16, 1, 4);
  32.  
  33. resetDisplay();
  34. updateProjection();
  35.  
  36. Keyboard.create();
  37. Mouse.create();
  38.  
  39. glClearColor(0.5f, 0.5f, 0.5f, 1f);
  40.  
  41. glEnable(GL_DEPTH_TEST);
  42. glDepthFunc(GL_LEQUAL);
  43. glClearDepth(1.0f);
  44.  
  45. glDisable(GL_CULL_FACE);
  46.  
  47. block.init();
  48. block2.init();
  49.  
  50. block2.location = new Vector3f(0, 2, 0);
  51.  
  52. shader = new Shader();
  53. shader.attachVertexShader("assets/box.vert");
  54. shader.attachFragmentShader("assets/box.frag");
  55. shader.link();
  56.  
  57. while(!Display.isCloseRequested()){
  58. update();
  59. render();
  60. }
  61. }
  62.  
  63. public void render(){
  64. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  65. if(Display.wasResized()) updateProjection();
  66. glLoadIdentity();
  67. camera.translatePosition();
  68.  
  69. shader.bind();
  70.  
  71. glUniform3f(glGetUniformLocation(shader.programID, "lightLocation"), camera.vector.x, camera.vector.y, 10);
  72.  
  73. block.render();
  74. block2.render();
  75.  
  76. shader.unbind();
  77.  
  78. Display.update();
  79. }
  80.  
  81. public void update(){
  82. camera.update();
  83.  
  84. block.update();
  85. block2.update();
  86.  
  87. Display.sync(60);
  88. }
  89.  
  90. public void destroy(){
  91. block.destroy();
  92.  
  93. Keyboard.destroy();
  94. Mouse.destroy();
  95. Display.destroy();
  96. }
  97.  
  98. public static void main(String[] args) throws LWJGLException{
  99. new Game();
  100. }
  101.  
  102. public void resetDisplay() throws LWJGLException{
  103. if(Display.isCreated()) Display.destroy();
  104. Display.setDisplayMode(displayMode);
  105. Display.create(pixelFormat);
  106. }
  107.  
  108. public void updateProjection(){
  109. glMatrixMode(GL_PROJECTION);
  110. glLoadIdentity();
  111. GLU.gluPerspective(45, (float)800 / 600, 0.1f, 1000);
  112. glMatrixMode(GL_MODELVIEW);
  113. }
  114. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement