Guest User

Untitled

a guest
Nov 16th, 2013
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.15 KB | None | 0 0
  1. public class lwjgl_test {
  2.     static int vaoID;
  3.     static int vboID;
  4.     public static void create(String name){
  5.         try{
  6.             System.out.println("Window Creation");
  7.             Display.setDisplayMode(new DisplayMode(800, 600));
  8.         //  Display.setVSyncEnabled(true);
  9.             Display.setTitle(name);
  10.             Display.create(new PixelFormat(), new ContextAttribs(3, 2).withForwardCompatible(true).withProfileCore(true));
  11.             System.out.println("OpenGL version: " + GL11.glGetString(GL11.GL_VERSION));
  12.         }
  13.         catch(LWJGLException e){
  14.             e.printStackTrace();
  15.             System.exit(-1);
  16.         }
  17.         GL11.glClearColor(0.4f, 0.6f, 0.9f, 0f);
  18.         GL11.glViewport(0, 0, 800, 600);
  19.  
  20.         setupQuad();
  21.         render();
  22.     }
  23.     public static void setupQuad(){
  24.         float[] vertices = {
  25.                 // Left bottom triangle
  26.                 -0.5f, 0.5f, 0f,
  27.                 -0.5f, -0.5f, 0f,
  28.                 0.5f, -0.5f, 0f,
  29.                 // Right top triangle
  30.                 0.5f, -0.5f, 0f,
  31.                 0.5f, 0.5f, 0f,
  32.                 -0.5f, 0.5f, 0f
  33.         };
  34.         FloatBuffer verticesBuf = BufferUtils.createFloatBuffer(vertices.length);
  35.         verticesBuf.put(vertices);
  36.         verticesBuf.flip();
  37.         int vertexcount = 6;
  38.        
  39.         vaoID = GL30.glGenVertexArrays();
  40.         GL30.glBindVertexArray(vaoID);
  41.         vboID = GL15.glGenBuffers();
  42.         GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vboID);
  43.  
  44.         GL15.glBufferData(GL15.GL_ARRAY_BUFFER, verticesBuf, GL15.GL_STATIC_DRAW);
  45.         GL20.glVertexAttribPointer(0 ,3 , GL11.GL_FLOAT, false, 0, 0);
  46.        
  47.         // debind
  48.         GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
  49.         GL30.glBindVertexArray(0);
  50.        
  51.     }
  52.     public static void render(){
  53.         while(!Display.isCloseRequested()){
  54.             update();
  55.             GL30.glBindVertexArray(vaoID);
  56.             GL20.glEnableVertexAttribArray(0);
  57.            
  58.             GL11.glDrawArrays(GL11.GL_TRIANGLES, 0, 6);
  59.            
  60.             GL20.glDisableVertexAttribArray(0);
  61.             GL30.glBindVertexArray(0);
  62.  
  63.         }
  64.         clean();
  65.     }
  66.     public static void update(){
  67.         GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);
  68.         Display.sync(60);
  69.         Display.update();
  70.     }
  71.     public static void clean(){
  72.         GL20.glDisableVertexAttribArray(0);
  73.         GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
  74.         GL15.glDeleteBuffers(vboID);
  75.         GL30.glBindVertexArray(0);
  76.         GL30.glDeleteVertexArrays(vaoID);
  77.     }
  78.     public static void main(String[] args) {
  79.         create("LWJGL");
  80.     }
  81. }
Advertisement
Add Comment
Please, Sign In to add comment