当前位置: 首页>>代码示例>>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;未经允许,请勿转载。