use of org.lwjgl.glfw.GLFWErrorCallback in project lwjgl3-demos by LWJGL.
the class ShadowMappingDemo method init.
void init() throws IOException {
glfwSetErrorCallback(errCallback = new GLFWErrorCallback() {
GLFWErrorCallback delegate = GLFWErrorCallback.createPrint(System.err);
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, "Shadow Mapping Demo", NULL, NULL);
if (window == NULL) {
throw new AssertionError("Failed to create the GLFW window");
}
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);
}
}
});
glfwSetFramebufferSizeCallback(window, fbCallback = new GLFWFramebufferSizeCallback() {
public void invoke(long window, int width, int height) {
if (width > 0 && height > 0 && (ShadowMappingDemo.this.width != width || ShadowMappingDemo.this.height != height)) {
ShadowMappingDemo.this.width = width;
ShadowMappingDemo.this.height = height;
}
}
});
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);
caps = GL.createCapabilities();
debugProc = GLUtil.setupDebugMessageCallback();
/* Set some GL states */
glEnable(GL_CULL_FACE);
glEnable(GL_DEPTH_TEST);
glClearColor(0.2f, 0.3f, 0.4f, 1.0f);
/* Create all needed GL resources */
createVao();
createShadowProgram();
initShadowProgram();
createNormalProgram();
initNormalProgram();
createDepthTexture();
createFbo();
}
use of org.lwjgl.glfw.GLFWErrorCallback in project lwjgl3-demos by LWJGL.
the class ShadowMappingDemo20 method init.
void init() throws IOException {
glfwSetErrorCallback(errCallback = new GLFWErrorCallback() {
GLFWErrorCallback delegate = GLFWErrorCallback.createPrint(System.err);
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, "Shadow Mapping Demo", NULL, NULL);
if (window == NULL) {
throw new AssertionError("Failed to create the GLFW window");
}
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);
}
}
});
glfwSetFramebufferSizeCallback(window, fbCallback = new GLFWFramebufferSizeCallback() {
public void invoke(long window, int width, int height) {
if (width > 0 && height > 0 && (ShadowMappingDemo20.this.width != width || ShadowMappingDemo20.this.height != height)) {
ShadowMappingDemo20.this.width = width;
ShadowMappingDemo20.this.height = height;
}
}
});
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);
caps = GL.createCapabilities();
if (!caps.GL_EXT_framebuffer_object) {
throw new AssertionError("This demo requires the EXT_framebuffer_object extension");
}
debugProc = GLUtil.setupDebugMessageCallback();
/* Set some GL states */
glEnable(GL_CULL_FACE);
glEnable(GL_DEPTH_TEST);
glClearColor(0.2f, 0.3f, 0.4f, 1.0f);
/* Create all needed GL resources */
createVbo();
createShadowProgram();
initShadowProgram();
createNormalProgram();
initNormalProgram();
createDepthTexture();
createFbo();
}
use of org.lwjgl.glfw.GLFWErrorCallback in project lwjgl3-demos by LWJGL.
the class DepthEdgeShaderDemo20 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_CONTEXT_VERSION_MAJOR, 2);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0);
glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE);
glfwWindowHint(GLFW_RESIZABLE, GLFW_TRUE);
window = glfwCreateWindow(width, height, "Silhouette rendering with edge detection shader", NULL, NULL);
if (window == NULL) {
throw new AssertionError("Failed to create the GLFW window");
}
System.out.println("Press spacebar to show/hide edges.");
glfwSetFramebufferSizeCallback(window, fbCallback = new GLFWFramebufferSizeCallback() {
@Override
public void invoke(long window, int width, int height) {
if (width > 0 && height > 0 && (DepthEdgeShaderDemo20.this.width != width || DepthEdgeShaderDemo20.this.height != height)) {
DepthEdgeShaderDemo20.this.width = width;
DepthEdgeShaderDemo20.this.height = height;
DepthEdgeShaderDemo20.this.resize = true;
}
}
});
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_SPACE) {
showEdge = !showEdge;
}
}
});
GLFWVidMode vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor());
glfwSetWindowPos(window, (vidmode.width() - width) / 2, (vidmode.height() - height) / 2);
glfwMakeContextCurrent(window);
glfwSwapInterval(0);
glfwShowWindow(window);
caps = GL.createCapabilities();
if (!caps.GL_EXT_framebuffer_object) {
throw new AssertionError("This demo requires the EXT_framebuffer_object extension");
}
if (!caps.GL_ARB_texture_float) {
throw new AssertionError("This demo requires the ARB_texture_float extension");
}
debugProc = GLUtil.setupDebugMessageCallback();
glClearColor(0.0f, 0.0f, 1.0f, 0.0f);
glEnable(GL_DEPTH_TEST);
glEnable(GL_CULL_FACE);
/* Create all needed GL resources */
createCube();
createQuad();
createNormalProgram();
createEdgeProgram();
createTex();
createFbo();
}
use of org.lwjgl.glfw.GLFWErrorCallback in project lwjgl3-demos by LWJGL.
the class EdgeShaderMultisampleDemo20 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_CONTEXT_VERSION_MAJOR, 2);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0);
glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE);
glfwWindowHint(GLFW_RESIZABLE, GLFW_TRUE);
window = glfwCreateWindow(width, height, "Multisampled silhouette rendering with Sobel edge detection shader", NULL, NULL);
if (window == NULL) {
throw new AssertionError("Failed to create the GLFW window");
}
System.out.println("Press letter 'O' to toggle between outline/edges.");
System.out.println("Press spacebar to show/hide edges.");
glfwSetFramebufferSizeCallback(window, fbCallback = new GLFWFramebufferSizeCallback() {
@Override
public void invoke(long window, int width, int height) {
if (width > 0 && height > 0 && (EdgeShaderMultisampleDemo20.this.width != width || EdgeShaderMultisampleDemo20.this.height != height)) {
EdgeShaderMultisampleDemo20.this.width = width;
EdgeShaderMultisampleDemo20.this.height = height;
EdgeShaderMultisampleDemo20.this.resize = true;
}
}
});
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_O) {
outlineOnly = !outlineOnly;
} else if (key == GLFW_KEY_SPACE) {
showEdge = !showEdge;
}
}
});
GLFWVidMode vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor());
glfwSetWindowPos(window, (vidmode.width() - width) / 2, (vidmode.height() - height) / 2);
glfwMakeContextCurrent(window);
glfwSwapInterval(0);
glfwShowWindow(window);
caps = GL.createCapabilities();
if (!caps.GL_EXT_framebuffer_object) {
throw new AssertionError("This demo requires the EXT_framebuffer_object extension");
}
if (!caps.GL_EXT_framebuffer_multisample) {
throw new AssertionError("This demo requires the EXT_framebuffer_multisample extension");
}
if (!caps.GL_EXT_framebuffer_blit) {
throw new AssertionError("This demo requires the EXT_framebuffer_blit extension");
}
debugProc = GLUtil.setupDebugMessageCallback();
// using alpha = 0.0 is important here for the outline to work!
glClearColor(1.0f, 1.0f, 1.0f, 0.0f);
glEnable(GL_DEPTH_TEST);
glEnable(GL_CULL_FACE);
samples = Math.min(4, glGetInteger(GL_MAX_SAMPLES_EXT));
/* Create all needed GL resources */
createCube();
createQuad();
createNormalProgram();
createEdgeProgram();
createOutlineProgram();
createTex();
createFbos();
}
Aggregations