Advertisement
Guest User

JOGL/OpenGL Graphics Driver Crash

a guest
Apr 8th, 2013
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.14 KB | None | 0 0
  1. import java.nio.FloatBuffer;
  2. import java.util.Random;
  3.  
  4. import javax.media.opengl.GL2;
  5. import javax.media.opengl.GLAutoDrawable;
  6. import javax.media.opengl.GLCapabilities;
  7. import javax.media.opengl.GLEventListener;
  8. import javax.media.opengl.glu.GLU;
  9. import com.jogamp.common.nio.Buffers;
  10. import com.jogamp.newt.opengl.GLWindow;
  11. import com.jogamp.opengl.util.Animator;
  12.  
  13. public class IsolatedVBOTest {
  14.     private static final float[] POINT_DISTANCE_ATTENUATION = { 0.0f, 0.0f,
  15.             0.00005f };
  16.    
  17.     //On machines I've tested, reducing the point size OR the total number
  18.     // of vertices prevents crashing.
  19.     private static int POINT_SIZE = 64;
  20.     private static int NUMBER_OF_VERTICES = 3000000;
  21.    
  22.     private static int VERTEX_BUFFER_SIZE = NUMBER_OF_VERTICES * 3;
  23.  
  24.     public static void main(String[] args) {
  25.         Animator animator;
  26.         GLCapabilities caps = new GLCapabilities(null);
  27.         GLWindow window = GLWindow.create(caps);
  28.  
  29.         window.addGLEventListener(new GLEventListener() {
  30.             private GLU glu = new GLU();
  31.             int[] vbufferId = new int[1];
  32.  
  33.             @Override
  34.             public void reshape(GLAutoDrawable drawable, int x, int y,
  35.                     int width, int height) {
  36.                 GL2 gl = (GL2) drawable.getGL();
  37.  
  38.                 if (height <= 0) {
  39.                     height = 1;
  40.                 }
  41.                 final float h = (float) width / (float) height;
  42.                 gl.glViewport(0, 0, width, height);
  43.                 gl.glMatrixMode(GL2.GL_PROJECTION);
  44.                 gl.glLoadIdentity();
  45.                 glu.gluPerspective(45.0f, h, 1.0, 200.0);
  46.                 gl.glMatrixMode(GL2.GL_MODELVIEW);
  47.                 gl.glLoadIdentity();
  48.             }
  49.  
  50.             @Override
  51.             public void init(GLAutoDrawable drawable) {
  52.                 GL2 gl = (GL2) drawable.getGL();
  53.  
  54.                 gl.glPointSize(POINT_SIZE);
  55.                 gl.glPointParameterfv(GL2.GL_POINT_DISTANCE_ATTENUATION,
  56.                         POINT_DISTANCE_ATTENUATION, 0);
  57.  
  58.                 gl.glGenBuffers(1, vbufferId, 0);
  59.                 gl.glBindBuffer(GL2.GL_ARRAY_BUFFER, vbufferId[0]);
  60.                 FloatBuffer floatBuffer = Buffers
  61.                         .newDirectFloatBuffer(VERTEX_BUFFER_SIZE);
  62.  
  63.                 Random random = new Random();
  64.  
  65.                 for (int i = 0; i < NUMBER_OF_VERTICES; i++) {
  66.                     floatBuffer.put((random.nextFloat() * 8) - 4);
  67.                     floatBuffer.put((random.nextFloat() * 8) - 4);
  68.                     floatBuffer.put(0.0f);
  69.                 }
  70.  
  71.                 floatBuffer.rewind();
  72.                 gl.glBufferData(GL2.GL_ARRAY_BUFFER, VERTEX_BUFFER_SIZE
  73.                         * Buffers.SIZEOF_FLOAT, floatBuffer, GL2.GL_STATIC_DRAW);
  74.  
  75.                 gl.glBindBuffer(GL2.GL_ARRAY_BUFFER, 0);
  76.             }
  77.  
  78.             @Override
  79.             public void dispose(GLAutoDrawable drawable) {
  80.  
  81.             }
  82.  
  83.             @Override
  84.             public void display(GLAutoDrawable drawable) {
  85.                 final GL2 gl = (GL2) drawable.getGL();
  86.  
  87.                 gl.glClear(GL2.GL_COLOR_BUFFER_BIT | GL2.GL_DEPTH_BUFFER_BIT);
  88.                 gl.glLoadIdentity();
  89.  
  90.                 glu.gluLookAt(0, 0, 10, 0, 0, 0, 0, 1, 0);
  91.  
  92.                 gl.glColor4f(1.0f, 0f, 0f, 1.0f);
  93.  
  94.                 gl.glBindBuffer(GL2.GL_ARRAY_BUFFER, vbufferId[0]);
  95.  
  96.                 gl.glEnableVertexAttribArray(0);
  97.                 gl.glVertexAttribPointer(0, 3, GL2.GL_FLOAT, false, 0, 0);
  98.                 gl.glDrawArrays(GL2.GL_POINTS, 0, NUMBER_OF_VERTICES);
  99.                 gl.glDisableVertexAttribArray(0);
  100.  
  101.                 gl.glBindBuffer(GL2.GL_ARRAY_BUFFER, 0);
  102.             }
  103.         });
  104.  
  105.         animator = new Animator(window);
  106.         animator.start();
  107.         window.setSize(800, 800);
  108.  
  109.         window.setVisible(true);
  110.     }
  111. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement