public void createWindow(String title) { window = glfwCreateWindow( width, height, title, fullscreen ? glfwGetPrimaryMonitor() : 0, 0); if (window == 0) { throw new IllegalStateException("GLFW failed to create window!"); } if (!fullscreen) { GLFWVidMode vid = glfwGetVideoMode(glfwGetPrimaryMonitor()); glfwSetWindowPos(window, (vid.width() - width) / 2, (vid.height() - height) / 2); glfwShowWindow(window); } glfwMakeContextCurrent(window); input = new Input(window); }
private void start(){ if(!glfwInit()){ throw new IllegalStateException("Not enable GLFW Init"); } glfwDefaultWindowHints(); glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE); glfwWindowHint(GLFW_RESIZABLE, GLFW_TRUE); window = glfwCreateWindow(Width, Height, "Light! Weight! Test!", NULL, NULL); if(window == NULL){ throw new RuntimeException("ウィンドウの生成に失敗しました"); } glfwSetWindowAspectRatio(window,1,1); GLFWVidMode vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor()); glfwSetWindowPos(window, (vidmode.width()-Width)/ 2, (vidmode.height()-Height)/ 2); glfwMakeContextCurrent(window); glfwSwapInterval(1); glfwShowWindow(window); }
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 }
Display(long id) { this.id = id; GLFWVidMode.Buffer modes = glfwGetVideoModes(id); displayModes = new HashSet<>(); for(int i = 0; i < modes.limit(); i++) { GLFWVidMode vm = modes.get(); DisplayMode wm = new DisplayMode( this, vm.width(), vm.height(), vm.redBits(), vm.refreshRate()); displayModes.add(wm); } }
/** * <p> * Get the native window mode of the display. * </p> * * @return The native window mode. */ public final DisplayMode getNativeDisplayMode() { GLFWVidMode nvm = glfwGetVideoMode(id); for(DisplayMode mode : displayModes) { if(mode.getWidth() == nvm.width() && mode.getHeight() == nvm.height() && mode.getBitsPerPixel() == nvm.redBits() && mode.getFrequency() == nvm.refreshRate()) { return mode; } } return null; }
/** * Create a new application * @param width The width * @param height The height * @param fullscreen Wether the window should be fullscreen * @param title The title * @throws InitializationException If the application fails to initialize */ public Application(int width, int height, boolean fullscreen, String title) throws InitializationException { Logs.setApplication(this); GLFWVidMode displayMode = null; if (fullscreen) { displayMode = Window.getBestFullscreenVideoMode(Window.getFullscreenVideoModes(GLFW.glfwGetPrimaryMonitor())); } window = new Window(title, width, height, fullscreen, displayMode, GLFW.glfwGetPrimaryMonitor()); GLFW.glfwShowWindow(window.getWindow()); window.setVsync(false); loader = new Loader(this); renderer = new MasterRenderer(); renderer.viewport(0, 0, window.getWidth(), window.getHeight()); renderer.init(); Quad.setup(loader); }
public float getDensity () { intBuffer.clear(); intBuffer2.clear(); glfwGetMonitorPhysicalSize(getWindowMonitor(), intBuffer, intBuffer2); float mmWidth = intBuffer.get(); float mmHeight = intBuffer2.get(); float inches = (float) Math.sqrt(mmWidth * mmWidth + mmHeight * mmHeight) * 0.03937f; // mm to inches final GLFWVidMode vidMode = glfwGetVideoMode(getWindowMonitor()); float pixelWidth = vidMode.width(); float pixelHeight = vidMode.height(); float pixels = (float) Math.sqrt(pixelWidth * pixelWidth + pixelHeight * pixelHeight); float diagonalPpi = pixels / inches; return diagonalPpi / 160f; }
@Override public void setSize (int width, int height, boolean fullscreen) { if (plat.config.fullscreen != fullscreen) { plat.log().warn("fullscreen cannot be changed via setSize, use config.fullscreen instead"); return; } GLFWVidMode vidMode = glfwGetVideoMode(glfwGetPrimaryMonitor()); if (width > vidMode.width()) { plat.log().debug("Capping window width at desktop width: " + width + " -> " + vidMode.width()); width = vidMode.width(); } if (height > vidMode.height()) { plat.log().debug("Capping window height at desktop height: " + height + " -> " + vidMode.height()); height = vidMode.height(); } glfwSetWindowSize(window, width, height); // plat.log().info("setSize: " + width + "x" + height); viewSizeM.setSize(width, height); IntBuffer fbSize = BufferUtils.createIntBuffer(2); long addr = MemoryUtil.memAddress(fbSize); nglfwGetFramebufferSize(window, addr, addr + 4); viewportAndScaleChanged(fbSize.get(0), fbSize.get(1)); }
public void initialize() throws LWJGLLibraryException { glfwDefaultWindowHints(); glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, OpenGL.CONTEXT_VERSION_MAJOR); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, OpenGL.CONTEXT_VERSION_MINOR); glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, (OpenGL.FORWARD_COMPATIBILITY ? GL_TRUE : GL_FALSE)); glfwWindowHint(GLFW_OPENGL_PROFILE, OpenGL.PROFILE); glfwWindowHint(GLFW_VISIBLE, GL_FALSE); glfwWindowHint(GLFW_RESIZABLE, (resizable ? GL_TRUE : GL_FALSE)); if (fullScreen) { windowID = glfwCreateWindow(width, height, title, glfwGetPrimaryMonitor(), NULL); } else { windowID = glfwCreateWindow(width, height, title, NULL, NULL); } if (windowID == NULL) throw new LWJGLLibraryException("Failed to create a GLFW window"); final ByteBuffer vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor()); glfwSetWindowPos(windowID, (GLFWvidmode.width(vidmode) - width) / 2, (GLFWvidmode.height(vidmode) - height) / 2); glfwMakeContextCurrent(windowID); glfwShowWindow(windowID); }
public boolean findRift() { PointerBuffer monitors = GLFW.glfwGetMonitors(); IntBuffer modeCount = BufferUtils.createIntBuffer(1); for (int i = 0; i < monitors.limit(); i++) { long monitorId = monitors.get(i); System.out.println("monitor: " + monitorId); ByteBuffer modes = GLFW.glfwGetVideoModes(monitorId, modeCount); System.out.println("mode count=" + modeCount.get(0)); for (int j = 0; j < modeCount.get(0); j++) { modes.position(j * GLFWvidmode.SIZEOF); int width = GLFWvidmode.width(modes); int height = GLFWvidmode.height(modes); // System.out.println(width + "," + height + "," + monitorId); if (width == riftWidth && height == riftHeight) { System.out.println("found dimensions match: " + width + "," + height + "," + monitorId); riftMonitorId = monitorId; if (i == RIFT_MONITOR) { return true; } } } System.out.println("-----------------"); } return (riftMonitorId != 0); }
/** * Create window and OpenGL context * @param title Window title * @param width Window width * @param height Window height * @param resizable Should the window be resizable * @param game CoreGame instance */ public static void init(String title, int width, int height, boolean resizable, CoreGame game) { if (!glfwInit()) { System.err.println("Could not initialize window system!"); System.exit(1); } if (!resizable) glfwWindowHint(GLFW_RESIZABLE, GL_FALSE); if (anti_alias) glfwWindowHint(GLFW_SAMPLES, 4); window = glfwCreateWindow(width, height, title, 0, 0); if (window == 0) { glfwTerminate(); System.err.println("Could not create window!"); System.exit(1); } glfwMakeContextCurrent(window); GL.createCapabilities(); GLFWVidMode vidMode = glfwGetVideoMode(window); glfwSetWindowPos(window, (vidMode.width() / 2) - (width / 2), (vidMode.height() / 2) - (height / 2)); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0, width, height, 0, -1, 1); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); if (anti_alias) glEnable(GL_MULTISAMPLE); Window.game = game; Window.render = new Render(); AudioPlayer.init(); start(); }
/** * Initializes the GLFW library, creating a window and any necessary shaders. */ void init(GameState gameState, Main client) { if (!glfwInit()) { System.err.println("Failed to initialise GLFW"); System.exit(1); } glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE); window = glfwCreateWindow(windowWidth, windowHeight, Constants.TITLE, 0, 0); if (window == 0) { System.err.println("Failed to create window."); System.exit(1); } GLFWVidMode videoMode = glfwGetVideoMode(glfwGetPrimaryMonitor()); int windowXPosition = (videoMode.width() - windowWidth) / 2; int windowYPosition = (videoMode.height() - windowHeight) / 2; glfwSetWindowPos(window, windowXPosition, windowYPosition); glfwShowWindow(window); glfwMakeContextCurrent(window); GL.createCapabilities(); cshader = new ShaderProgram("shaders/cshader.vs","shaders/shader.fs"); rshader = new ShaderProgram("shaders/rshader.vs","shaders/shader.fs"); pshader1 = new ShaderProgram("shaders/pshader.vs","shaders/shader.fs"); pshader2 = new ShaderProgram("shaders/pshader2.vs","shaders/shader.fs"); pshader3 = new ShaderProgram("shaders/pshader3.vs","shaders/shader.fs"); starshader = new ShaderProgram("shaders/starshader.vs","shaders/shader.fs"); registerInputCallbacks(gameState, client); }
public static void glfwSwapInterval(int interval, Void ret, MethodCall mc) { Context ctx = CURRENT_CONTEXT.get(); if (ctx != null && interval != 0) { // != 0 for EXT_swap_control_tear long monitor = org.lwjgl.glfw.GLFW.glfwGetWindowMonitor(ctx.window); if (monitor == 0L) { monitor = org.lwjgl.glfw.GLFW.glfwGetPrimaryMonitor(); } GLFWVidMode mode = org.lwjgl.glfw.GLFW.glfwGetVideoMode(monitor); int refreshRate = mode.refreshRate(); mc.comment(refreshRate / Math.abs(interval) + " Hz"); } mc.param(interval); }
private void createBackground() { Variables.X = 0; Variables.Y = 0; GLFWVidMode vidmode = GLFW.glfwGetVideoMode(GLFW.glfwGetPrimaryMonitor()); WindowHandle handle = WindowManager.generateHandle(vidmode.width(), vidmode.height(), ""); handle.isDecorated(false); handle.isVisible(false); PixelBufferHandle pb = new PixelBufferHandle(); pb.setSrgbCapable(1); pb.setSamples(4); handle.setPixelBuffer(pb); Window backWindow = WindowManager.generate(handle); Thread backThr = new Thread(() -> { backgroundWindow = new Background(backWindow, handle); backgroundWindow.init(); float delta = 0; float accumulator = 0f; float interval = 1f / 5; float alpha = 0; int fps = 5; Window window = backgroundWindow.getWindow(); while (running) { delta = window.getDelta(); accumulator += delta; while (accumulator >= interval) { backgroundWindow.update(interval); accumulator -= interval; } alpha = accumulator / interval; if (window.isVisible()) backgroundWindow.render(alpha); window.updateDisplay(fps); } backgroundWindow.dispose(); window.dispose(); }); backThr.start(); }
public static void main(String[] args) { new Bootstrap(args); GLFWVidMode vidmode = GLFW.glfwGetVideoMode(GLFW.glfwGetPrimaryMonitor()); Variables.WIDTH = vidmode.width(); Variables.HEIGHT = 40; Variables.X = 0; Variables.Y = vidmode.height() - 40; Variables.ALWAYS_ON_TOP = true; Variables.DECORATED = false; Variables.TITLE = "Shell_TrayWnd"; new App(new TaskBar()); }
private void centerWindow(Display display) { GLFWVidMode vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor()); glfwSetWindowPos( this.windowHandle, (vidmode.width() - display.getWidth()) / 2, (vidmode.height() - display.getHeight()) / 2 ); }
/** * Center the window. */ public void centerWindow() { // Get the video mode GLFWVidMode videoMode = glfwGetVideoMode(glfwGetPrimaryMonitor()); // Set the window position glfwSetWindowPos(this.window, (videoMode.width() - this.width) / 2, (videoMode.height() - this.height) / 2); }
public void setFullscreen(boolean fullscreen){ this.fullscreen = fullscreen; if (fullscreen){ glfwSetWindowMonitor(getID(), glfwGetPrimaryMonitor(), 0, 0, getWidth(), getHeight(), GLFW.GLFW_DONT_CARE); } else { GLFWVidMode vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor()); glfwSetWindowMonitor(getID(), NULL, (vidmode.width() - WIDTH) / 2, (vidmode.height() - HEIGHT) / 2, getWidth(), getHeight(), GLFW.GLFW_DONT_CARE); } }
@Override public void setFullscreen(IMonitor monitor) { checkMainThread(); if (monitor == null) { GLFW.glfwSetWindowMonitor(window, MemoryUtil.NULL, (int) windowPosition.x, (int) windowPosition.y, (int) windowSize.x, (int) windowSize.y, GLFW.GLFW_DONT_CARE); } else { long m = ((GLFWMonitor) monitor).getHandle(); GLFWVidMode mode = GLFW.glfwGetVideoMode(m); GLFW.glfwSetWindowMonitor(window, m, 0, 0, mode.width(), mode.height(), mode.refreshRate()); } }
public float getPpiX () { intBuffer.clear(); glfwGetMonitorPhysicalSize(getWindowMonitor(), intBuffer, null); final GLFWVidMode vidMode = glfwGetVideoMode(getWindowMonitor()); int pW = intBuffer.get(); return vidMode.width() / (pW * 0.03937f); }
public float getPpiY () { intBuffer.clear(); glfwGetMonitorPhysicalSize(getWindowMonitor(), null, intBuffer); final GLFWVidMode vidMode = glfwGetVideoMode(getWindowMonitor()); int pH = intBuffer.get(); return vidMode.height() / (pH * 0.03937f); }
public float getPpcX () { intBuffer.clear(); glfwGetMonitorPhysicalSize(getWindowMonitor(), intBuffer, null); final GLFWVidMode vidMode = glfwGetVideoMode(getWindowMonitor()); int pW = intBuffer.get(); return vidMode.width() / (pW / 10); }
public float getPpcY () { intBuffer.clear(); glfwGetMonitorPhysicalSize(getWindowMonitor(), null, intBuffer); final GLFWVidMode vidMode = glfwGetVideoMode(getWindowMonitor()); int pH = intBuffer.get(); return vidMode.height() / (pH / 10); }
public DisplayMode[] getDisplayModes () { Array<DisplayMode> modes = new Array<DisplayMode>(); GLFWVidMode.Buffer vidModes = glfwGetVideoModes(getWindowMonitor()); for (int j = 0; j < vidModes.capacity(); j++) { vidModes.position(j); modes.add(new JglfwDisplayMode( vidModes.width(), vidModes.height(), vidModes.refreshRate(), vidModes.redBits() + vidModes.greenBits() + vidModes.blueBits() )); } return modes.toArray(DisplayMode.class); }
@Override public VideoMode[] getAvailableVideoModes() { GLFWVidMode.Buffer modes = GLFW.glfwGetVideoModes(monitor); VideoMode[] vmodes = new VideoMode[modes.capacity()]; for(int i = 0; i < modes.capacity(); i++) { vmodes[i] = new VideoMode(modes.get(i).width(), modes.get(i).height(), modes.get(i).refreshRate()); } return vmodes; }
@Override public double getDPI() { try(MemoryStack stack = MemoryStack.stackPush()) { IntBuffer width = stack.ints(0), height = stack.ints(0); glfwGetMonitorPhysicalSize(glfwGetPrimaryMonitor(), width, height); GLFWVidMode mode = glfwGetVideoMode(glfwGetPrimaryMonitor()); return mode.width() / (width.get(0) / 25.4); } }
@Override public LWJGLWindow createFullscreen() { long mon = monitor == null ? glfwGetPrimaryMonitor() : monitor.monitor; GLFWVidMode mode = glfwGetVideoMode(mon); long window = glfwCreateWindow(mode.width(), mode.height(), title, mon, 0L); if(window == 0L) throw new GLError("Context cannot be created"); return new LWJGLWindow(window, core); }
/** * This function returns a list of all video modes supported by the specified monitor. The returned list is sorted * in ascending order, first by color bit depth (the sum of all channel depths) and then by resolution area (the * product of width and height). * * @return The list of {@link VideoMode}s supported by this Monitor object. Note that this list is unmodifiable. */ public List<VideoMode> getVideoModes() { if (videoModes == null) { videoModes = new ArrayList<>(); GLFWVidMode.Buffer modes = glfwGetVideoModes(handle); for (int i = 0; i < modes.capacity(); i++) { modes.position(i); int width = modes.width(); int height = modes.height(); int redBits = modes.redBits(); int greenBits = modes.greenBits(); int blueBits = modes.blueBits(); int refreshRate = modes.refreshRate(); videoModes.add(new VideoMode(width, height, redBits, greenBits, blueBits, refreshRate)); } videoModes = Collections.unmodifiableList(videoModes); } return videoModes; }
/** * This function returns the current video mode of the specified monitor. If you have created a full screen window * for that monitor, the return value will depend on whether that window is iconified. * * @return The current {@link VideoMode} of this monitor. */ public VideoMode getVideoMode() { GLFWVidMode mode = glfwGetVideoMode(handle); int width = mode.width(); int height = mode.height(); int redBits = mode.redBits(); int greenBits = mode.greenBits(); int blueBits = mode.blueBits(); int refreshRate = mode.refreshRate(); return new VideoMode(width, height, redBits, greenBits, blueBits, refreshRate); }
private void handleResize(final long window, final int width, final int height) { if ((width != this.width) || (height != this.height)) { Main.this.width = width; Main.this.height = height; // Get the resolution of the primary monitor final ByteBuffer vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor()); // Center our window glfwSetWindowPos(this.window, (GLFWvidmode.width(vidmode) - this.width) / 2, (GLFWvidmode.height(vidmode) - this.height) / 2); glViewport(0, 0, width, height); } }
private void init() { glfwSetErrorCallback(errorCallback = errorCallbackPrint(System.err)); if (glfwInit() != GL11.GL_TRUE) throw new IllegalStateException("Unable to initialize GLFW"); glfwDefaultWindowHints(); glfwWindowHint(GLFW_VISIBLE, GL_FALSE); glfwWindowHint(GLFW_RESIZABLE, GL_FALSE); int WIDTH = 300; int HEIGHT = 300; window = glfwCreateWindow(WIDTH, HEIGHT, "cars-remote", NULL, NULL); if (window == NULL) throw new RuntimeException("Failed to create the GLFW window"); glfwSetKeyCallback(window, keyCallback); ByteBuffer vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor()); glfwSetWindowPos(window, (GLFWvidmode.width(vidmode) - WIDTH) / 2, (GLFWvidmode.height(vidmode) - HEIGHT) / 2); glfwMakeContextCurrent(window); glfwSwapInterval(1); glfwShowWindow(window); }
/** * Creates a new OpenGL display. * * @param width The width of the display, in pixels. * @param height The height of the display, in pixels. * @param title The text appearing in the display's title bar. */ public OpenGLDisplay(int width, int height, String title) { glfwSetErrorCallback(errorCallback = errorCallbackPrint(System.err)); if (glfwInit() != GL_TRUE) { throw new IllegalStateException("Unable to initialize GLFW"); } glfwDefaultWindowHints(); glfwWindowHint(GLFW_VISIBLE, GL_FALSE); glfwWindowHint(GLFW_RESIZABLE, GL_TRUE); window = glfwCreateWindow(width, height, title, NULL, NULL); if (window == NULL) { throw new RuntimeException("Failed to create the GLFW window"); } ByteBuffer vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor()); glfwSetWindowPos(window, (GLFWvidmode.width(vidmode) - width) / 2, (GLFWvidmode.height(vidmode) - height) / 2); glfwMakeContextCurrent(window); glfwSwapInterval(Debug.isIgnoringFrameCap() ? 0 : 1); glfwShowWindow(window); GLContext.createFromCurrent(); device = new OpenGLRenderDevice(width, height); this.target = new RenderTarget(device, width, height, 0, 0); frameBuffer = new RenderContext(device, target); input = new OpenGLInput(window); audioDevice = new OpenALAudioDevice(); }
/** * 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); } }
private void init() { ChessMaster.getLogger().info("Initializing GLFW"); errorCallback = GLFWErrorCallback.createPrint(System.err).set(); if (!glfwInit()) ChessMaster.getLogger().error("Cannot initialize GLFW!", new RuntimeException()); ChessMaster.getLogger().info("GLFW Creation complete"); glfwDefaultWindowHints(); glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE); glfwWindowHint(GLFW_RESIZABLE, GLFW_TRUE); window = glfwCreateWindow(600, 600, "Chess Master", MemoryUtil.NULL, MemoryUtil.NULL); if (window == MemoryUtil.NULL) ChessMaster.getLogger().error("Cannot create window!", new RuntimeException()); glfwSetKeyCallback(window, (window, key, scancode, action, mods) -> { switch (action) { case GLFW_RELEASE: ChessMaster.postEvent(new KeyEvent.Release(window, key, scancode, mods)); break; case GLFW_PRESS: ChessMaster.postEvent(new KeyEvent.Press(window, key, scancode, mods)); break; case GLFW_REPEAT: ChessMaster.postEvent(new KeyEvent.Repeat(window, key, scancode, mods)); } }); glfwSetWindowSizeCallback(window, (window1, w, h) -> { if (w > 0 && h > 0) { width = w; height = h; } }); try (MemoryStack stack = MemoryStack.stackPush()) { IntBuffer pWidth = stack.mallocInt(1); // int* IntBuffer pHeight = stack.mallocInt(1); // int* // Get the window size passed to glfwCreateWindow glfwGetWindowSize(window, pWidth, pHeight); // Get the resolution of the primary monitor GLFWVidMode vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor()); // Center the window glfwSetWindowPos( window, (vidmode.width() - pWidth.get(0)) / 2, (vidmode.height() - pHeight.get(0)) / 2 ); } // Make the OpenGL context current glfwMakeContextCurrent(window); glEnable(GL_TEXTURE_2D); // Make the window visible glfwShowWindow(window); board = new Board(); ChessMaster.getLogger().info("Initialization Complete"); }
private void init(int width, int height, String title) { // Setup an error callback. The default implementation // will print the error message in System.err. GLFWErrorCallback.createPrint(System.err).set(); // Initialize GLFW if(!glfwInit()){ throw new IllegalStateException("Unable to initialize GLFW"); } // Specify OpenGL 3.2 core profile context, with forward compatibility (for Mac) glfwDefaultWindowHints(); 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); // Allows our window to be resizable glfwWindowHint(GLFW_RESIZABLE, GL_TRUE); // Create main window window = glfwCreateWindow(width, height, title, NULL, NULL); // Check if window was created if(window == NULL){ System.err.println("Could not create our Window!"); } // Get the resolution of the primary monitor GLFWVidMode vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor()); // Center window glfwSetWindowPos( window, (vidmode.width() - width) / 2, (vidmode.height() - height) / 2 ); // Set context current to this window glfwMakeContextCurrent(window); // Show the window glfwShowWindow(window); // vsync off // glfwSwapInterval(0); }
public void center(){ GLFWVidMode mon = GLFW.glfwGetVideoMode(GLFW.glfwGetPrimaryMonitor()); setPosition((mon.width() - width) / 2, (mon.height() - height) / 2); }