Guest User

Untitled

a guest
Apr 19th, 2012
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.86 KB | None | 0 0
  1. import com.jogamp.newt.event.WindowAdapter;
  2. import com.jogamp.newt.event.WindowEvent;
  3. import com.jogamp.newt.opengl.GLWindow;
  4. import com.jogamp.opengl.util.FPSAnimator;
  5. import java.nio.FloatBuffer;
  6. import javax.media.opengl.*;
  7.  
  8. public class Main {
  9.    
  10.     static private class EventListener implements GLEventListener {
  11.  
  12.         float[] vertices = {
  13.             -1.0f, -1.0f, 0.0f,
  14.             1.0f, -1.0f, 0.0f,
  15.             0.0f,  1.0f, 0.0f,
  16.         };
  17.        
  18.         int[] vertexBuffer = new int[1];
  19.            
  20.         @Override
  21.         public void init(GLAutoDrawable drawable) {
  22.             GL3 gl = drawable.getGL().getGL3();
  23.             gl.glGenBuffers(1, vertexBuffer, 0);
  24.             gl.glBindBuffer(GL3.GL_ARRAY_BUFFER, vertexBuffer[0]);                          
  25.             gl.glBufferData(GL3.GL_ARRAY_BUFFER, vertices.length * 4, FloatBuffer.wrap(vertices), GL3.GL_STATIC_DRAW);
  26.  
  27.             gl.glClearColor(0, 0, 1.0f, 1.0f);
  28.  
  29.         }
  30.  
  31.         @Override
  32.         public void dispose(GLAutoDrawable drawable) {
  33.             GL3 gl = drawable.getGL().getGL3();
  34.             gl.glDeleteBuffers(1, vertexBuffer, 0);
  35.         }
  36.  
  37.         @Override
  38.         public void display(GLAutoDrawable drawable) {
  39.             GL3 gl = drawable.getGL().getGL3();
  40.  
  41.             gl.glClear(GL3.GL_COLOR_BUFFER_BIT | GL3.GL_DEPTH_BUFFER_BIT);
  42.  
  43.             gl.glEnableVertexAttribArray(0);
  44.  
  45.             gl.glBindBuffer(GL3.GL_ARRAY_BUFFER, vertexBuffer[0]);
  46.             gl.glVertexAttribPointer(
  47.                     0,
  48.                     3,
  49.                     GL3.GL_FLOAT,
  50.                     false,
  51.                     0,
  52.                     0
  53.             );
  54.             gl.glDrawArrays(GL3.GL_TRIANGLE_STRIP, 0, 3);
  55.  
  56.             gl.glDisableVertexAttribArray(0);              
  57.  
  58.         }
  59.  
  60.         @Override
  61.         public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {
  62.  
  63.         }
  64.        
  65.     }
  66.        
  67.     public static void main(String[] args) {
  68.        
  69.         GLProfile profile = GLProfile.get(GLProfile.GL3);
  70.         if(!GLProfile.isAvailable(GLProfile.GL3)) {
  71.             System.out.println("No OpenGL 3");
  72.             System.exit(1);
  73.         }
  74.         GLCapabilities caps = new GLCapabilities(profile);        
  75.         GLWindow window = GLWindow.create(caps);
  76.        
  77.         window.setSize(800, 600);
  78.         window.setVisible(true);
  79.         window.setTitle("Newt Window");
  80.                
  81.         window.addWindowListener(new WindowAdapter() {
  82.             @Override
  83.             public void windowDestroyNotify(WindowEvent arg0) {
  84.                 System.exit(0);
  85.             }
  86.         });
  87.        
  88.         window.addGLEventListener(new EventListener());
  89.        
  90.         FPSAnimator animator = new FPSAnimator(60);
  91.         animator.add(window);
  92.         animator.start();
  93.  
  94.     }
  95.    
  96. }
Advertisement
Add Comment
Please, Sign In to add comment