當前位置: 首頁>>代碼示例>>Java>>正文


Java GLFW類代碼示例

本文整理匯總了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);
		}
	}
}
 
開發者ID:tek256,項目名稱:LD38,代碼行數:29,代碼來源:Joystick.java

示例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);
   }
 
開發者ID:camilne,項目名稱:open-world,代碼行數:27,代碼來源:Main.java

示例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);
   }
 
開發者ID:camilne,項目名稱:open-world,代碼行數:20,代碼來源:Application.java

示例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));
}
 
開發者ID:tek256,項目名稱:LD38,代碼行數:31,代碼來源:Joystick.java

示例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());
	}
}
 
開發者ID:andykuo1,項目名稱:candlelight,代碼行數:21,代碼來源:View.java

示例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;
}
 
開發者ID:Guerra24,項目名稱:NanoUI,代碼行數:20,代碼來源:WindowHandle.java

示例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
}
 
開發者ID:andykuo1,項目名稱:candlelight,代碼行數:26,代碼來源:Window.java

示例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;
}
 
開發者ID:andykuo1,項目名稱:candlelight,代碼行數:22,代碼來源:GLEngine.java

示例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();
}
 
開發者ID:andykuo1,項目名稱:candlelight,代碼行數:24,代碼來源:ConsoleBase.java

示例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);
}
 
開發者ID:SmashMaster,項目名稱:KraftigAudio,代碼行數:17,代碼來源:Main.java

示例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();
}
 
開發者ID:SmashMaster,項目名稱:KraftigAudio,代碼行數:25,代碼來源:Player.java

示例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;
    }
}
 
開發者ID:RockBottomGame,項目名稱:API,代碼行數:15,代碼來源:ComponentSlot.java

示例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);
	}

}
 
開發者ID:MarcPopescu-Pfeiffer,項目名稱:2DGame,代碼行數:33,代碼來源:Player.java

示例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 + "");
					}
				}
			}
		}
	}

}
 
開發者ID:erikgoe,項目名稱:Cubeland,代碼行數:37,代碼來源:InputSystem.java

示例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);
}
   }
 
開發者ID:camilne,項目名稱:open-world,代碼行數:11,代碼來源:Input.java


注:本文中的org.lwjgl.glfw.GLFW類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。