Java 类org.lwjgl.glfw.GLFWWindowSizeCallback 实例源码

项目:Lime    文件:Window.java   
public static void setCallbacks()
{
    keyCallback = new Input.KeyCallback();
    charCallback = new Input.CharCallback();
    mouseCallback = new Input.MouseCallback();
    motionCallback = new Input.MotionCallback();
    resizeCallback = new GLFWWindowSizeCallback()
    {
        @Override
        public void invoke(long window, int width, int height)
        {
            if (!fullscreen)
            {
                size.x = width;
                size.y = height;
            }
        }
    };

    Lime.LOGGER.F("Setting callbacks");
    glfwSetKeyCallback(windowHandle, keyCallback);
    glfwSetCharCallback(windowHandle, charCallback);
    glfwSetMouseButtonCallback(windowHandle, mouseCallback);
    glfwSetCursorPosCallback(windowHandle, motionCallback);
    glfwSetWindowSizeCallback(windowHandle, resizeCallback);
    Lime.LOGGER.F("Callbacks set");
}
项目:Assimp-Tutorial-LWJGL-3    文件:Window.java   
public static void CreateWindow(int width, int height, String title)
{
    try 
    {
        if(!glfwInit()) throw new Exception("GLFW Initialization failed.");
        glfwSetErrorCallback(m_errorCallback = GLFWErrorCallback.createPrint(System.err));
        glfwDefaultWindowHints();
        glfwWindowHint(GLFW_VISIBLE, GL_FALSE);
        glfwWindowHint(GLFW_RESIZABLE, GL_FALSE);
        glfwWindowHint(GLFW_REFRESH_RATE , GLFW_DONT_CARE);
        glfwWindowHint(GLFW_DOUBLEBUFFER , GL_TRUE);
        Window.WIDTH = width;
        Window.HEIGHT = height;
        m_window = glfwCreateWindow(width, height, title, NULL, NULL);
        if(m_window == 0) throw new Exception("GLFW Window creation failed.");
        GLFWVidMode vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor());
        // Center our window
        glfwSetWindowPos(
            m_window,
            (vidmode.width() - WIDTH) / 2,
            (vidmode.height() - HEIGHT) / 2
        );

        Mouse = window.new Mouse();
        Mouse.Create(m_window);

        glfwSetWindowSizeCallback(m_window, m_resizeCallBack = new GLFWWindowSizeCallback()
        {
            @Override
            public void invoke(long arg0, int arg1, int arg2)
            {
                Window.WIDTH = arg1;
                Window.HEIGHT = arg2;
            }
        });
        glfwMakeContextCurrent(m_window);
        glfwSwapInterval(0);
        glfwShowWindow(m_window);
        GL.createCapabilities();
        int vao = GL30.glGenVertexArrays ();
        GL30.glBindVertexArray (vao);
    } 
    catch (Exception e) 
    {
        e.printStackTrace();
        System.exit(0);
    }
}
项目:Diorite-old    文件:Main.java   
private void init()
{
    // Setup an error callback. The default implementation
    // will print the error message in System.err.
    glfwSetErrorCallback(this.errorCallback = errorCallbackPrint(System.err));

    // Initialize GLFW. Most GLFW functions will not work before doing this.
    if (glfwInit() != GL11.GL_TRUE)
    {
        throw new IllegalStateException("Unable to initialize GLFW");
    }

    // Configure our window
    glfwDefaultWindowHints(); // optional, the current window hints are already the default
    glfwWindowHint(GLFW_VISIBLE, GL_FALSE); // the window will stay hidden after creation
    glfwWindowHint(GLFW_RESIZABLE, GL_TRUE); // the window will be resizable

    // Create the window
    this.window = glfwCreateWindow(this.width, this.height, "DioritOS", NULL, NULL);
    if (this.window == NULL)
    {
        throw new RuntimeException("Failed to create the GLFW window");
    }
    this.resizeCallback = GLFWWindowSizeCallback(this::handleResize);

    // Setup a key callback. It will be called every time a key is pressed, repeated or released.
    glfwSetKeyCallback(this.window, this.keyCallback = new MyGLFWResizeKeyCallback());

    // Get the resolution of the primary monitor
    final ByteBuffer vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor());
    // Center our window
    glfwSetWindowPos(this.window, (GLFWvidmode.width(vidmode) - this.width) / 2, (GLFWvidmode.height(vidmode) - this.height) / 2);

    // Make the OpenGL context current
    glfwMakeContextCurrent(this.window);
    // Enable v-sync
    glfwSwapInterval(1);

    // Make the window visible
    glfwShowWindow(this.window);

    glfwSetWindowSizeCallback(this.window, this.resizeCallback);
}
项目:OpenAargon    文件:GameWindow.java   
public void init() {
    ar = Aargon.getInstance();
    graphicsThread = ar.getThreadPool().submit(() -> {
        try {
            errorCb = GLFWErrorCallback.createPrint();
            GLFW.glfwSetErrorCallback(errorCb);

            if (GLFW.glfwInit() != GLFW.GLFW_TRUE)
                throw new IllegalStateException("Could not initialize GLFW!");

            GLFW.glfwDefaultWindowHints();
            GLFW.glfwWindowHint(GLFW.GLFW_VISIBLE, GLFW.GLFW_FALSE);
            GLFW.glfwWindowHint(GLFW.GLFW_RESIZABLE, GLFW.GLFW_FALSE);

            winId = GLFW.glfwCreateWindow(DEF_WIDTH, DEF_HEIGHT, "OpenAargon", MemoryUtil.NULL, MemoryUtil.NULL);
            if (winId == MemoryUtil.NULL)
                throw new IllegalStateException("Could not initialize window!");

            GLFW.glfwSetKeyCallback(winId, ar.getInputManager().getKeyCallback());
            GLFW.glfwSetMouseButtonCallback(winId, ar.getInputManager().getMouseCallback());
            GLFW.glfwSetCursorPosCallback(winId, ar.getInputManager().getCursorCallback());
            windowSizeCb = new GLFWWindowSizeCallback() {
                @Override
                public void invoke(long id, int w, int h) {
                    windowSize.setX(w).setY(h);
                    windowResized.set(true);
                }
            };
            GLFW.glfwSetWindowSizeCallback(winId, windowSizeCb);

            GLFWVidMode vidMode = GLFW.glfwGetVideoMode(GLFW.glfwGetPrimaryMonitor());
            GLFW.glfwSetWindowPos(winId, (vidMode.width() - DEF_WIDTH) / 2, (vidMode.height() - DEF_HEIGHT) / 2);

            GLFW.glfwMakeContextCurrent(winId);
            GLFW.glfwSwapInterval(1);

            GL.createCapabilities();

            vaoId = GL30.glGenVertexArrays();
            GL30.glBindVertexArray(vaoId);
            vboId = GL15.glGenBuffers();
            GL30.glBindVertexArray(0);

            initShaders();
            GL11.glClearColor(0F, 0F, 0F, 1F);
            GL11.glEnable(GL11.GL_BLEND);
            GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
            GL11.glEnable(GL11.GL_LINE_SMOOTH);
            GL11.glHint(GL11.GL_LINE_SMOOTH_HINT, GL11.GL_NICEST);

            GL11.glViewport(0, 0, windowSize.getX(), windowSize.getY());

            while (GLFW.glfwWindowShouldClose(winId) == GLFW.GLFW_FALSE) {
                if (windowResized.getAndSet(false))
                    GL11.glViewport(0, 0, windowSize.getX(), windowSize.getY());

                GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);

                ar.bufferRenders(WORLD_WIDTH, WORLD_HEIGHT, (float)windowSize.getX() / (float)windowSize.getY());

                render();
                GLFW.glfwSwapBuffers(winId);

                GLFW.glfwPollEvents();
            }
        } catch (Exception e) {
            Aargon.getLogger().error("Graphics thread errored!");
            e.printStackTrace();
        } finally {
            destruct();
            new Thread(Main::exitRequested, "Exit Thread").run();
        }
    });
}
项目:Mavkit    文件:Display.java   
@RequiresNonNull("this.mav")
@EnsuresNonNull("this.canvas")
@UIEffect
private void finishInitialization(boolean es) {
    GLFWErrorCallback ecb = GLFWErrorCallback.createPrint(System.err);
    mav.keepAlive(ecb);
    glfwSetErrorCallback(ecb);

    GLFWWindowSizeCallback scb = GLFWWindowSizeCallback.create(this::updateWindowSize);
    mav.keepAlive(scb);
    glfwSetWindowSizeCallback(window, scb);

    updateWindowSize(window, DEFAULT_WIDTH, DEFAULT_HEIGHT);

    String version = getGLVersion(es);
    int major = version.charAt(0)-'0';
    int minor = version.charAt(2)-'0';

    if (es) {
        if (major >= 3) {
            log.info("Using OpenGL ES 3 rendering");
            canvas = new NanoVGGLES3Canvas(mav);
        } else if (major >= 2) {
            log.info("Using OpenGL ES 2 rendering");
            canvas = new NanoVGGLES2Canvas(mav);
        } else {
            throw new Panic("panic.noSuitableContext", I18n.get("panic.noSuitableContext.onlyGlEs", version));
        }
    } else {
        if (major >= 3) {
            log.info("Using OpenGL 3 rendering");
            canvas = new NanoVGGL3Canvas(mav);
        } else if (major >= 2) {
            log.info("Using OpenGL 2 rendering");
            canvas = new NanoVGGL2Canvas(mav);
        } else {
            throw new Panic("panic.noSuitableContext", I18n.get("panic.noSuitableContext.onlyGl", version));
        }
    }

    glfwShowWindow(window);

    if (glfwExtensionSupported("WGL_EXT_swap_control_tear") || glfwExtensionSupported("GLX_EXT_swap_control_tear")) {
        log.info("Using tearing prevention");
        glfwSwapInterval(-1);
    } else {
        glfwSwapInterval(1);
    }
}
项目:JavaGraphicsEngine    文件:Window.java   
/**
 * Gets the GLFWWindow's Window Size Callback
 * 
 * @return Window Size Callback of the GLFW Instance
 */
public GLFWWindowSizeCallback getWindowSizeCallback() {
    return windowSizeCallback;
}
项目:JavaGraphicsEngine    文件:Window.java   
/**
 * Sets the GLFWWindow's Window Size Callback
 * 
 * @param windowSizeCallback    GLFWWindowSizeCallback to be used by the GLFW Instance
 */
public void setWindowSizeCallback(GLFWWindowSizeCallback windowSizeCallback) {
    this.windowSizeCallback = windowSizeCallback;
}