本文整理汇总了Java中org.lwjgl.glfw.GLFWKeyCallback类的典型用法代码示例。如果您正苦于以下问题:Java GLFWKeyCallback类的具体用法?Java GLFWKeyCallback怎么用?Java GLFWKeyCallback使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
GLFWKeyCallback类属于org.lwjgl.glfw包,在下文中一共展示了GLFWKeyCallback类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: init
import org.lwjgl.glfw.GLFWKeyCallback; //导入依赖的package包/类
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/");
}
示例2: setupKeyboardCallbacks
import org.lwjgl.glfw.GLFWKeyCallback; //导入依赖的package包/类
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();
}
});
}
示例3: setKeyCallback
import org.lwjgl.glfw.GLFWKeyCallback; //导入依赖的package包/类
/**
* 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);
}
示例4: init
import org.lwjgl.glfw.GLFWKeyCallback; //导入依赖的package包/类
/**
* 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);
}
示例5: init
import org.lwjgl.glfw.GLFWKeyCallback; //导入依赖的package包/类
/**
* 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);
}
}
示例6: setKeyCallback
import org.lwjgl.glfw.GLFWKeyCallback; //导入依赖的package包/类
public void setKeyCallback(GLFWKeyCallback kcb){
glfwSetKeyCallback(id, keyCallback = kcb);
}
示例7: getKeyCallback
import org.lwjgl.glfw.GLFWKeyCallback; //导入依赖的package包/类
public GLFWKeyCallback getKeyCallback() {
return keyCb;
}
示例8: Window
import org.lwjgl.glfw.GLFWKeyCallback; //导入依赖的package包/类
/**
* 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);
}
示例9: getKeyCallback
import org.lwjgl.glfw.GLFWKeyCallback; //导入依赖的package包/类
/**
* Gets the GLFWWindow's Key Callback
*
* @return Key Callback of the GLFW Instance
*/
public GLFWKeyCallback getKeyCallback() {
return keyCallback;
}
示例10: setKeyCallback
import org.lwjgl.glfw.GLFWKeyCallback; //导入依赖的package包/类
/**
* Sets the GLFWWindow's Key Callback
*
* @param keyCallback GLFWKeyCallback to be used by the GLFW Instance
*/
public void setKeyCallback(GLFWKeyCallback keyCallback) {
this.keyCallback = keyCallback;
}