loadLibrary function
Implementation
DynamicLibrary loadLibrary() {
DynamicLibrary library;
String name;
if (Platform.isWindows) {
name = 'Opengl32.dll';
} else if (Platform.isLinux) {
name = 'libGL.so.1';
} else if (Platform.isMacOS) {
name =
'/System/Library/Frameworks/OpenGL.framework/Versions/Current/OpenGL';
} else {
throw UnsupportedError('unsupported platform ${Platform.operatingSystem}');
}
try {
library = DynamicLibrary.open(name);
} catch (ex) {
throw Exception('failed to load OpenGL library $name');
}
String? glGetProcAddressName;
if (Platform.isWindows) {
glGetProcAddressName = 'wglGetProcAddress';
} else if (Platform.isLinux) {
glGetProcAddressName = 'glXGetProcAddress';
}
try {
if (glGetProcAddressName != null) {
final func = library.lookup(glGetProcAddressName);
_glGetProcAddress =
Pointer<NativeFunction<GlGetProcAddressNative>>.fromAddress(
func.address)
.asFunction<GlGetProcAddress>();
}
} catch (ex) {
throw Exception('failed to loookup $glGetProcAddressName function');
}
return library;
}