Skip to content

Instantly share code, notes, and snippets.

@DennisSnijder
Last active October 20, 2023 23:56
Show Gist options
  • Save DennisSnijder/a1c40c45e89f677c6242 to your computer and use it in GitHub Desktop.
Save DennisSnijder/a1c40c45e89f677c6242 to your computer and use it in GitHub Desktop.
this might be helpful for people who are having problems with GL30 on osx
package abstraction;
import Util.OsCheck;
import org.lwjgl.opengl.APPLEVertexArrayObject;
import org.lwjgl.opengl.GL30;
public final class GL30Abstraction {
public static void glBindVertexArray( int array ) {
OsCheck.OSType ostype = OsCheck.getOperatingSystemType();
switch (ostype) {
case Windows:
case Linux:
case Other:
GL30.glBindVertexArray(array);
break;
case MacOS:
APPLEVertexArrayObject.glBindVertexArrayAPPLE(array);
break;
}
}
public static int glGenVertexArrays() {
OsCheck.OSType ostype = OsCheck.getOperatingSystemType();
switch (ostype) {
case Windows:
case Linux:
case Other:
return GL30.glGenVertexArrays();
case MacOS:
return APPLEVertexArrayObject.glGenVertexArraysAPPLE();
}
return 0;
}
public static void glDeleteVertexArrays(int array) {
OsCheck.OSType ostype = OsCheck.getOperatingSystemType();
switch (ostype) {
case Windows:
case Linux:
case Other:
GL30.glDeleteVertexArrays(array);
break;
case MacOS:
APPLEVertexArrayObject.glDeleteVertexArraysAPPLE(array);
break;
}
}
}
package Util;
import java.util.Locale;
public final class OsCheck {
/**
* types of Operating Systems
*/
public enum OSType {
Windows, MacOS, Linux, Other
};
// cached result of OS detection
protected static OSType detectedOS;
/**
* detect the operating system from the os.name System property and cache
* the result
*
* @returns - the operating system detected
*/
public static OSType getOperatingSystemType() {
if (detectedOS == null) {
String OS = System.getProperty("os.name", "generic").toLowerCase(Locale.ENGLISH);
if ((OS.indexOf("mac") >= 0) || (OS.indexOf("darwin") >= 0)) {
detectedOS = OSType.MacOS;
} else if (OS.indexOf("win") >= 0) {
detectedOS = OSType.Windows;
} else if (OS.indexOf("nux") >= 0) {
detectedOS = OSType.Linux;
} else {
detectedOS = OSType.Other;
}
}
return detectedOS;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment