use of org.lwjgl.glfw.GLFWVidMode in project libgdx by libgdx.
the class GlfwTest method main.
public static void main(String[] argv) {
GLFW.glfwSetErrorCallback(errorCallback);
if (!glfwInit()) {
System.out.println("Couldn't initialize GLFW");
System.exit(-1);
}
glfwDefaultWindowHints();
glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE);
// fullscreen, not current resolution, fails
Buffer modes = glfwGetVideoModes(glfwGetPrimaryMonitor());
for (int i = 0; i < modes.limit(); i++) {
System.out.println(modes.get(i).width() + "x" + modes.get(i).height());
}
GLFWVidMode mode = modes.get(7);
System.out.println("Mode: " + mode.width() + "x" + mode.height());
windowHandle = glfwCreateWindow(mode.width(), mode.height(), "Test", glfwGetPrimaryMonitor(), 0);
if (windowHandle == 0) {
throw new RuntimeException("Couldn't create window");
}
glfwMakeContextCurrent(windowHandle);
GL.createCapabilities();
glfwSwapInterval(1);
glfwShowWindow(windowHandle);
IntBuffer tmp = BufferUtils.createIntBuffer(1);
IntBuffer tmp2 = BufferUtils.createIntBuffer(1);
int fbWidth = 0;
int fbHeight = 0;
while (!glfwWindowShouldClose(windowHandle)) {
glfwGetFramebufferSize(windowHandle, tmp, tmp2);
if (fbWidth != tmp.get(0) || fbHeight != tmp2.get(0)) {
fbWidth = tmp.get(0);
fbHeight = tmp2.get(0);
System.out.println("Framebuffer: " + tmp.get(0) + "x" + tmp2.get(0));
// GL11.glViewport(0, 0, tmp.get(0) * 2, tmp2.get(0) * 2);
}
GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);
GL11.glBegin(GL11.GL_TRIANGLES);
GL11.glVertex2f(-1f, -1f);
GL11.glVertex2f(1f, -1f);
GL11.glVertex2f(0, 1f);
GL11.glEnd();
glfwSwapBuffers(windowHandle);
glfwPollEvents();
}
glfwDestroyWindow(windowHandle);
glfwTerminate();
}
use of org.lwjgl.glfw.GLFWVidMode in project libgdx by libgdx.
the class Lwjgl3ApplicationConfiguration method getDisplayModes.
/**
* @return the available {@link DisplayMode}s of the given {@link Monitor}
*/
public static DisplayMode[] getDisplayModes(Monitor monitor) {
Lwjgl3Application.initializeGlfw();
Buffer videoModes = GLFW.glfwGetVideoModes(((Lwjgl3Monitor) monitor).monitorHandle);
DisplayMode[] result = new DisplayMode[videoModes.limit()];
for (int i = 0; i < result.length; i++) {
GLFWVidMode videoMode = videoModes.get(i);
result[i] = new Lwjgl3Graphics.Lwjgl3DisplayMode(((Lwjgl3Monitor) monitor).monitorHandle, videoMode.width(), videoMode.height(), videoMode.refreshRate(), videoMode.redBits() + videoMode.greenBits() + videoMode.blueBits());
}
return result;
}
use of org.lwjgl.glfw.GLFWVidMode in project Glowstone by GlowstoneMC.
the class GlowClient method start.
public void start() {
GLFWErrorCallback.createPrint(System.err).set();
entity = new GlowClientEntity(server.getWorlds().get(0).getSpawnLocation(), new PlayerProfile("GlowClient", UUID.randomUUID()));
if (!GLFW.glfwInit()) {
throw new IllegalStateException("Unable to initialize GLFW");
}
GLFW.glfwWindowHint(GLFW.GLFW_RESIZABLE, GLFW.GLFW_TRUE);
window = GLFW.glfwCreateWindow(1280, 720, "GlowClient", MemoryUtil.NULL, MemoryUtil.NULL);
if (window == MemoryUtil.NULL) {
throw new RuntimeException("Failed to create window");
}
GLFW.glfwSetKeyCallback(window, this::onInput);
try (MemoryStack stack = MemoryStack.stackPush()) {
IntBuffer pWidth = stack.mallocInt(1);
IntBuffer pHeight = stack.mallocInt(1);
GLFW.glfwGetWindowSize(window, pWidth, pHeight);
GLFWVidMode vidmode = GLFW.glfwGetVideoMode(GLFW.glfwGetPrimaryMonitor());
GLFW.glfwSetWindowPos(window, (vidmode.width() - pWidth.get(0)) / 2, (vidmode.height() - pHeight.get(0)) / 2);
}
GLFW.glfwMakeContextCurrent(window);
GLFW.glfwSwapInterval(1);
}
Aggregations