use of org.lwjgl.glfw.GLFWMouseButtonCallback in project lwjgl3-demos by LWJGL.
the class Demo20 method init.
private void init() throws IOException {
glfwSetErrorCallback(errCallback = new GLFWErrorCallback() {
private GLFWErrorCallback delegate = GLFWErrorCallback.createPrint(System.err);
@Override
public void invoke(int error, long description) {
if (error == GLFW_VERSION_UNAVAILABLE)
System.err.println("This demo requires OpenGL 2.0 or higher.");
delegate.invoke(error, description);
}
@Override
public void free() {
delegate.free();
}
});
if (!glfwInit())
throw new IllegalStateException("Unable to initialize GLFW");
glfwDefaultWindowHints();
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 2);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0);
glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE);
glfwWindowHint(GLFW_RESIZABLE, GLFW_TRUE);
window = glfwCreateWindow(width, height, "Raytracing Demo (fragment shader)", 0L, 0L);
if (window == 0L) {
throw new AssertionError("Failed to create the GLFW window");
}
System.out.println("Press keypad '+' or 'page up' to increase the number of bounces.");
System.out.println("Press keypad '-' or 'page down' to decrease the number of bounces.");
glfwSetKeyCallback(window, keyCallback = new GLFWKeyCallback() {
@Override
public void invoke(long window, int key, int scancode, int action, int mods) {
if (action != GLFW_RELEASE) {
return;
}
if (key == GLFW_KEY_ESCAPE) {
glfwSetWindowShouldClose(window, true);
} else if (key == GLFW_KEY_KP_ADD || key == GLFW_KEY_PAGE_UP) {
int newBounceCount = Math.min(4, Demo20.this.bounceCount + 1);
if (newBounceCount != Demo20.this.bounceCount) {
Demo20.this.bounceCount = newBounceCount;
System.out.println("Ray bounce count is now: " + Demo20.this.bounceCount);
Demo20.this.frameNumber = 0;
}
} else if (key == GLFW_KEY_KP_SUBTRACT || key == GLFW_KEY_PAGE_DOWN) {
int newBounceCount = Math.max(1, Demo20.this.bounceCount - 1);
if (newBounceCount != Demo20.this.bounceCount) {
Demo20.this.bounceCount = newBounceCount;
System.out.println("Ray bounce count is now: " + Demo20.this.bounceCount);
Demo20.this.frameNumber = 0;
}
}
}
});
glfwSetFramebufferSizeCallback(window, fbCallback = new GLFWFramebufferSizeCallback() {
@Override
public void invoke(long window, int width, int height) {
if (width > 0 && height > 0 && (Demo20.this.width != width || Demo20.this.height != height)) {
Demo20.this.width = width;
Demo20.this.height = height;
Demo20.this.resetFramebuffer = true;
Demo20.this.frameNumber = 0;
}
}
});
glfwSetCursorPosCallback(window, cpCallback = new GLFWCursorPosCallback() {
@Override
public void invoke(long window, double x, double y) {
Demo20.this.mouseX = (float) x;
if (mouseDown) {
Demo20.this.frameNumber = 0;
}
}
});
glfwSetMouseButtonCallback(window, mbCallback = new GLFWMouseButtonCallback() {
@Override
public void invoke(long window, int button, int action, int mods) {
if (action == GLFW_PRESS) {
Demo20.this.mouseDownX = Demo20.this.mouseX;
Demo20.this.mouseDown = true;
} else if (action == GLFW_RELEASE) {
Demo20.this.mouseDown = false;
Demo20.this.rotationAboutY = Demo20.this.currRotationAboutY;
}
}
});
GLFWVidMode vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor());
glfwSetWindowPos(window, (vidmode.width() - width) / 2, (vidmode.height() - height) / 2);
glfwMakeContextCurrent(window);
glfwSwapInterval(0);
glfwShowWindow(window);
IntBuffer framebufferSize = BufferUtils.createIntBuffer(2);
nglfwGetFramebufferSize(window, memAddress(framebufferSize), memAddress(framebufferSize) + 4);
width = framebufferSize.get(0);
height = framebufferSize.get(1);
GLCapabilities caps = GL.createCapabilities();
if (!caps.GL_EXT_framebuffer_object) {
throw new AssertionError("This demo requires the EXT_framebuffer_object extensions");
}
if (!caps.GL_ARB_texture_float) {
throw new AssertionError("This demo requires the ARB_texture_float extensions");
}
debugProc = GLUtil.setupDebugMessageCallback();
/* Create all needed GL resources */
createFramebufferTexture();
createFrameBufferObject();
quadFullScreenVbo();
createBoxesTexture();
createRayTracingProgram();
initRayTracingProgram();
createQuadProgram();
initQuadProgram();
firstTime = System.nanoTime();
}
Aggregations