Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class lwjgl_test {
- static int vaoID;
- static int vboID;
- public static void create(String name){
- try{
- System.out.println("Window Creation");
- Display.setDisplayMode(new DisplayMode(800, 600));
- // Display.setVSyncEnabled(true);
- Display.setTitle(name);
- Display.create(new PixelFormat(), new ContextAttribs(3, 2).withForwardCompatible(true).withProfileCore(true));
- System.out.println("OpenGL version: " + GL11.glGetString(GL11.GL_VERSION));
- }
- catch(LWJGLException e){
- e.printStackTrace();
- System.exit(-1);
- }
- GL11.glClearColor(0.4f, 0.6f, 0.9f, 0f);
- GL11.glViewport(0, 0, 800, 600);
- setupQuad();
- render();
- }
- public static void setupQuad(){
- float[] vertices = {
- // Left bottom triangle
- -0.5f, 0.5f, 0f,
- -0.5f, -0.5f, 0f,
- 0.5f, -0.5f, 0f,
- // Right top triangle
- 0.5f, -0.5f, 0f,
- 0.5f, 0.5f, 0f,
- -0.5f, 0.5f, 0f
- };
- FloatBuffer verticesBuf = BufferUtils.createFloatBuffer(vertices.length);
- verticesBuf.put(vertices);
- verticesBuf.flip();
- int vertexcount = 6;
- vaoID = GL30.glGenVertexArrays();
- GL30.glBindVertexArray(vaoID);
- vboID = GL15.glGenBuffers();
- GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vboID);
- GL15.glBufferData(GL15.GL_ARRAY_BUFFER, verticesBuf, GL15.GL_STATIC_DRAW);
- GL20.glVertexAttribPointer(0 ,3 , GL11.GL_FLOAT, false, 0, 0);
- // debind
- GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
- GL30.glBindVertexArray(0);
- }
- public static void render(){
- while(!Display.isCloseRequested()){
- update();
- GL30.glBindVertexArray(vaoID);
- GL20.glEnableVertexAttribArray(0);
- GL11.glDrawArrays(GL11.GL_TRIANGLES, 0, 6);
- GL20.glDisableVertexAttribArray(0);
- GL30.glBindVertexArray(0);
- }
- clean();
- }
- public static void update(){
- GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);
- Display.sync(60);
- Display.update();
- }
- public static void clean(){
- GL20.glDisableVertexAttribArray(0);
- GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
- GL15.glDeleteBuffers(vboID);
- GL30.glBindVertexArray(0);
- GL30.glDeleteVertexArrays(vaoID);
- }
- public static void main(String[] args) {
- create("LWJGL");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment