Search in sources :

Example 1 with MemoryStack

use of org.lwjgl.system.MemoryStack in project Glowstone by GlowstoneMC.

the class GlowClient method start.

public void start() {
    GLFWErrorCallback.createPrint(System.err).set();
    entity = new GlowClientEntity(server.getWorlds().get(0).getSpawnLocation(), new PlayerProfile("GlowClient", UUID.randomUUID()));
    if (!GLFW.glfwInit()) {
        throw new IllegalStateException("Unable to initialize GLFW");
    }
    GLFW.glfwWindowHint(GLFW.GLFW_RESIZABLE, GLFW.GLFW_TRUE);
    window = GLFW.glfwCreateWindow(1280, 720, "GlowClient", MemoryUtil.NULL, MemoryUtil.NULL);
    if (window == MemoryUtil.NULL) {
        throw new RuntimeException("Failed to create window");
    }
    GLFW.glfwSetKeyCallback(window, this::onInput);
    try (MemoryStack stack = MemoryStack.stackPush()) {
        IntBuffer pWidth = stack.mallocInt(1);
        IntBuffer pHeight = stack.mallocInt(1);
        GLFW.glfwGetWindowSize(window, pWidth, pHeight);
        GLFWVidMode vidmode = GLFW.glfwGetVideoMode(GLFW.glfwGetPrimaryMonitor());
        GLFW.glfwSetWindowPos(window, (vidmode.width() - pWidth.get(0)) / 2, (vidmode.height() - pHeight.get(0)) / 2);
    }
    GLFW.glfwMakeContextCurrent(window);
    GLFW.glfwSwapInterval(1);
}
Also used : PlayerProfile(net.glowstone.entity.meta.profile.PlayerProfile) MemoryStack(org.lwjgl.system.MemoryStack) IntBuffer(java.nio.IntBuffer) GLFWVidMode(org.lwjgl.glfw.GLFWVidMode)

Aggregations

IntBuffer (java.nio.IntBuffer)1 PlayerProfile (net.glowstone.entity.meta.profile.PlayerProfile)1 GLFWVidMode (org.lwjgl.glfw.GLFWVidMode)1 MemoryStack (org.lwjgl.system.MemoryStack)1