use of org.lwjgl.glfw.GLFWErrorCallback 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();
}
use of org.lwjgl.glfw.GLFWErrorCallback in project lwjgl3-demos by LWJGL.
the class ImmediateModeDemo method init.
void init() throws IOException {
glfwSetErrorCallback(errCallback = new GLFWErrorCallback() {
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_VISIBLE, GLFW_FALSE);
glfwWindowHint(GLFW_RESIZABLE, GLFW_TRUE);
window = glfwCreateWindow(width, height, "Immediate mode shader demo", NULL, NULL);
if (window == NULL) {
throw new AssertionError("Failed to create the GLFW window");
}
glfwSetFramebufferSizeCallback(window, fbCallback = new GLFWFramebufferSizeCallback() {
@Override
public void invoke(long window, int width, int height) {
if (width > 0 && height > 0 && (ImmediateModeDemo.this.width != width || ImmediateModeDemo.this.height != height)) {
ImmediateModeDemo.this.width = width;
ImmediateModeDemo.this.height = height;
}
}
});
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);
}
}
});
GLFWVidMode vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor());
glfwSetWindowPos(window, (vidmode.width() - width) / 2, (vidmode.height() - height) / 2);
glfwMakeContextCurrent(window);
glfwSwapInterval(1);
glfwShowWindow(window);
caps = GL.createCapabilities();
debugProc = GLUtil.setupDebugMessageCallback();
glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
// Create all needed GL resources
createProgram();
// and set some GL state
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
}
use of org.lwjgl.glfw.GLFWErrorCallback in project lwjgl3-demos by LWJGL.
the class NoVerticesGridDemo method init.
void init() throws IOException {
glfwSetErrorCallback(errCallback = new GLFWErrorCallback() {
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 3.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, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0);
glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE);
glfwWindowHint(GLFW_RESIZABLE, GLFW_TRUE);
window = glfwCreateWindow(width, height, "No vertices grid shader demo", NULL, NULL);
if (window == NULL) {
throw new AssertionError("Failed to create the GLFW window");
}
glfwSetFramebufferSizeCallback(window, fbCallback = new GLFWFramebufferSizeCallback() {
@Override
public void invoke(long window, int width, int height) {
if (width > 0 && height > 0 && (NoVerticesGridDemo.this.width != width || NoVerticesGridDemo.this.height != height)) {
NoVerticesGridDemo.this.width = width;
NoVerticesGridDemo.this.height = height;
}
}
});
System.out.println("Press 'arrow right' to increase the grid size in X");
System.out.println("Press 'arrow left' to decrease the grid size in X");
System.out.println("Press 'arrow up' to increase the grid size in Y");
System.out.println("Press 'arrow down' to decrease the grid size in Y");
glfwSetKeyCallback(window, keyCallback = new GLFWKeyCallback() {
@Override
public void invoke(long window, int key, int scancode, int action, int mods) {
if (key == GLFW_KEY_ESCAPE && action == GLFW_RELEASE) {
glfwSetWindowShouldClose(window, true);
}
if (key == GLFW_KEY_LEFT && (action == GLFW_RELEASE || action == GLFW_REPEAT)) {
sizeX = Math.max(1, sizeX - 1);
} else if (key == GLFW_KEY_RIGHT && (action == GLFW_RELEASE || action == GLFW_REPEAT)) {
sizeX++;
} else if (key == GLFW_KEY_DOWN && (action == GLFW_RELEASE || action == GLFW_REPEAT)) {
sizeY = Math.max(1, sizeY - 1);
} else if (key == GLFW_KEY_UP && (action == GLFW_RELEASE || action == GLFW_REPEAT)) {
sizeY++;
}
}
});
GLFWVidMode vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor());
glfwSetWindowPos(window, (vidmode.width() - width) / 2, (vidmode.height() - height) / 2);
glfwMakeContextCurrent(window);
glfwSwapInterval(0);
glfwShowWindow(window);
caps = createCapabilities();
debugProc = GLUtil.setupDebugMessageCallback();
glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
// Create all needed GL resources
createProgram();
// and set some GL state
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
}
use of org.lwjgl.glfw.GLFWErrorCallback in project lwjgl3-demos by LWJGL.
the class NoVerticesPolygonDemo method init.
void init() throws IOException {
glfwSetErrorCallback(errCallback = new GLFWErrorCallback() {
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 3.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, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0);
glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE);
glfwWindowHint(GLFW_RESIZABLE, GLFW_TRUE);
window = glfwCreateWindow(width, height, "No vertices polygon shader demo", NULL, NULL);
if (window == NULL) {
throw new AssertionError("Failed to create the GLFW window");
}
glfwSetFramebufferSizeCallback(window, fbCallback = new GLFWFramebufferSizeCallback() {
@Override
public void invoke(long window, int width, int height) {
if (width > 0 && height > 0 && (NoVerticesPolygonDemo.this.width != width || NoVerticesPolygonDemo.this.height != height)) {
NoVerticesPolygonDemo.this.width = width;
NoVerticesPolygonDemo.this.height = height;
}
}
});
System.out.println("Press 'arrow up' to increase the polygon vertex count");
System.out.println("Press 'arrow down' to decrease the polygon vertex count");
glfwSetKeyCallback(window, keyCallback = new GLFWKeyCallback() {
@Override
public void invoke(long window, int key, int scancode, int action, int mods) {
if (key == GLFW_KEY_ESCAPE && action == GLFW_RELEASE) {
glfwSetWindowShouldClose(window, true);
} else if (key == GLFW_KEY_UP && (action == GLFW_RELEASE || action == GLFW_REPEAT)) {
count++;
} else if (key == GLFW_KEY_DOWN && (action == GLFW_RELEASE || action == GLFW_REPEAT)) {
count = Math.max(3, count - 1);
}
}
});
GLFWVidMode vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor());
glfwSetWindowPos(window, (vidmode.width() - width) / 2, (vidmode.height() - height) / 2);
glfwMakeContextCurrent(window);
glfwSwapInterval(1);
glfwShowWindow(window);
caps = GL.createCapabilities();
debugProc = GLUtil.setupDebugMessageCallback();
glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
// Create all needed GL resources
createProgram();
// and set some GL state
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
}
use of org.lwjgl.glfw.GLFWErrorCallback in project lwjgl3-demos by LWJGL.
the class SwtAndGlfwDemo method main.
public static void main(String[] args) {
// Create SWT window
Display display = new Display();
final Shell shell = new Shell(display);
shell.setText("SWT window");
shell.setLayout(new FillLayout());
shell.addListener(SWT.Traverse, new Listener() {
public void handleEvent(Event event) {
switch(event.detail) {
case SWT.TRAVERSE_ESCAPE:
shell.close();
event.detail = SWT.TRAVERSE_NONE;
event.doit = false;
break;
default:
break;
}
}
});
GLData data = new GLData();
data.doubleBuffer = true;
GLCanvas swtCanvas = new GLCanvas(shell, SWT.NO_BACKGROUND | SWT.NO_REDRAW_RESIZE, data);
int dw = shell.getSize().x - shell.getClientArea().width;
int dh = shell.getSize().y - shell.getClientArea().height;
shell.setSize(800 + dw, 600 + dh);
swtCanvas.setCurrent();
GLCapabilities swtCapabilities = createCapabilities();
Callback swtDebugProc = GLUtil.setupDebugMessageCallback();
shell.open();
// Create GLFW window
GLFWErrorCallback errorCallback;
glfwSetErrorCallback(errorCallback = GLFWErrorCallback.createPrint(System.err));
if (!glfwInit())
throw new IllegalStateException("Unable to initialize GLFW");
glfwDefaultWindowHints();
glfwWindowHint(GLFW_RESIZABLE, GLFW_TRUE);
glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE);
glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, GLFW_TRUE);
long glfwWindow = glfwCreateWindow(800, 600, "GLFW window", NULL, NULL);
GLFWKeyCallback keyCallback;
glfwSetKeyCallback(glfwWindow, keyCallback = new GLFWKeyCallback() {
public void invoke(long window, int key, int scancode, int action, int mods) {
if (key == GLFW_KEY_ESCAPE && action == GLFW_RELEASE)
glfwSetWindowShouldClose(window, true);
}
});
glfwMakeContextCurrent(glfwWindow);
GLCapabilities glfwCapabilities = createCapabilities();
Callback glfwDebugProc = GLUtil.setupDebugMessageCallback();
glfwShowWindow(glfwWindow);
while (!shell.isDisposed() && !glfwWindowShouldClose(glfwWindow)) {
// Process window messages (for both SWT _and_ GLFW)
display.readAndDispatch();
// Render to SWT window
if (!swtCanvas.isDisposed()) {
swtCanvas.setCurrent();
setCapabilities(swtCapabilities);
glClearColor(0.2f, 0.4f, 0.6f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
swtCanvas.swapBuffers();
}
// Render to GLFW window
if (glfwGetWindowAttrib(glfwWindow, GLFW_VISIBLE) == GLFW_TRUE) {
glfwMakeContextCurrent(glfwWindow);
setCapabilities(glfwCapabilities);
glClearColor(0.2f, 0.3f, 0.4f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
glfwSwapBuffers(glfwWindow);
}
}
// Dispose of SWT
if (swtDebugProc != null)
swtDebugProc.free();
if (!shell.isDisposed())
shell.dispose();
display.dispose();
// Dispose of GLFW
if (glfwDebugProc != null)
glfwDebugProc.free();
keyCallback.free();
glfwDestroyWindow(glfwWindow);
glfwTerminate();
errorCallback.free();
}
Aggregations