本文整理匯總了Java中org.lwjgl.glfw.GLFW類的典型用法代碼示例。如果您正苦於以下問題:Java GLFW類的具體用法?Java GLFW怎麽用?Java GLFW使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
GLFW類屬於org.lwjgl.glfw包,在下文中一共展示了GLFW類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: setup
import org.lwjgl.glfw.GLFW; //導入依賴的package包/類
/**
* setup all connected joysticks
*/
public static void setup(){
int[] joys = new int[]{
GLFW.GLFW_JOYSTICK_1,
GLFW.GLFW_JOYSTICK_2,
GLFW.GLFW_JOYSTICK_3,
GLFW.GLFW_JOYSTICK_4,
GLFW.GLFW_JOYSTICK_5,
GLFW.GLFW_JOYSTICK_6,
GLFW.GLFW_JOYSTICK_7,
GLFW.GLFW_JOYSTICK_8,
GLFW.GLFW_JOYSTICK_9,
GLFW.GLFW_JOYSTICK_10,
GLFW.GLFW_JOYSTICK_11,
GLFW.GLFW_JOYSTICK_12,
GLFW.GLFW_JOYSTICK_13,
GLFW.GLFW_JOYSTICK_14,
GLFW.GLFW_JOYSTICK_15,
GLFW.GLFW_JOYSTICK_16,
};
for(int joy : joys){
if(GLFW.glfwJoystickPresent(joy)){
setupJoystick(joy);
}
}
}
示例2: update
import org.lwjgl.glfw.GLFW; //導入依賴的package包/類
@Override
public void update(float delta) {
final float speedThisFrame = speed * delta;
// Move forward
if (Input.isKeyPressed(GLFW.GLFW_KEY_W))
camera.move(Camera.Direction.FORWARD, speedThisFrame);
// Move backward
if (Input.isKeyPressed(GLFW.GLFW_KEY_S))
camera.move(Camera.Direction.BACKWARD, speedThisFrame);
// Move right
if (Input.isKeyPressed(GLFW.GLFW_KEY_D))
camera.move(Camera.Direction.RIGHT, speedThisFrame);
// Move left
if (Input.isKeyPressed(GLFW.GLFW_KEY_A))
camera.move(Camera.Direction.LEFT, speedThisFrame);
// Move up
if (Input.isKeyPressed(GLFW.GLFW_KEY_SPACE))
camera.move(Camera.AXIS_Y, speedThisFrame);
// Move down
if (Input.isKeyPressed(GLFW.GLFW_KEY_LEFT_SHIFT))
camera.move(Camera.AXIS_Y, -speedThisFrame);
camera.update();
world.update(camera, delta);
}
示例3: createWindow
import org.lwjgl.glfw.GLFW; //導入依賴的package包/類
/**
* Creates a GLFWWindow and gives it OpenGL context
*/
private void createWindow() {
// Hide the window during application initialization
Window.hint(GLFW.GLFW_VISIBLE, GL11.GL_FALSE);
// Setup MSAA 4x
Window.hint(GLFW.GLFW_SAMPLES, 4);
WINDOW.create(config.width, config.height, config.title);
// Make this thread and window the current context for OpenGL
WINDOW.makeContextCurrent();
GLContext.createFromCurrent();
// Set other specified window configurations
WINDOW.setVSyncEnabled(config.vSyncEnabled);
WINDOW.setPosition(config.position);
}
示例4: setupJoystick
import org.lwjgl.glfw.GLFW; //導入依賴的package包/類
/** Setup a specific joystick that is connected
*
* @param joy the joystick id to setup
*/
public static void setupJoystick(int joy){
//make sure the joystick is connected
if(!GLFW.glfwJoystickPresent(joy))
return;
//get the name of the joystick and normalize the casing
String name = GLFW.glfwGetJoystickName(joy).toLowerCase();
JoystickType type = JoystickType.OTHER;
//check the name for the type
if(name.contains("xbox"))
type = JoystickType.XBOX360;
else if(name.contains("playstation"))
type = JoystickType.PLAYSTATION;
//setup the axis size for the controller
FloatBuffer buf = GLFW.glfwGetJoystickAxes(joy);
int axisCount = buf.capacity();
//setup the button size for the controller
ByteBuffer bbuf = GLFW.glfwGetJoystickButtons(joy);
int buttonCount = bbuf.capacity();
//add the controller to the static array for usage
connected.add(new Joystick(joy, type, axisCount, buttonCount));
}
示例5: updateViewPort
import org.lwjgl.glfw.GLFW; //導入依賴的package包/類
private void updateViewPort(ViewPort viewport)
{
if (viewport == this.defaultViewPort)
{
//FIXME: This is a fix (hack?) for Mac's weird hack to scale windows for compatibility
try (MemoryStack stack = MemoryStack.stackPush())
{
IntBuffer pWidth = stack.mallocInt(1);
IntBuffer pHeight = stack.mallocInt(1);
GLFW.glfwGetFramebufferSize(this.window.handle(), pWidth, pHeight);
GL11.glViewport(0, 0, pWidth.get(0), pHeight.get(0));
}
}
else
{
GL11.glViewport(viewport.getX(), viewport.getY(),
viewport.getWidth(), viewport.getHeight());
}
}
示例6: setPixelBuffer
import org.lwjgl.glfw.GLFW; //導入依賴的package包/類
public WindowHandle setPixelBuffer(PixelBufferHandle pbh) {
this.setWindowHint(GLFW.GLFW_RED_BITS, pbh.getRedBits());
this.setWindowHint(GLFW.GLFW_ACCUM_RED_BITS, pbh.getRedBitsAccum());
this.setWindowHint(GLFW.GLFW_GREEN_BITS, pbh.getGreenBits());
this.setWindowHint(GLFW.GLFW_ACCUM_GREEN_BITS, pbh.getGreenBitsAccum());
this.setWindowHint(GLFW.GLFW_BLUE_BITS, pbh.getBlueBits());
this.setWindowHint(GLFW.GLFW_ACCUM_BLUE_BITS, pbh.getBlueBitsAccum());
this.setWindowHint(GLFW.GLFW_ALPHA_BITS, pbh.getAlphaBits());
this.setWindowHint(GLFW.GLFW_ACCUM_ALPHA_BITS, pbh.getAlphaBitsAccum());
this.setWindowHint(GLFW.GLFW_DEPTH_BITS, pbh.getDepthBits());
this.setWindowHint(GLFW.GLFW_STENCIL_BITS, pbh.getStencilBits());
this.setWindowHint(GLFW.GLFW_AUX_BUFFERS, pbh.getAuxBuffers());
this.setWindowHint(GLFW.GLFW_SAMPLES, pbh.getSamples());
this.setWindowHint(GLFW.GLFW_REFRESH_RATE, pbh.getRefreshRate());
this.setWindowHint(GLFW.GLFW_STEREO, pbh.getStereo());
this.setWindowHint(GLFW.GLFW_SRGB_CAPABLE, pbh.getSRGBCapable());
this.setWindowHint(GLFW.GLFW_DOUBLEBUFFER, pbh.getDoubleBuffer());
return this;
}
示例7: makeWindowCentered
import org.lwjgl.glfw.GLFW; //導入依賴的package包/類
public void makeWindowCentered()
{
// Get the thread stack and push a new frame
try (MemoryStack stack = MemoryStack.stackPush())
{
IntBuffer pWidth = stack.mallocInt(1); // int*
IntBuffer pHeight = stack.mallocInt(1); // int*
// Get the window size passed to glfwCreateWindow
GLFW.glfwGetWindowSize(this.handle, pWidth, pHeight);
this.width = pWidth.get(0);
this.height = pHeight.get(0);
// Get the resolution of the primary monitor
GLFWVidMode vidmode = getCurrentVideoMode();
// Center the window
GLFW.glfwSetWindowPos(
this.handle,
this.x = ((vidmode.width() - this.width) / 2),
this.y = ((vidmode.height() - this.height) / 2)
);
} // the stack frame is popped automatically
}
示例8: initialize
import org.lwjgl.glfw.GLFW; //導入依賴的package包/類
@Override
public boolean initialize()
{
System.out.println("OS " + System.getProperty("os.name"));
System.out.println("JAVA " + System.getProperty("java.version"));
System.out.println("LWJGL " + Version.getVersion());
System.out.println("GLFW " + GLFW.glfwGetVersionString());
System.out.println("JOML 1.9.2");
// Setup an error callback. The default implementation
// will print the error message in System.err.
GLFWErrorCallback.createPrint(System.err).set();
// Initialize GLFW. Most GLFW functions will not work before doing this.
if (!GLFW.glfwInit())
{
throw new IllegalStateException("Unable to initialize GLFW");
}
return true;
}
示例9: ConsoleBase
import org.lwjgl.glfw.GLFW; //導入依賴的package包/類
public ConsoleBase(Console console, Transform transform, Asset<TextureAtlas> textureAtlas, int width, int height)
{
this.console = console;
this.transform = transform;
this.view = new RasterizedView(width, height).setTextureAtlas(textureAtlas);
this.background = new RasterizedView(width, height).setTextureAtlas(textureAtlas);
this.backgroundOffset = new Matrix4f().translate(0.0625F, -0.0625F, 0);
this.view.forEach((vector2ic, character, integer) ->
this.view.draw(vector2ic.x(), vector2ic.y(), 'A', 0xFFFFFF));
this.background.forEach((vector2ic, character, integer) ->
this.background.draw(vector2ic.x(), vector2ic.y(), 'A', 0x888888));
//this.view.clear((byte) 0, 0xFFFFFF);
//this.background.clear((byte) 0, 0x888888);
Console.getConsole().getInputEngine().getDefaultContext()
.registerEvent("newline",
Console.getConsole().getInputEngine().getKeyboard().getButton(GLFW.GLFW_KEY_ENTER)::getAction);
this.textHandler = Console.getConsole().getInputEngine().getText();
this.initialize();
}
示例10: onKey
import org.lwjgl.glfw.GLFW; //導入依賴的package包/類
@Override
public void onKey(int key, int action, int mods)
{
if (action == GLFW.GLFW_PRESS && key == GLFW.GLFW_KEY_TAB && menu == null)
{
displayMouse = !displayMouse;
boolean display = displayMouse();
mouse.setGrabbed(!display);
if (!display) mouse.setPosDirty();
Vec2i res = getResolution();
mouse.setPos(res.x/2.0f, res.y/2.0f);
}
interactionState.onKey(key, action, mods);
}
示例11: step
import org.lwjgl.glfw.GLFW; //導入依賴的package包/類
void step(float dt)
{
float yaw = cameraController.getYaw();
float cosYaw = (float)Math.cos(yaw);
float sinYaw = (float)Math.sin(yaw);
Vec3 groundFwd = new Vec3(-sinYaw, 0.0f, -cosYaw);
Vec3 groundRight = new Vec3(cosYaw, 0.0f, -sinYaw);
Vec3 desiredVel = new Vec3();
if (keyboard.isKeyDown(GLFW.GLFW_KEY_W)) desiredVel.add(groundFwd);
if (keyboard.isKeyDown(GLFW.GLFW_KEY_S)) desiredVel.sub(groundFwd);
if (keyboard.isKeyDown(GLFW.GLFW_KEY_D)) desiredVel.add(groundRight);
if (keyboard.isKeyDown(GLFW.GLFW_KEY_A)) desiredVel.sub(groundRight);
boolean sprinting = keyboard.isKeyDown(GLFW.GLFW_KEY_LEFT_SHIFT);
float speed = sprinting ? SPEED_SPRINT : SPEED;
if (!desiredVel.isZero(0.0f)) desiredVel.normalize().mult(speed);
vel.move(desiredVel, dt*ACC);
pos.madd(vel, dt);
cameraController.update();
}
示例12: onMouseAction
import org.lwjgl.glfw.GLFW; //導入依賴的package包/類
@Override
public boolean onMouseAction(IGameInstance game, int button, float x, float y){
if(this.isMouseOver(game)){
if(game.getInput().isKeyDown(GLFW.GLFW_KEY_LEFT_SHIFT)){
return RockBottomAPI.getInternalHooks().doDefaultShiftClicking(game, this.container, this);
}
else{
return RockBottomAPI.getInternalHooks().doDefaultSlotMovement(game, button, x, y, this);
}
}
else{
return false;
}
}
示例13: update
import org.lwjgl.glfw.GLFW; //導入依賴的package包/類
@Override
public void update(float delta, Window window, Camera camera, World world) {
Vector2f movement = new Vector2f();
if (window.getInput().isKeyDown(GLFW.GLFW_KEY_A)){
movement.add(-10 * delta, 0);
}
if (window.getInput().isKeyDown(GLFW.GLFW_KEY_D)){
movement.add(10 * delta, 0);
}
if (window.getInput().isKeyDown(GLFW.GLFW_KEY_W)){
movement.add(0, 10 * delta * JUMP_STRENGTH);
}
movement.add(0, -10 * delta * GRAVITATION);
move(movement);
if(movement.y > 0){
useAnimation(ANIM_JETPACK);
}else if (movement.x != 0){
useAnimation(ANIM_WALK);
}else{
useAnimation(ANIM_IDLE);
}
camera.getPosition().lerp(transform.pos.mul(-world.getScale(), new Vector3f()), 0.2f);
if (window.getInput().isKeyDown(GLFW.GLFW_KEY_SPACE)){
Rocket rocket = new Rocket(1, transform);
}
}
示例14: handleEvents
import org.lwjgl.glfw.GLFW; //導入依賴的package包/類
@Override
public void handleEvents(List<Event> events) {
for (Event e : events) {
if (e.type == Event.Type.KEY_INPUT) {
KeyInputEvent evt = (KeyInputEvent) e;
if (evt.action == GLFW.GLFW_PRESS) {
if (evt.mods == GLFW.GLFW_MOD_CONTROL && evt.key == GLFW.GLFW_KEY_ENTER) { // command
// mode
java.lang.System.out.print("Enter your command: ");
String commandLine = consoleScanner.nextLine();
String command = commandLine;
if (commandLine.indexOf(' ') != -1)
commandLine.substring(0, commandLine.indexOf(' '));
if (command.equals("load")) {
game.createEvent(new LoadSceneEvent("default"));// TODO
// change
// default
// to
// last
// (or
// sth).
} else if (command.equals("save")) {
game.createEvent(new Event(Event.Type.SAVE));
} else if (command.equals("exit")) {
game.createEvent(new Event(Event.Type.EXIT));
} else {// unknown command
Logger.warn("Unknown command " + command + "");
}
}
}
}
}
}
示例15: invoke
import org.lwjgl.glfw.GLFW; //導入依賴的package包/類
@Override
public void invoke(long window, int keycode, int scancode, int action, int mods) {
// If the key was pressed
if(action == GLFW.GLFW_PRESS) {
keyPressed(keycode);
// If the key was released
} else if (action == GLFW.GLFW_RELEASE){
keyReleased(keycode);
}
}