Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package de.kiel.pmain;
- import java.awt.EventQueue;
- import javax.swing.JFrame;
- import com.jogamp.common.util.VersionNumber;
- import com.jogamp.opengl.GLAutoDrawable;
- import com.jogamp.opengl.GLCapabilities;
- import com.jogamp.opengl.GLEventListener;
- import com.jogamp.opengl.GLProfile;
- import com.jogamp.opengl.awt.GLCanvas;
- public class TestGL {
- public static boolean isGLSLSupported(VersionNumber vn) {
- boolean[] container = new boolean[] {false};
- try {
- EventQueue.invokeAndWait(() -> {
- JFrame foo = new JFrame("open gl version test");
- GLCapabilities caps = new GLCapabilities(GLProfile.get(GLProfile.GL3));
- GLCanvas glCanvas = new GLCanvas(caps);
- glCanvas.addGLEventListener(new GLEventListener() {
- @Override
- public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {
- }
- @Override
- public void init(GLAutoDrawable drawable) {
- System.out.println("GL version is " + drawable.getContext().getGLVersion());
- VersionNumber glslVersionNumber = drawable.getContext().getGLSLVersionNumber();
- System.out.println("GLSL version number is "+glslVersionNumber);
- container[0] = glslVersionNumber.compareTo(vn) > -1;
- }
- @Override
- public void dispose(GLAutoDrawable drawable) {
- }
- @Override
- public void display(GLAutoDrawable drawable) {
- }
- });
- foo.add(glCanvas);
- foo.setUndecorated(true);
- foo.setSize(1, 1);
- foo.setVisible(true);
- foo.requestFocus();
- glCanvas.display();
- foo.setVisible(false);
- foo.dispose();
- });
- } catch (Exception ex) {
- System.out.println("Error trying to detect OpenGL version:");
- ex.printStackTrace();
- }
- return container[0];
- }
- private static boolean canRunOpenGL3() {
- GLProfile prof = GLProfile.getDefault();
- return prof.isGL3() && prof.hasGLSL();
- }
- private static boolean canRunOpenGL4() {
- GLProfile prof = GLProfile.getDefault();
- return prof.isGL4() && prof.hasGLSL();
- }
- public static void main(String[] args) {
- System.out.println("can run OpenGL 4: "+canRunOpenGL4());
- System.out.println("can run OpenGL 3: "+canRunOpenGL3());
- System.out.println("GLSL version check for 3.30 returns: "+isGLSLSupported(new VersionNumber(3, 30, 0)));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement