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

项目:gl3DGE    文件:LightingDemo.java   
public void init(){
    WIDTH = 1920;
    HEIGHT = 1080;

    Window.setErrorCallback(GLFWErrorCallback.createPrint(System.err));
    w = new Window(WIDTH, HEIGHT, "gl3DGE", true, 4, 0);
    w.setKeyCallback(new GLFWKeyCallback(){

        @Override
        public void invoke(long window, int key, int scancode, int action, int mods) {
            // TODO Auto-generated method stub
            if (key == GLFW_KEY_ESCAPE && action == GLFW_RELEASE)
                glfwSetWindowShouldClose(window, true);
        }

    });

    w.setCursorPos((double) WIDTH / 2, (double) HEIGHT / 2);

    AudioEngine.initAudioEngine();

    Resource.setGameObjectDir("/mesh/");
    Resource.setOBJDir("/obj/");
    Resource.setTexDir("/tex/");
    Resource.setShaderDir("/shaders/");
}
项目:RGGE-Engine    文件:InputManager.java   
public void setupKeyboardCallbacks()
{
    // Create a callback in GLFW
    glfwSetKeyCallback(Engine.getEngine().getDisplay().getWindowHandler(), keyCallback = new GLFWKeyCallback() {
           @Override
           public void invoke(long window, int key, int scancode, int action, int mods) {

            //Dispatch an event
            EventManager.getEventManager().dispatch(new KeyEvent(new Key(key, action)));

            // Hardcode the debug key
               if ( key == GLFW_KEY_F8 && action == GLFW_RELEASE && !Engine.getEngine().getPerformanceThread().isAlive() && !Engine.getEngine().getPerformanceMonitor().shouldStop)
                Engine.getEngine().getPerformanceThread().start();
           }
       });
}
项目:gl3DGE    文件:LightingDemo.java   
public void init(){
    WIDTH = 1920;
    HEIGHT = 1080;

    Window.setErrorCallback(GLFWErrorCallback.createPrint(System.err));
    w = new Window(WIDTH, HEIGHT, "gl3DGE", true, 4, 0);
    w.setKeyCallback(new GLFWKeyCallback(){

        @Override
        public void invoke(long window, int key, int scancode, int action, int mods) {
            // TODO Auto-generated method stub
            if (key == GLFW_KEY_ESCAPE && action == GLFW_RELEASE)
                glfwSetWindowShouldClose(window, true);
        }

    });

    w.setCursorPos((double) WIDTH / 2, (double) HEIGHT / 2);

    AudioEngine.initAudioEngine();

    Resource.setGameObjectDir("/mesh/");
    Resource.setOBJDir("/obj/");
    Resource.setTexDir("/tex/");
    Resource.setShaderDir("/shaders/");
}
项目:open-world    文件:Window.java   
/**
    * Sets the key callback for the window
    * @param callback The callback that will receive keyboard input
    */
   public void setKeyCallback(GLFWKeyCallback callback) throws IllegalStateException {
if(handle == 0) {
    throw new IllegalStateException("handle is NULL");
}

GLFW.glfwSetKeyCallback(handle, callback);
   }
项目:key-barricade    文件:KeyInputManager.java   
/**
 * Initialize.
 */
public void init() {
    // Create and set up the key callback
    this.keyCallback = new GLFWKeyCallback() {
        @Override
        public void invoke(long window, int key, int scanCode, int action, int mods) {
            // Set whether the key is pressed
            keysDown[key] = (keysDownOnce[key] = action == GLFW.GLFW_PRESS) || action == GLFW.GLFW_REPEAT;
        }
    };

    // Register the key callback for the given window.
    GLFW.glfwSetKeyCallback(window.getWindowId(), keyCallback);
}
项目:voxeltex-engine    文件:KeyInputManager.java   
/**
 * Initialize.
 */
public void init() {
    // Create and set up the key callback
    this.keyCallback = new GLFWKeyCallback() {
        @Override
        public void invoke(long window, int key, int scanCode, int action, int mods) {
            // Set whether the key is pressed
            keysDown[key] = (keysDownOnce[key] = action == GLFW.GLFW_PRESS) || action == GLFW.GLFW_REPEAT;
        }
    };

    // Register the key callback for the given window.
    GLFW.glfwSetKeyCallback(window.getWindowId(), keyCallback);
}
项目:Mass    文件:Screen.java   
/**
 * Initializes the Screen by settings its callbacks and applying options specified in the
 * ScreenOptions object for this Screen.
 */
public void init() {
    // Set resizeable to false.
    glfwWindowHint(GLFW_RESIZABLE, GLFW_FALSE);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);

    if (this.screenOptions.getCompatibleProfile()) {
        glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_COMPAT_PROFILE);
    } else {
        glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
        glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
    }

    // Create the window
    id = glfwCreateWindow(width, height, title, NULL, NULL);
    if (id == NULL) {
        glfwTerminate();
        throw new RuntimeException("Failed to create GLFW window");
    }

    // Center window on the screen
    GLFWVidMode vidMode = glfwGetVideoMode(glfwGetPrimaryMonitor());
    glfwSetWindowPos(id, (vidMode.width() - width)/2, (vidMode.height() - height)/2);


    // Create OpenGL context
    glfwMakeContextCurrent(id);

    // Enable v-sync
    if (this.getVsync()) {
        glfwSwapInterval(1);
    }

    // Make the window visible
    glfwShowWindow(id);

    GL.createCapabilities();

    // Set key callback
    GLFWKeyCallback keyCallback = new GLFWKeyCallback() {
        @Override
        public void invoke(long window, int key, int scancode, int action, int mods) {
            if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS) {
                glfwSetWindowShouldClose(window, true);
            }
        }
    };
    glfwSetKeyCallback(id, keyCallback);

    // Setting the clear color.
    glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
    glEnable(GL_DEPTH_TEST);
    glEnable(GL_STENCIL_TEST);

    if (screenOptions.getShowTriangles()) {
        glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
    }

    // Enable OpenGL blending that gives support for transparencies.
    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

    if (screenOptions.getCullFace()) {
        glEnable(GL_CULL_FACE);
        glCullFace(GL_BACK);
    }

    // Antialiasing
    if (screenOptions.getAntialiasing()) {
        glfwWindowHint(GLFW_SAMPLES, 4);
    }
}
项目:gl3DGE    文件:Window.java   
public void setKeyCallback(GLFWKeyCallback kcb){
    glfwSetKeyCallback(id, keyCallback = kcb);
}
项目:OpenAargon    文件:InputManager.java   
public GLFWKeyCallback getKeyCallback() {
    return keyCb;
}
项目:gl3DGE    文件:Window.java   
public void setKeyCallback(GLFWKeyCallback kcb){
    glfwSetKeyCallback(id, keyCallback = kcb);
}
项目:lwjgl3-tutorial    文件:Window.java   
/**
 * Creates a GLFW window and its OpenGL context with the specified width,
 * height and title.
 *
 * @param width  Width of the drawing area
 * @param height Height of the drawing area
 * @param title  Title of the window
 * @param vsync  Set to true, if you want v-sync
 */
public Window(int width, int height, CharSequence title, boolean vsync) {
    this.vsync = vsync;

    /* Creating a temporary window for getting the available OpenGL version */
    glfwDefaultWindowHints();
    glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE);
    long temp = glfwCreateWindow(1, 1, "", NULL, NULL);
    glfwMakeContextCurrent(temp);
    GL.createCapabilities();
    GLCapabilities caps = GL.getCapabilities();
    glfwDestroyWindow(temp);

    /* Reset and set window hints */
    glfwDefaultWindowHints();
    if (caps.OpenGL32) {
        /* Hints for OpenGL 3.2 core profile */
        glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
        glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
        glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
        glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GLFW_TRUE);
    } else if (caps.OpenGL21) {
        /* Hints for legacy OpenGL 2.1 */
        glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 2);
        glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 1);
    } else {
        throw new RuntimeException("Neither OpenGL 3.2 nor OpenGL 2.1 is "
                                   + "supported, you may want to update your graphics driver.");
    }
    glfwWindowHint(GLFW_RESIZABLE, GLFW_FALSE);

    /* Create window with specified OpenGL context */
    id = glfwCreateWindow(width, height, title, NULL, NULL);
    if (id == NULL) {
        glfwTerminate();
        throw new RuntimeException("Failed to create the GLFW window!");
    }

    /* Center window on screen */
    GLFWVidMode vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor());
    glfwSetWindowPos(id,
                     (vidmode.width() - width) / 2,
                     (vidmode.height() - height) / 2
    );

    /* Create OpenGL context */
    glfwMakeContextCurrent(id);
    GL.createCapabilities();

    /* Enable v-sync */
    if (vsync) {
        glfwSwapInterval(1);
    }

    /* Set key callback */
    keyCallback = new GLFWKeyCallback() {
        @Override
        public void invoke(long window, int key, int scancode, int action, int mods) {
            if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS) {
                glfwSetWindowShouldClose(window, true);
            }
        }
    };
    glfwSetKeyCallback(id, keyCallback);
}
项目:JavaGraphicsEngine    文件:Window.java   
/**
 * Gets the GLFWWindow's Key Callback
 * 
 * @return Key Callback of the GLFW Instance
 */
public GLFWKeyCallback getKeyCallback() {
    return keyCallback;
}
项目:JavaGraphicsEngine    文件:Window.java   
/**
 * Sets the GLFWWindow's Key Callback
 * 
 * @param keyCallback       GLFWKeyCallback to be used by the GLFW Instance
 */
public void setKeyCallback(GLFWKeyCallback keyCallback) {
    this.keyCallback = keyCallback;
}