Hello jgo! Today i have been using lwjgl 3, and I have succesfully managed to create a glfw window! The window runs fine with no errors on Eclipse, but when I export it into runnable jar file and try opening it on my Desktop, i get the following error:
Caused by: java.lang.UnsatisfiedLinkError: Failed to load the native library: lwjgl
at org.lwjgl.LWJGLUtil.loadLibrarySystem(LWJGLUtil.java:329)
at org.lwjgl.Sys$1.run(Sys.java:36)
at java.security.AccessController.doPrivileged(Native Method)
at org.lwjgl.Sys.<clinit>(Sys.java:33)
at core.Display.<init>(Display.java:36)
at core.Main.main(Main.java:6)
... 5 more
Display.java:
public class Display {
/** The window handle */
private long wHandle;
// All event callbacks
GLFWErrorCallback errorCalls;
GLFWKeyCallback keyCalls;
GLFWCursorPosCallback cpCalls;
GLFWMouseButtonCallback mbCalls;
int width, height;
String title;
Game game;
public Display(int width, int height, String title, Game game) {
this.width = width;
this.height = height;
this.title = title;
this.game = game;
System.out.println("Hello Lwjgl " + Sys.getVersion());
try {
init();
loop();
// Dispose of game and resources
if(game != null)
game.dispose();
glfwDestroyWindow(wHandle);
// Release all callbacks
if(keyCalls != null)
keyCalls.release();
if(cpCalls != null)
cpCalls.release();
if(mbCalls != null)
mbCalls.release();
} finally {
glfwTerminate();
errorCalls.release();
}
}
private void init() {
glfwSetErrorCallback(errorCalls = errorCallbackPrint(System.err)); // This will print any lwjgl errors to System.err
if(glfwInit() != GL_TRUE) {
throw new IllegalStateException("GLFW cant init!");
}
// Config window
glfwDefaultWindowHints();
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_VISIBLE, GL_FALSE);
glfwWindowHint(GLFW_RESIZABLE, GL_FALSE);
/** Create window */
wHandle = glfwCreateWindow(width, height, title, NULL, NULL);
if(wHandle == NULL) {
throw new IllegalStateException("Unable to create window, check if have a Opengl version of 3.3 or higher.");
}
// Set up key callback
glfwSetKeyCallback(wHandle, keyCalls = new GLFWKeyCallback() {
@Override
public void invoke(long window, int key, int scancode, int action, int mods) {
if(key == GLFW_KEY_ESCAPE && action == GLFW_RELEASE)
glfwSetWindowShouldClose(wHandle, GL_TRUE);
}
});
// Get video mode of moniter
ByteBuffer vidMode = glfwGetVideoMode(glfwGetPrimaryMonitor());
// Center window
glfwSetWindowPos(wHandle, (GLFWvidmode.width(vidMode) - width) / 2,
(GLFWvidmode.height(vidMode) - height) / 2);
// Make the Opengl context current in thread
glfwMakeContextCurrent(wHandle);
// Enable v-sync
glfwSwapInterval(1);
// Finally ready to show window
glfwShowWindow(wHandle);
}
private void loop() {
// Allow us to use Opengl functions
GLContext.createFromCurrent();
// Enable blending and alpha transparency for sprites
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glViewport(0, 0, width, height); // Sets viewport
game.start();
// Game Loop
while(glfwWindowShouldClose(wHandle) == GL_FALSE) {
glClearColor(0, 0, 0, 1);
glClear(GL_COLOR_BUFFER_BIT);
game.render();
game.update();
glfwSwapBuffers(wHandle);
glfwPollEvents();
}
}
}
Main.java:
public class Main {
public static void main(String[] args) {
new Display(800, 600, "Lwjgl Test!", new Game());
}
}
Help!