Advertisement
Guest User

Untitled

a guest
Jun 17th, 2015
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.30 KB | None | 0 0
  1. package de.kiel.pmain;
  2.  
  3. import java.awt.EventQueue;
  4.  
  5. import javax.swing.JFrame;
  6.  
  7. import com.jogamp.common.util.VersionNumber;
  8. import com.jogamp.opengl.GLAutoDrawable;
  9. import com.jogamp.opengl.GLCapabilities;
  10. import com.jogamp.opengl.GLEventListener;
  11. import com.jogamp.opengl.GLProfile;
  12. import com.jogamp.opengl.awt.GLCanvas;
  13.  
  14. public class TestGL {
  15.     public static boolean isGLSLSupported(VersionNumber vn) {
  16.        
  17.         boolean[] container = new boolean[] {false};
  18.         try {
  19.             EventQueue.invokeAndWait(() -> {
  20.                 JFrame foo = new JFrame("open gl version test");
  21.                 GLCapabilities caps = new GLCapabilities(GLProfile.get(GLProfile.GL3));
  22.                 GLCanvas glCanvas = new GLCanvas(caps);
  23.                 glCanvas.addGLEventListener(new GLEventListener() {
  24.                     @Override
  25.                     public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {
  26.                     }
  27.                    
  28.                     @Override
  29.                     public void init(GLAutoDrawable drawable) {
  30.                         System.out.println("GL version is " + drawable.getContext().getGLVersion());
  31.                         VersionNumber glslVersionNumber = drawable.getContext().getGLSLVersionNumber();
  32.                         System.out.println("GLSL version number is "+glslVersionNumber);
  33.                         container[0] = glslVersionNumber.compareTo(vn) > -1;
  34.                     }
  35.                    
  36.                     @Override
  37.                     public void dispose(GLAutoDrawable drawable) {
  38.                     }
  39.                    
  40.                     @Override
  41.                     public void display(GLAutoDrawable drawable) {
  42.                     }
  43.                 });
  44.                 foo.add(glCanvas);
  45.                 foo.setUndecorated(true);
  46.                 foo.setSize(1, 1);
  47.                 foo.setVisible(true);
  48.                 foo.requestFocus();
  49.                 glCanvas.display();
  50.                 foo.setVisible(false);
  51.                 foo.dispose();
  52.             });
  53.         } catch (Exception ex) {
  54.             System.out.println("Error trying to detect OpenGL version:");
  55.             ex.printStackTrace();
  56.         }
  57.        
  58.         return container[0];
  59.     }
  60.    
  61.     private static boolean canRunOpenGL3() {
  62.         GLProfile prof = GLProfile.getDefault();
  63.         return prof.isGL3() && prof.hasGLSL();
  64.     }
  65.    
  66.     private static boolean canRunOpenGL4() {
  67.         GLProfile prof = GLProfile.getDefault();
  68.         return prof.isGL4() && prof.hasGLSL();
  69.     }
  70.    
  71.     public static void main(String[] args) {
  72.         System.out.println("can run OpenGL 4: "+canRunOpenGL4());
  73.         System.out.println("can run OpenGL 3: "+canRunOpenGL3());
  74.         System.out.println("GLSL version check for 3.30 returns: "+isGLSLSupported(new VersionNumber(3, 30, 0)));
  75.     }
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement