org.lwjgl.glfw.GLFWErrorCallback Java Examples
The following examples show how to use
org.lwjgl.glfw.GLFWErrorCallback.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GLFWContextCreator.java From settlers-remake with MIT License | 6 votes |
public void async_init() { if(debug) { ec = GLFWErrorCallback.createPrint(System.err); GLFW.glfwSetErrorCallback(ec); } if(!GLFW.glfwInit()) throw new Error("glfwInit() failed!"); GLFW.glfwWindowHint(GLFW.GLFW_OPENGL_DEBUG_CONTEXT, debug ? GLFW.GLFW_TRUE : GLFW.GLFW_DONT_CARE); GLFW.glfwWindowHint(GLFW.GLFW_STENCIL_BITS, 1); glfw_wnd = GLFW.glfwCreateWindow(width + 1, width + 1, "lwjgl-offscreen", 0, 0); GLFW.glfwMakeContextCurrent(glfw_wnd); GLFW.glfwSwapInterval(0); event_converter.registerCallbacks(); }
Example #2
Source File: OpenGLStars.java From scava with Eclipse Public License 2.0 | 5 votes |
@Override public void init() { // Set the error handling code: all GLFW errors will be printed to the system error stream (just like println) GLFWErrorCallback.createPrint(System.err).set(); glfwSetErrorCallback(errorCallback); // Initialize GLFW: if (!glfwInit()) throw new IllegalStateException("GLFW initialization failed"); // Configure the GLFW window windowID = glfwCreateWindow( 640, 480, // Width and height of the drawing canvas in pixels "Test", // Title of the window MemoryUtil.NULL, // Monitor ID to use for fullscreen mode, or NULL to use windowed mode (LWJGL JavaDoc) MemoryUtil.NULL); // Window to share resources with, or NULL to not share resources (LWJGL JavaDoc) if (windowID == MemoryUtil.NULL) throw new IllegalStateException("GLFW window creation failed"); glfwMakeContextCurrent(windowID); // Links the OpenGL context of the window to the current thread (GLFW_NO_CURRENT_CONTEXT error) glfwSwapInterval(1); // Enable VSync, which effective caps the frame-rate of the application to 60 frames-per-second glfwShowWindow(windowID); // If you don't add this line, you'll get the following exception: // java.lang.IllegalStateException: There is no OpenGL context current in the current thread. glfwMakeContextCurrent(windowID); // This line is critical for LWJGL's interoperation with GLFW's // OpenGL context, or any context that is managed externally. // LWJGL detects the context that is current in the current thread, // creates the GLCapabilities instance and makes the OpenGL // bindings available for use. GL.createCapabilities(); // Set the clear color glClearColor(0.5f, 0.5f, 0.5f, 1f); setUpMatrices(); }
Example #3
Source File: DesktopMini2DxGame.java From mini2Dx with Apache License 2.0 | 5 votes |
static void initializeGlfw() { if (errorCallback == null) { Lwjgl3NativesLoader.load(); errorCallback = GLFWErrorCallback.createPrint(System.err); GLFW.glfwSetErrorCallback(errorCallback); GLFW.glfwInitHint(GLFW.GLFW_JOYSTICK_HAT_BUTTONS, GLFW.GLFW_FALSE); if (!GLFW.glfwInit()) { throw new GdxRuntimeException("Unable to initialize GLFW"); } } }
Example #4
Source File: GlfwAPI.java From WraithEngine with Apache License 2.0 | 5 votes |
@Override public void setErrorCallback(PrintStream printStream) { try (GLFWErrorCallback callback = GLFWErrorCallback.createPrint(printStream)) { callback.set(); } }
Example #5
Source File: CoreEngine.java From oreon-engine with GNU General Public License v3.0 | 5 votes |
private void init() { glfwSetErrorCallback(errorCallback = GLFWErrorCallback.createPrint(System.err)); renderEngine = BaseContext.getRenderEngine(); window = BaseContext.getWindow(); input = BaseContext.getInput(); input.create(window.getId()); window.show(); }
Example #6
Source File: GlfwAPI.java From WraithEngine with Apache License 2.0 | 5 votes |
@Override public void setErrorCallback(PrintStream printStream) { try (GLFWErrorCallback callback = GLFWErrorCallback.createPrint(printStream)) { callback.set(); } }
Example #7
Source File: Window.java From lwjglbook with Apache License 2.0 | 4 votes |
public void init() { // Setup an error callback. The default implementation // will print the error message in System.err. GLFWErrorCallback.createPrint(System.err).set(); // Initialize GLFW. Most GLFW functions will not work before doing this. if (!glfwInit()) { throw new IllegalStateException("Unable to initialize GLFW"); } glfwDefaultWindowHints(); // optional, the current window hints are already the default glfwWindowHint(GLFW_VISIBLE, GL_FALSE); // the window will stay hidden after creation glfwWindowHint(GLFW_RESIZABLE, GL_TRUE); // the window will be resizable glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2); if (opts.compatibleProfile) { glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_COMPAT_PROFILE); } else { glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); } boolean maximized = false; // If no size has been specified set it to maximized state if (width == 0 || height == 0) { // Set up a fixed width and height so window initialization does not fail width = 100; height = 100; glfwWindowHint(GLFW_MAXIMIZED, GLFW_TRUE); maximized = true; } // Create the window windowHandle = glfwCreateWindow(width, height, title, NULL, NULL); if (windowHandle == NULL) { throw new RuntimeException("Failed to create the GLFW window"); } // Setup resize callback glfwSetFramebufferSizeCallback(windowHandle, (window, width, height) -> { this.width = width; this.height = height; this.setResized(true); }); // Setup a key callback. It will be called every time a key is pressed, repeated or released. glfwSetKeyCallback(windowHandle, (window, key, scancode, action, mods) -> { if (key == GLFW_KEY_ESCAPE && action == GLFW_RELEASE) { glfwSetWindowShouldClose(window, true); // We will detect this in the rendering loop } }); if (maximized) { glfwMaximizeWindow(windowHandle); } else { // Get the resolution of the primary monitor GLFWVidMode vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor()); // Center our window glfwSetWindowPos( windowHandle, (vidmode.width() - width) / 2, (vidmode.height() - height) / 2 ); } // Make the OpenGL context current glfwMakeContextCurrent(windowHandle); if (isvSync()) { // Enable v-sync glfwSwapInterval(1); } // Make the window visible glfwShowWindow(windowHandle); GL.createCapabilities(); // Set the clear color glClearColor(0.0f, 0.0f, 0.0f, 0.0f); glEnable(GL_DEPTH_TEST); glEnable(GL_STENCIL_TEST); if (opts.showTriangles) { glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); } // Support for transparencies glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); if (opts.cullFace) { glEnable(GL_CULL_FACE); glCullFace(GL_BACK); } // Antialiasing if (opts.antialiasing) { glfwWindowHint(GLFW_SAMPLES, 4); } }
Example #8
Source File: Window.java From lwjglbook with Apache License 2.0 | 4 votes |
public void init() { // Setup an error callback. The default implementation // will print the error message in System.err. GLFWErrorCallback.createPrint(System.err).set(); // Initialize GLFW. Most GLFW functions will not work before doing this. if (!glfwInit()) { throw new IllegalStateException("Unable to initialize GLFW"); } glfwDefaultWindowHints(); // optional, the current window hints are already the default glfwWindowHint(GLFW_VISIBLE, GL_FALSE); // the window will stay hidden after creation glfwWindowHint(GLFW_RESIZABLE, GL_TRUE); // the window will be resizable 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, GL_TRUE); // Create the window windowHandle = glfwCreateWindow(width, height, title, NULL, NULL); if (windowHandle == NULL) { throw new RuntimeException("Failed to create the GLFW window"); } // Setup resize callback glfwSetFramebufferSizeCallback(windowHandle, (window, width, height) -> { this.width = width; this.height = height; this.setResized(true); }); // Setup a key callback. It will be called every time a key is pressed, repeated or released. glfwSetKeyCallback(windowHandle, (window, key, scancode, action, mods) -> { if (key == GLFW_KEY_ESCAPE && action == GLFW_RELEASE) { glfwSetWindowShouldClose(window, true); // We will detect this in the rendering loop } }); // Get the resolution of the primary monitor GLFWVidMode vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor()); // Center our window glfwSetWindowPos( windowHandle, (vidmode.width() - width) / 2, (vidmode.height() - height) / 2 ); // Make the OpenGL context current glfwMakeContextCurrent(windowHandle); if (isvSync()) { // Enable v-sync glfwSwapInterval(1); } // Make the window visible glfwShowWindow(windowHandle); GL.createCapabilities(); // Set the clear color glClearColor(0.0f, 0.0f, 0.0f, 0.0f); }
Example #9
Source File: Window.java From lwjglbook with Apache License 2.0 | 4 votes |
public void init() { // Setup an error callback. The default implementation // will print the error message in System.err. GLFWErrorCallback.createPrint(System.err).set(); // Initialize GLFW. Most GLFW functions will not work before doing this. if (!glfwInit()) { throw new IllegalStateException("Unable to initialize GLFW"); } glfwDefaultWindowHints(); // optional, the current window hints are already the default glfwWindowHint(GLFW_VISIBLE, GL_FALSE); // the window will stay hidden after creation glfwWindowHint(GLFW_RESIZABLE, GL_TRUE); // the window will be resizable glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2); if (opts.compatibleProfile) { glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_COMPAT_PROFILE); } else { glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); } boolean maximized = false; // If no size has been specified set it to maximized state if (width == 0 || height == 0) { // Set up a fixed width and height so window initialization does not fail width = 100; height = 100; glfwWindowHint(GLFW_MAXIMIZED, GLFW_TRUE); maximized = true; } // Create the window windowHandle = glfwCreateWindow(width, height, title, NULL, NULL); if (windowHandle == NULL) { throw new RuntimeException("Failed to create the GLFW window"); } // Setup resize callback glfwSetFramebufferSizeCallback(windowHandle, (window, width, height) -> { this.width = width; this.height = height; this.setResized(true); }); // Setup a key callback. It will be called every time a key is pressed, repeated or released. glfwSetKeyCallback(windowHandle, (window, key, scancode, action, mods) -> { if (key == GLFW_KEY_ESCAPE && action == GLFW_RELEASE) { glfwSetWindowShouldClose(window, true); // We will detect this in the rendering loop } }); if (maximized) { glfwMaximizeWindow(windowHandle); } else { // Get the resolution of the primary monitor GLFWVidMode vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor()); // Center our window glfwSetWindowPos( windowHandle, (vidmode.width() - width) / 2, (vidmode.height() - height) / 2 ); } // Make the OpenGL context current glfwMakeContextCurrent(windowHandle); if (isvSync()) { // Enable v-sync glfwSwapInterval(1); } // Make the window visible glfwShowWindow(windowHandle); GL.createCapabilities(); // Set the clear color glClearColor(0.0f, 0.0f, 0.0f, 0.0f); glEnable(GL_DEPTH_TEST); glEnable(GL_STENCIL_TEST); if (opts.showTriangles) { glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); } // Support for transparencies glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); if (opts.cullFace) { glEnable(GL_CULL_FACE); glCullFace(GL_BACK); } // Antialiasing if (opts.antialiasing) { glfwWindowHint(GLFW_SAMPLES, 4); } }
Example #10
Source File: Window.java From lwjglbook with Apache License 2.0 | 4 votes |
public void init() { // Setup an error callback. The default implementation // will print the error message in System.err. GLFWErrorCallback.createPrint(System.err).set(); // Initialize GLFW. Most GLFW functions will not work before doing this. if (!glfwInit()) { throw new IllegalStateException("Unable to initialize GLFW"); } glfwDefaultWindowHints(); // optional, the current window hints are already the default glfwWindowHint(GLFW_VISIBLE, GL_FALSE); // the window will stay hidden after creation glfwWindowHint(GLFW_RESIZABLE, GL_TRUE); // the window will be resizable 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, GL_TRUE); boolean maximized = false; // If no size has been specified set it to maximized state if (width == 0 || height == 0) { // Set up a fixed width and height so window initialization does not fail width = 100; height = 100; glfwWindowHint(GLFW_MAXIMIZED, GLFW_TRUE); maximized = true; } // Create the window windowHandle = glfwCreateWindow(width, height, title, NULL, NULL); if (windowHandle == NULL) { throw new RuntimeException("Failed to create the GLFW window"); } // Setup resize callback glfwSetFramebufferSizeCallback(windowHandle, (window, width, height) -> { this.width = width; this.height = height; this.setResized(true); }); // Setup a key callback. It will be called every time a key is pressed, repeated or released. glfwSetKeyCallback(windowHandle, (window, key, scancode, action, mods) -> { if (key == GLFW_KEY_ESCAPE && action == GLFW_RELEASE) { glfwSetWindowShouldClose(window, true); // We will detect this in the rendering loop } }); if (maximized) { glfwMaximizeWindow(windowHandle); } else { // Get the resolution of the primary monitor GLFWVidMode vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor()); // Center our window glfwSetWindowPos( windowHandle, (vidmode.width() - width) / 2, (vidmode.height() - height) / 2 ); } // Make the OpenGL context current glfwMakeContextCurrent(windowHandle); if (isvSync()) { // Enable v-sync glfwSwapInterval(1); } // Make the window visible glfwShowWindow(windowHandle); GL.createCapabilities(); // Set the clear color glClearColor(0.0f, 0.0f, 0.0f, 0.0f); glEnable(GL_DEPTH_TEST); if (opts.showTriangles) { glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); } // Support for transparencies glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); if (opts.cullFace) { glEnable(GL_CULL_FACE); glCullFace(GL_BACK); } }
Example #11
Source File: Window.java From lwjglbook with Apache License 2.0 | 4 votes |
public void init() { // Setup an error callback. The default implementation // will print the error message in System.err. GLFWErrorCallback.createPrint(System.err).set(); // Initialize GLFW. Most GLFW functions will not work before doing this. if (!glfwInit()) { throw new IllegalStateException("Unable to initialize GLFW"); } glfwDefaultWindowHints(); // optional, the current window hints are already the default glfwWindowHint(GLFW_VISIBLE, GL_FALSE); // the window will stay hidden after creation glfwWindowHint(GLFW_RESIZABLE, GL_TRUE); // the window will be resizable 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, GL_TRUE); boolean maximized = false; // If no size has been specified set it to maximized state if (width == 0 || height == 0) { // Set up a fixed width and height so window initialization does not fail width = 100; height = 100; glfwWindowHint(GLFW_MAXIMIZED, GLFW_TRUE); maximized = true; } // Create the window windowHandle = glfwCreateWindow(width, height, title, NULL, NULL); if (windowHandle == NULL) { throw new RuntimeException("Failed to create the GLFW window"); } // Setup resize callback glfwSetFramebufferSizeCallback(windowHandle, (window, width, height) -> { this.width = width; this.height = height; this.setResized(true); }); // Setup a key callback. It will be called every time a key is pressed, repeated or released. glfwSetKeyCallback(windowHandle, (window, key, scancode, action, mods) -> { if (key == GLFW_KEY_ESCAPE && action == GLFW_RELEASE) { glfwSetWindowShouldClose(window, true); // We will detect this in the rendering loop } }); if (maximized) { glfwMaximizeWindow(windowHandle); } else { // Get the resolution of the primary monitor GLFWVidMode vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor()); // Center our window glfwSetWindowPos( windowHandle, (vidmode.width() - width) / 2, (vidmode.height() - height) / 2 ); } // Make the OpenGL context current glfwMakeContextCurrent(windowHandle); if (isvSync()) { // Enable v-sync glfwSwapInterval(1); } // Make the window visible glfwShowWindow(windowHandle); GL.createCapabilities(); // Set the clear color glClearColor(0.0f, 0.0f, 0.0f, 0.0f); glEnable(GL_DEPTH_TEST); if (opts.showTriangles) { glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); } // Support for transparencies glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); if (opts.cullFace) { glEnable(GL_CULL_FACE); glCullFace(GL_BACK); } }
Example #12
Source File: Window.java From lwjglbook with Apache License 2.0 | 4 votes |
public void init() { // Setup an error callback. The default implementation // will print the error message in System.err. GLFWErrorCallback.createPrint(System.err).set(); // Initialize GLFW. Most GLFW functions will not work before doing this. if (!glfwInit()) { throw new IllegalStateException("Unable to initialize GLFW"); } glfwDefaultWindowHints(); // optional, the current window hints are already the default glfwWindowHint(GLFW_VISIBLE, GL_FALSE); // the window will stay hidden after creation glfwWindowHint(GLFW_RESIZABLE, GL_TRUE); // the window will be resizable 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, GL_TRUE); boolean maximized = false; // If no size has been specified set it to maximized state if (width == 0 || height == 0) { // Set up a fixed width and height so window initialization does not fail width = 100; height = 100; glfwWindowHint(GLFW_MAXIMIZED, GLFW_TRUE); maximized = true; } // Create the window windowHandle = glfwCreateWindow(width, height, title, NULL, NULL); if (windowHandle == NULL) { throw new RuntimeException("Failed to create the GLFW window"); } // Setup resize callback glfwSetFramebufferSizeCallback(windowHandle, (window, width, height) -> { this.width = width; this.height = height; this.setResized(true); }); // Setup a key callback. It will be called every time a key is pressed, repeated or released. glfwSetKeyCallback(windowHandle, (window, key, scancode, action, mods) -> { if (key == GLFW_KEY_ESCAPE && action == GLFW_RELEASE) { glfwSetWindowShouldClose(window, true); // We will detect this in the rendering loop } }); if (maximized) { glfwMaximizeWindow(windowHandle); } else { // Get the resolution of the primary monitor GLFWVidMode vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor()); // Center our window glfwSetWindowPos( windowHandle, (vidmode.width() - width) / 2, (vidmode.height() - height) / 2 ); } // Make the OpenGL context current glfwMakeContextCurrent(windowHandle); if (isvSync()) { // Enable v-sync glfwSwapInterval(1); } // Make the window visible glfwShowWindow(windowHandle); GL.createCapabilities(); // Set the clear color glClearColor(0.0f, 0.0f, 0.0f, 0.0f); glEnable(GL_DEPTH_TEST); if (opts.showTriangles) { glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); } // Support for transparencies glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); if (opts.cullFace) { glEnable(GL_CULL_FACE); glCullFace(GL_BACK); } }
Example #13
Source File: Window.java From lwjglbook with Apache License 2.0 | 4 votes |
public void init() { // Setup an error callback. The default implementation // will print the error message in System.err. GLFWErrorCallback.createPrint(System.err).set(); // Initialize GLFW. Most GLFW functions will not work before doing this. if (!glfwInit()) { throw new IllegalStateException("Unable to initialize GLFW"); } glfwDefaultWindowHints(); // optional, the current window hints are already the default glfwWindowHint(GLFW_VISIBLE, GL_FALSE); // the window will stay hidden after creation glfwWindowHint(GLFW_RESIZABLE, GL_TRUE); // the window will be resizable 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, GL_TRUE); // Create the window windowHandle = glfwCreateWindow(width, height, title, NULL, NULL); if (windowHandle == NULL) { throw new RuntimeException("Failed to create the GLFW window"); } // Setup resize callback glfwSetFramebufferSizeCallback(windowHandle, (window, width, height) -> { this.width = width; this.height = height; this.setResized(true); }); // Setup a key callback. It will be called every time a key is pressed, repeated or released. glfwSetKeyCallback(windowHandle, (window, key, scancode, action, mods) -> { if (key == GLFW_KEY_ESCAPE && action == GLFW_RELEASE) { glfwSetWindowShouldClose(window, true); // We will detect this in the rendering loop } }); // Get the resolution of the primary monitor GLFWVidMode vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor()); // Center our window glfwSetWindowPos( windowHandle, (vidmode.width() - width) / 2, (vidmode.height() - height) / 2 ); // Make the OpenGL context current glfwMakeContextCurrent(windowHandle); if (isvSync()) { // Enable v-sync glfwSwapInterval(1); } // Make the window visible glfwShowWindow(windowHandle); GL.createCapabilities(); // Set the clear color glClearColor(0.0f, 0.0f, 0.0f, 0.0f); }
Example #14
Source File: Window.java From lwjglbook with Apache License 2.0 | 4 votes |
public void init() { // Setup an error callback. The default implementation // will print the error message in System.err. GLFWErrorCallback.createPrint(System.err).set(); // Initialize GLFW. Most GLFW functions will not work before doing this. if (!glfwInit()) { throw new IllegalStateException("Unable to initialize GLFW"); } glfwDefaultWindowHints(); // optional, the current window hints are already the default glfwWindowHint(GLFW_VISIBLE, GL_FALSE); // the window will stay hidden after creation glfwWindowHint(GLFW_RESIZABLE, GL_TRUE); // the window will be resizable glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2); if (opts.compatibleProfile) { glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_COMPAT_PROFILE); } else { glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); } boolean maximized = false; // If no size has been specified set it to maximized state if (width == 0 || height == 0) { // Set up a fixed width and height so window initialization does not fail width = 100; height = 100; glfwWindowHint(GLFW_MAXIMIZED, GLFW_TRUE); maximized = true; } // Create the window windowHandle = glfwCreateWindow(width, height, title, NULL, NULL); if (windowHandle == NULL) { throw new RuntimeException("Failed to create the GLFW window"); } // Setup resize callback glfwSetFramebufferSizeCallback(windowHandle, (window, width, height) -> { this.width = width; this.height = height; this.setResized(true); }); // Setup a key callback. It will be called every time a key is pressed, repeated or released. glfwSetKeyCallback(windowHandle, (window, key, scancode, action, mods) -> { if (key == GLFW_KEY_ESCAPE && action == GLFW_RELEASE) { glfwSetWindowShouldClose(window, true); // We will detect this in the rendering loop } }); if (maximized) { glfwMaximizeWindow(windowHandle); } else { // Get the resolution of the primary monitor GLFWVidMode vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor()); // Center our window glfwSetWindowPos( windowHandle, (vidmode.width() - width) / 2, (vidmode.height() - height) / 2 ); } // Make the OpenGL context current glfwMakeContextCurrent(windowHandle); if (isvSync()) { // Enable v-sync glfwSwapInterval(1); } // Make the window visible glfwShowWindow(windowHandle); GL.createCapabilities(); // Set the clear color glClearColor(0.0f, 0.0f, 0.0f, 0.0f); glEnable(GL_DEPTH_TEST); if (opts.showTriangles) { glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); } // Support for transparencies glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); if (opts.cullFace) { glEnable(GL_CULL_FACE); glCullFace(GL_BACK); } }
Example #15
Source File: Window.java From lwjglbook with Apache License 2.0 | 4 votes |
public void init() { // Setup an error callback. The default implementation // will print the error message in System.err. GLFWErrorCallback.createPrint(System.err).set(); // Initialize GLFW. Most GLFW functions will not work before doing this. if (!glfwInit()) { throw new IllegalStateException("Unable to initialize GLFW"); } glfwDefaultWindowHints(); // optional, the current window hints are already the default glfwWindowHint(GLFW_VISIBLE, GL_FALSE); // the window will stay hidden after creation glfwWindowHint(GLFW_RESIZABLE, GL_TRUE); // the window will be resizable glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2); if (opts.compatibleProfile) { glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_COMPAT_PROFILE); } else { glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); } boolean maximized = false; // If no size has been specified set it to maximized state if (width == 0 || height == 0) { // Set up a fixed width and height so window initialization does not fail width = 100; height = 100; glfwWindowHint(GLFW_MAXIMIZED, GLFW_TRUE); maximized = true; } // Create the window windowHandle = glfwCreateWindow(width, height, title, NULL, NULL); if (windowHandle == NULL) { throw new RuntimeException("Failed to create the GLFW window"); } // Setup resize callback glfwSetFramebufferSizeCallback(windowHandle, (window, width, height) -> { this.width = width; this.height = height; this.setResized(true); }); // Setup a key callback. It will be called every time a key is pressed, repeated or released. glfwSetKeyCallback(windowHandle, (window, key, scancode, action, mods) -> { if (key == GLFW_KEY_ESCAPE && action == GLFW_RELEASE) { glfwSetWindowShouldClose(window, true); // We will detect this in the rendering loop } }); if (maximized) { glfwMaximizeWindow(windowHandle); } else { // Get the resolution of the primary monitor GLFWVidMode vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor()); // Center our window glfwSetWindowPos( windowHandle, (vidmode.width() - width) / 2, (vidmode.height() - height) / 2 ); } // Make the OpenGL context current glfwMakeContextCurrent(windowHandle); if (isvSync()) { // Enable v-sync glfwSwapInterval(1); } // Make the window visible glfwShowWindow(windowHandle); GL.createCapabilities(); // Set the clear color glClearColor(0.0f, 0.0f, 0.0f, 0.0f); glEnable(GL_DEPTH_TEST); if (opts.showTriangles) { glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); } // Support for transparencies glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); if (opts.cullFace) { glEnable(GL_CULL_FACE); glCullFace(GL_BACK); } }
Example #16
Source File: Window.java From lwjglbook with Apache License 2.0 | 4 votes |
public void init() { // Setup an error callback. The default implementation // will print the error message in System.err. GLFWErrorCallback.createPrint(System.err).set(); // Initialize GLFW. Most GLFW functions will not work before doing this. if (!glfwInit()) { throw new IllegalStateException("Unable to initialize GLFW"); } glfwDefaultWindowHints(); // optional, the current window hints are already the default glfwWindowHint(GLFW_VISIBLE, GL_FALSE); // the window will stay hidden after creation glfwWindowHint(GLFW_RESIZABLE, GL_TRUE); // the window will be resizable 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, GL_TRUE); boolean maximized = false; // If no size has been specified set it to maximized state if (width == 0 || height == 0) { // Set up a fixed width and height so window initialization does not fail width = 100; height = 100; glfwWindowHint(GLFW_MAXIMIZED, GLFW_TRUE); maximized = true; } // Create the window windowHandle = glfwCreateWindow(width, height, title, NULL, NULL); if (windowHandle == NULL) { throw new RuntimeException("Failed to create the GLFW window"); } // Setup resize callback glfwSetFramebufferSizeCallback(windowHandle, (window, width, height) -> { this.width = width; this.height = height; this.setResized(true); }); // Setup a key callback. It will be called every time a key is pressed, repeated or released. glfwSetKeyCallback(windowHandle, (window, key, scancode, action, mods) -> { if (key == GLFW_KEY_ESCAPE && action == GLFW_RELEASE) { glfwSetWindowShouldClose(window, true); // We will detect this in the rendering loop } }); if (maximized) { glfwMaximizeWindow(windowHandle); } else { // Get the resolution of the primary monitor GLFWVidMode vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor()); // Center our window glfwSetWindowPos( windowHandle, (vidmode.width() - width) / 2, (vidmode.height() - height) / 2 ); } // Make the OpenGL context current glfwMakeContextCurrent(windowHandle); if (isvSync()) { // Enable v-sync glfwSwapInterval(1); } // Make the window visible glfwShowWindow(windowHandle); GL.createCapabilities(); // Set the clear color glClearColor(0.0f, 0.0f, 0.0f, 0.0f); glEnable(GL_DEPTH_TEST); if (opts.showTriangles) { glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); } // Support for transparencies glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); if (opts.cullFace) { glEnable(GL_CULL_FACE); glCullFace(GL_BACK); } }
Example #17
Source File: Window.java From lwjglbook with Apache License 2.0 | 4 votes |
public void init() { // Setup an error callback. The default implementation // will print the error message in System.err. GLFWErrorCallback.createPrint(System.err).set(); // Initialize GLFW. Most GLFW functions will not work before doing this. if (!glfwInit()) { throw new IllegalStateException("Unable to initialize GLFW"); } glfwDefaultWindowHints(); // optional, the current window hints are already the default glfwWindowHint(GLFW_VISIBLE, GL_FALSE); // the window will stay hidden after creation glfwWindowHint(GLFW_RESIZABLE, GL_TRUE); // the window will be resizable 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, GL_TRUE); boolean maximized = false; // If no size has been specified set it to maximized state if (width == 0 || height == 0) { // Set up a fixed width and height so window initialization does not fail width = 100; height = 100; glfwWindowHint(GLFW_MAXIMIZED, GLFW_TRUE); maximized = true; } // Create the window windowHandle = glfwCreateWindow(width, height, title, NULL, NULL); if (windowHandle == NULL) { throw new RuntimeException("Failed to create the GLFW window"); } // Setup resize callback glfwSetFramebufferSizeCallback(windowHandle, (window, width, height) -> { this.width = width; this.height = height; this.setResized(true); }); // Setup a key callback. It will be called every time a key is pressed, repeated or released. glfwSetKeyCallback(windowHandle, (window, key, scancode, action, mods) -> { if (key == GLFW_KEY_ESCAPE && action == GLFW_RELEASE) { glfwSetWindowShouldClose(window, true); // We will detect this in the rendering loop } }); if (maximized) { glfwMaximizeWindow(windowHandle); } else { // Get the resolution of the primary monitor GLFWVidMode vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor()); // Center our window glfwSetWindowPos( windowHandle, (vidmode.width() - width) / 2, (vidmode.height() - height) / 2 ); } // Make the OpenGL context current glfwMakeContextCurrent(windowHandle); if (isvSync()) { // Enable v-sync glfwSwapInterval(1); } // Make the window visible glfwShowWindow(windowHandle); GL.createCapabilities(); // Set the clear color glClearColor(0.0f, 0.0f, 0.0f, 0.0f); glEnable(GL_DEPTH_TEST); if (opts.showTriangles) { glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); } // Support for transparencies glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); if (opts.cullFace) { glEnable(GL_CULL_FACE); glCullFace(GL_BACK); } }
Example #18
Source File: Window.java From lwjglbook with Apache License 2.0 | 4 votes |
public void init() { // Setup an error callback. The default implementation // will print the error message in System.err. GLFWErrorCallback.createPrint(System.err).set(); // Initialize GLFW. Most GLFW functions will not work before doing this. if (!glfwInit()) { throw new IllegalStateException("Unable to initialize GLFW"); } glfwDefaultWindowHints(); // optional, the current window hints are already the default glfwWindowHint(GLFW_VISIBLE, GL_FALSE); // the window will stay hidden after creation glfwWindowHint(GLFW_RESIZABLE, GL_TRUE); // the window will be resizable 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, GL_TRUE); // Create the window windowHandle = glfwCreateWindow(width, height, title, NULL, NULL); if (windowHandle == NULL) { throw new RuntimeException("Failed to create the GLFW window"); } // Setup resize callback glfwSetFramebufferSizeCallback(windowHandle, (window, width, height) -> { this.width = width; this.height = height; this.setResized(true); }); // Setup a key callback. It will be called every time a key is pressed, repeated or released. glfwSetKeyCallback(windowHandle, (window, key, scancode, action, mods) -> { if (key == GLFW_KEY_ESCAPE && action == GLFW_RELEASE) { glfwSetWindowShouldClose(window, true); // We will detect this in the rendering loop } }); // Get the resolution of the primary monitor GLFWVidMode vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor()); // Center our window glfwSetWindowPos( windowHandle, (vidmode.width() - width) / 2, (vidmode.height() - height) / 2 ); // Make the OpenGL context current glfwMakeContextCurrent(windowHandle); if (isvSync()) { // Enable v-sync glfwSwapInterval(1); } // Make the window visible glfwShowWindow(windowHandle); GL.createCapabilities(); // Set the clear color glClearColor(0.0f, 0.0f, 0.0f, 0.0f); glEnable(GL_DEPTH_TEST); }
Example #19
Source File: Window.java From lwjglbook with Apache License 2.0 | 4 votes |
public void init() { // Setup an error callback. The default implementation // will print the error message in System.err. GLFWErrorCallback.createPrint(System.err).set(); // Initialize GLFW. Most GLFW functions will not work before doing this. if (!glfwInit()) { throw new IllegalStateException("Unable to initialize GLFW"); } glfwDefaultWindowHints(); // optional, the current window hints are already the default glfwWindowHint(GLFW_VISIBLE, GL_FALSE); // the window will stay hidden after creation glfwWindowHint(GLFW_RESIZABLE, GL_TRUE); // the window will be resizable glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2); if (opts.compatibleProfile) { glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_COMPAT_PROFILE); } else { glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); } boolean maximized = false; // If no size has been specified set it to maximized state if (width == 0 || height == 0) { // Set up a fixed width and height so window initialization does not fail width = 100; height = 100; glfwWindowHint(GLFW_MAXIMIZED, GLFW_TRUE); maximized = true; } // Create the window windowHandle = glfwCreateWindow(width, height, title, NULL, NULL); if (windowHandle == NULL) { throw new RuntimeException("Failed to create the GLFW window"); } // Setup resize callback glfwSetFramebufferSizeCallback(windowHandle, (window, width, height) -> { this.width = width; this.height = height; this.setResized(true); }); // Setup a key callback. It will be called every time a key is pressed, repeated or released. glfwSetKeyCallback(windowHandle, (window, key, scancode, action, mods) -> { if (key == GLFW_KEY_ESCAPE && action == GLFW_RELEASE) { glfwSetWindowShouldClose(window, true); // We will detect this in the rendering loop } }); if (maximized) { glfwMaximizeWindow(windowHandle); } else { // Get the resolution of the primary monitor GLFWVidMode vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor()); // Center our window glfwSetWindowPos( windowHandle, (vidmode.width() - width) / 2, (vidmode.height() - height) / 2 ); } // Make the OpenGL context current glfwMakeContextCurrent(windowHandle); if (isvSync()) { // Enable v-sync glfwSwapInterval(1); } // Make the window visible glfwShowWindow(windowHandle); GL.createCapabilities(); // Set the clear color glClearColor(0.0f, 0.0f, 0.0f, 0.0f); glEnable(GL_DEPTH_TEST); glEnable(GL_STENCIL_TEST); if (opts.showTriangles) { glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); } // Support for transparencies glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); if (opts.cullFace) { glEnable(GL_CULL_FACE); glCullFace(GL_BACK); } // Antialiasing if (opts.antialiasing) { glfwWindowHint(GLFW_SAMPLES, 4); } }
Example #20
Source File: Window.java From lwjglbook with Apache License 2.0 | 4 votes |
public void init() { // Setup an error callback. The default implementation // will print the error message in System.err. GLFWErrorCallback.createPrint(System.err).set(); // Initialize GLFW. Most GLFW functions will not work before doing this. if (!glfwInit()) { throw new IllegalStateException("Unable to initialize GLFW"); } glfwDefaultWindowHints(); // optional, the current window hints are already the default glfwWindowHint(GLFW_VISIBLE, GL_FALSE); // the window will stay hidden after creation glfwWindowHint(GLFW_RESIZABLE, GL_TRUE); // the window will be resizable 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, GL_TRUE); // Create the window windowHandle = glfwCreateWindow(width, height, title, NULL, NULL); if (windowHandle == NULL) { throw new RuntimeException("Failed to create the GLFW window"); } // Setup resize callback glfwSetFramebufferSizeCallback(windowHandle, (window, width, height) -> { this.width = width; this.height = height; this.setResized(true); }); // Setup a key callback. It will be called every time a key is pressed, repeated or released. glfwSetKeyCallback(windowHandle, (window, key, scancode, action, mods) -> { if (key == GLFW_KEY_ESCAPE && action == GLFW_RELEASE) { glfwSetWindowShouldClose(window, true); // We will detect this in the rendering loop } }); // Get the resolution of the primary monitor GLFWVidMode vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor()); // Center our window glfwSetWindowPos( windowHandle, (vidmode.width() - width) / 2, (vidmode.height() - height) / 2 ); // Make the OpenGL context current glfwMakeContextCurrent(windowHandle); if (isvSync()) { // Enable v-sync glfwSwapInterval(1); } // Make the window visible glfwShowWindow(windowHandle); GL.createCapabilities(); // Set the clear color glClearColor(0.0f, 0.0f, 0.0f, 0.0f); }
Example #21
Source File: Window.java From lwjglbook with Apache License 2.0 | 4 votes |
public void init() { // Setup an error callback. The default implementation // will print the error message in System.err. GLFWErrorCallback.createPrint(System.err).set(); // Initialize GLFW. Most GLFW functions will not work before doing this. if (!glfwInit()) { throw new IllegalStateException("Unable to initialize GLFW"); } glfwDefaultWindowHints(); // optional, the current window hints are already the default glfwWindowHint(GLFW_VISIBLE, GL_FALSE); // the window will stay hidden after creation glfwWindowHint(GLFW_RESIZABLE, GL_TRUE); // the window will be resizable 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, GL_TRUE); // Create the window windowHandle = glfwCreateWindow(width, height, title, NULL, NULL); if (windowHandle == NULL) { throw new RuntimeException("Failed to create the GLFW window"); } // Setup resize callback glfwSetFramebufferSizeCallback(windowHandle, (window, width, height) -> { this.width = width; this.height = height; this.setResized(true); }); // Setup a key callback. It will be called every time a key is pressed, repeated or released. glfwSetKeyCallback(windowHandle, (window, key, scancode, action, mods) -> { if (key == GLFW_KEY_ESCAPE && action == GLFW_RELEASE) { glfwSetWindowShouldClose(window, true); // We will detect this in the rendering loop } }); // Get the resolution of the primary monitor GLFWVidMode vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor()); // Center our window glfwSetWindowPos( windowHandle, (vidmode.width() - width) / 2, (vidmode.height() - height) / 2 ); // Make the OpenGL context current glfwMakeContextCurrent(windowHandle); if (isvSync()) { // Enable v-sync glfwSwapInterval(1); } // Make the window visible glfwShowWindow(windowHandle); GL.createCapabilities(); // Set the clear color glClearColor(0.0f, 0.0f, 0.0f, 0.0f); }
Example #22
Source File: Window.java From lwjglbook with Apache License 2.0 | 4 votes |
public void init() { // Setup an error callback. The default implementation // will print the error message in System.err. GLFWErrorCallback.createPrint(System.err).set(); // Initialize GLFW. Most GLFW functions will not work before doing this. if (!glfwInit()) { throw new IllegalStateException("Unable to initialize GLFW"); } glfwDefaultWindowHints(); // optional, the current window hints are already the default glfwWindowHint(GLFW_VISIBLE, GL_FALSE); // the window will stay hidden after creation glfwWindowHint(GLFW_RESIZABLE, GL_TRUE); // the window will be resizable 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, GL_TRUE); // Create the window windowHandle = glfwCreateWindow(width, height, title, NULL, NULL); if (windowHandle == NULL) { throw new RuntimeException("Failed to create the GLFW window"); } // Setup resize callback glfwSetFramebufferSizeCallback(windowHandle, (window, width, height) -> { this.width = width; this.height = height; this.setResized(true); }); // Setup a key callback. It will be called every time a key is pressed, repeated or released. glfwSetKeyCallback(windowHandle, (window, key, scancode, action, mods) -> { if (key == GLFW_KEY_ESCAPE && action == GLFW_RELEASE) { glfwSetWindowShouldClose(window, true); // We will detect this in the rendering loop } }); // Get the resolution of the primary monitor GLFWVidMode vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor()); // Center our window glfwSetWindowPos( windowHandle, (vidmode.width() - width) / 2, (vidmode.height() - height) / 2 ); // Make the OpenGL context current glfwMakeContextCurrent(windowHandle); if (isvSync()) { // Enable v-sync glfwSwapInterval(1); } // Make the window visible glfwShowWindow(windowHandle); GL.createCapabilities(); // Set the clear color glClearColor(0.0f, 0.0f, 0.0f, 0.0f); }
Example #23
Source File: Window.java From lwjglbook with Apache License 2.0 | 4 votes |
public void init() { // Setup an error callback. The default implementation // will print the error message in System.err. GLFWErrorCallback.createPrint(System.err).set(); // Initialize GLFW. Most GLFW functions will not work before doing this. if (!glfwInit()) { throw new IllegalStateException("Unable to initialize GLFW"); } glfwDefaultWindowHints(); // optional, the current window hints are already the default glfwWindowHint(GLFW_VISIBLE, GL_FALSE); // the window will stay hidden after creation glfwWindowHint(GLFW_RESIZABLE, GL_TRUE); // the window will be resizable 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, GL_TRUE); // Create the window windowHandle = glfwCreateWindow(width, height, title, NULL, NULL); if (windowHandle == NULL) { throw new RuntimeException("Failed to create the GLFW window"); } // Setup resize callback glfwSetFramebufferSizeCallback(windowHandle, (window, width, height) -> { this.width = width; this.height = height; this.setResized(true); }); // Setup a key callback. It will be called every time a key is pressed, repeated or released. glfwSetKeyCallback(windowHandle, (window, key, scancode, action, mods) -> { if (key == GLFW_KEY_ESCAPE && action == GLFW_RELEASE) { glfwSetWindowShouldClose(window, true); // We will detect this in the rendering loop } }); // Get the resolution of the primary monitor GLFWVidMode vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor()); // Center our window glfwSetWindowPos( windowHandle, (vidmode.width() - width) / 2, (vidmode.height() - height) / 2 ); // Make the OpenGL context current glfwMakeContextCurrent(windowHandle); if (isvSync()) { // Enable v-sync glfwSwapInterval(1); } // Make the window visible glfwShowWindow(windowHandle); GL.createCapabilities(); // Set the clear color glClearColor(0.0f, 0.0f, 0.0f, 0.0f); glEnable(GL_DEPTH_TEST); }
Example #24
Source File: Window.java From lwjglbook with Apache License 2.0 | 4 votes |
public void init() { // Setup an error callback. The default implementation // will print the error message in System.err. GLFWErrorCallback.createPrint(System.err).set(); // Initialize GLFW. Most GLFW functions will not work before doing this. if (!glfwInit()) { throw new IllegalStateException("Unable to initialize GLFW"); } glfwDefaultWindowHints(); // optional, the current window hints are already the default glfwWindowHint(GLFW_VISIBLE, GL_FALSE); // the window will stay hidden after creation glfwWindowHint(GLFW_RESIZABLE, GL_TRUE); // the window will be resizable glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2); if (opts.compatibleProfile) { glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_COMPAT_PROFILE); } else { glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); } boolean maximized = false; // If no size has been specified set it to maximized state if (width == 0 || height == 0) { // Set up a fixed width and height so window initialization does not fail width = 100; height = 100; glfwWindowHint(GLFW_MAXIMIZED, GLFW_TRUE); maximized = true; } // Create the window windowHandle = glfwCreateWindow(width, height, title, NULL, NULL); if (windowHandle == NULL) { throw new RuntimeException("Failed to create the GLFW window"); } glfwSetFramebufferSizeCallback(windowHandle, (window, width, height) -> { this.width = width; this.height = height; this.setResized(true); }); // Setup a key callback. It will be called every time a key is pressed, repeated or released. glfwSetKeyCallback(windowHandle, (window, key, scancode, action, mods) -> { if (key == GLFW_KEY_ESCAPE && action == GLFW_RELEASE) { glfwSetWindowShouldClose(window, true); // We will detect this in the rendering loop } }); if (maximized) { glfwMaximizeWindow(windowHandle); } else { // Get the resolution of the primary monitor GLFWVidMode vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor()); // Center our window glfwSetWindowPos( windowHandle, (vidmode.width() - width) / 2, (vidmode.height() - height) / 2 ); } // Make the OpenGL context current glfwMakeContextCurrent(windowHandle); if (isvSync()) { // Enable v-sync glfwSwapInterval(1); } // Make the window visible glfwShowWindow(windowHandle); GL.createCapabilities(); // Set the clear color glClearColor(0.0f, 0.0f, 0.0f, 0.0f); glEnable(GL_DEPTH_TEST); glEnable(GL_STENCIL_TEST); if (opts.showTriangles) { glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); } // Support for transparencies glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); if (opts.cullFace) { glEnable(GL_CULL_FACE); glCullFace(GL_BACK); } // Antialiasing if (opts.antialiasing) { glfwWindowHint(GLFW_SAMPLES, 4); } }
Example #25
Source File: OpenGLWindow.java From caliko with MIT License | 4 votes |
public OpenGLWindow(int windowWidth, int windowHeight, float vertFoVDegs, float zNear, float zFar, float orthoExtent) { // Set properties and create the projection matrix mWindowWidth = windowWidth <= 0 ? 1 : windowWidth; mWindowHeight = windowHeight <= 0 ? 1 : windowHeight; mAspectRatio = (float)mWindowWidth / (float)mWindowHeight; mVertFoVDegs = vertFoVDegs; mZNear = zNear; mZFar = zFar; mOrthoExtent = orthoExtent; if (Application.use3dDemo) { mOrthographicProjection = false; mProjectionMatrix = Mat4f.createPerspectiveProjectionMatrix(mVertFoVDegs, mAspectRatio, mZNear, mZFar); } else { mOrthographicProjection = true; mProjectionMatrix = Mat4f.createOrthographicProjectionMatrix(-mOrthoExtent, mOrthoExtent, mOrthoExtent, -mOrthoExtent, mZNear, mZFar); } // Setup the error callback to output to System.err glfwSetErrorCallback(errorCallback = GLFWErrorCallback.createPrint(System.err)); // Initialize GLFW. Most GLFW functions will not work before doing this. if ( !glfwInit() ) { throw new IllegalStateException("Unable to initialize GLFW"); } // ----- Specify window hints ----- // Note: Window hints must be specified after glfwInit() (which resets them) and before glfwCreateWindow where the context is created. glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); // Request OpenGL version 3.3 (the minimum we can get away with) glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); // We want a core profile without any deprecated functionality... //glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); // ...however we do NOT want a forward compatible profile as they've removed line widths! glfwWindowHint(GLFW_RESIZABLE, GLFW_TRUE); // We want the window to be resizable glfwWindowHint(GLFW_VISIBLE, GLFW_TRUE); // We want the window to be visible (false makes it hidden after creation) glfwWindowHint(GLFW_FOCUSED, GLFW_TRUE); // We want the window to take focus on creation glfwWindowHint(GLFW_SAMPLES, 4); // Ask for 4x anti-aliasing (this doesn't mean we'll get it, though) // Create the window mWindowId = glfwCreateWindow(mWindowWidth, mWindowHeight, "LWJGL3 Test", NULL, NULL); if (mWindowId == NULL) { throw new RuntimeException("Failed to create the GLFW window"); } // Get the resolution of the primary monitor GLFWVidMode vidmode = glfwGetVideoMode( glfwGetPrimaryMonitor() ); int windowHorizOffset = (vidmode.width() - mWindowWidth) / 2; int windowVertOffset = (vidmode.height() - mWindowHeight) / 2; glfwSetWindowPos(mWindowId, windowHorizOffset, windowVertOffset); // Center our window glfwMakeContextCurrent(mWindowId); // Make the OpenGL context current glfwSwapInterval(1); // Swap buffers every frame (i.e. enable vSync) // This line is critical for LWJGL's interoperation with GLFW's OpenGL context, or any context that is managed externally. // LWJGL detects the context that is current in the current thread, creates the ContextCapabilities instance and makes // the OpenGL bindings available for use. glfwMakeContextCurrent(mWindowId); // Enumerate the capabilities of the current OpenGL context, loading forward compatible capabilities GL.createCapabilities(true); // Setup our keyboard, mouse and window resize callback functions setupCallbacks(); // ---------- OpenGL settings ----------- // Set the clear color glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // Specify the size of the viewport. Params: xOrigin, yOrigin, width, height glViewport(0, 0, mWindowWidth, mWindowHeight); // Enable depth testing glDepthFunc(GL_LEQUAL); glEnable(GL_DEPTH_TEST); // When we clear the depth buffer, we'll clear the entire buffer glClearDepth(1.0f); // Enable blending to use alpha channels // Note: blending must be enabled to use transparency / alpha values in our fragment shaders. glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_BLEND); glfwShowWindow(mWindowId); // Make the window visible }
Example #26
Source File: Window.java From lwjglbook with Apache License 2.0 | 4 votes |
public void init() { // Setup an error callback. The default implementation // will print the error message in System.err. GLFWErrorCallback.createPrint(System.err).set(); // Initialize GLFW. Most GLFW functions will not work before doing this. if (!glfwInit()) { throw new IllegalStateException("Unable to initialize GLFW"); } glfwDefaultWindowHints(); // optional, the current window hints are already the default glfwWindowHint(GLFW_VISIBLE, GL_FALSE); // the window will stay hidden after creation glfwWindowHint(GLFW_RESIZABLE, GL_TRUE); // the window will be resizable 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, GL_TRUE); boolean maximized = false; // If no size has been specified set it to maximized state if (width == 0 || height == 0) { // Set up a fixed width and height so window initialization does not fail width = 100; height = 100; glfwWindowHint(GLFW_MAXIMIZED, GLFW_TRUE); maximized = true; } // Create the window windowHandle = glfwCreateWindow(width, height, title, NULL, NULL); if (windowHandle == NULL) { throw new RuntimeException("Failed to create the GLFW window"); } // Setup resize callback glfwSetFramebufferSizeCallback(windowHandle, (window, width, height) -> { this.width = width; this.height = height; this.setResized(true); }); // Setup a key callback. It will be called every time a key is pressed, repeated or released. glfwSetKeyCallback(windowHandle, (window, key, scancode, action, mods) -> { if (key == GLFW_KEY_ESCAPE && action == GLFW_RELEASE) { glfwSetWindowShouldClose(window, true); // We will detect this in the rendering loop } }); if (maximized) { glfwMaximizeWindow(windowHandle); } else { // Get the resolution of the primary monitor GLFWVidMode vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor()); // Center our window glfwSetWindowPos( windowHandle, (vidmode.width() - width) / 2, (vidmode.height() - height) / 2 ); } // Make the OpenGL context current glfwMakeContextCurrent(windowHandle); if (isvSync()) { // Enable v-sync glfwSwapInterval(1); } // Make the window visible glfwShowWindow(windowHandle); GL.createCapabilities(); // Set the clear color glClearColor(0.0f, 0.0f, 0.0f, 0.0f); glEnable(GL_DEPTH_TEST); //glPolygonMode( GL_FRONT_AND_BACK, GL_LINE ); // Support for transparencies glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_CULL_FACE); glCullFace(GL_BACK); }
Example #27
Source File: Window.java From lwjglbook with Apache License 2.0 | 4 votes |
public void init() { // Setup an error callback. The default implementation // will print the error message in System.err. GLFWErrorCallback.createPrint(System.err).set(); // Initialize GLFW. Most GLFW functions will not work before doing this. if (!glfwInit()) { throw new IllegalStateException("Unable to initialize GLFW"); } glfwDefaultWindowHints(); // optional, the current window hints are already the default glfwWindowHint(GLFW_VISIBLE, GL_FALSE); // the window will stay hidden after creation glfwWindowHint(GLFW_RESIZABLE, GL_TRUE); // the window will be resizable 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, GL_TRUE); boolean maximized = false; // If no size has been specified set it to maximized state if (width == 0 || height == 0) { // Set up a fixed width and height so window initialization does not fail width = 100; height = 100; glfwWindowHint(GLFW_MAXIMIZED, GLFW_TRUE); maximized = true; } // Create the window windowHandle = glfwCreateWindow(width, height, title, NULL, NULL); if (windowHandle == NULL) { throw new RuntimeException("Failed to create the GLFW window"); } // Setup resize callback glfwSetFramebufferSizeCallback(windowHandle, (window, width, height) -> { this.width = width; this.height = height; this.setResized(true); }); // Setup a key callback. It will be called every time a key is pressed, repeated or released. glfwSetKeyCallback(windowHandle, (window, key, scancode, action, mods) -> { if (key == GLFW_KEY_ESCAPE && action == GLFW_RELEASE) { glfwSetWindowShouldClose(window, true); // We will detect this in the rendering loop } }); if (maximized) { glfwMaximizeWindow(windowHandle); } else { // Get the resolution of the primary monitor GLFWVidMode vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor()); // Center our window glfwSetWindowPos( windowHandle, (vidmode.width() - width) / 2, (vidmode.height() - height) / 2 ); } // Make the OpenGL context current glfwMakeContextCurrent(windowHandle); if (isvSync()) { // Enable v-sync glfwSwapInterval(1); } // Make the window visible glfwShowWindow(windowHandle); GL.createCapabilities(); // Set the clear color glClearColor(0.0f, 0.0f, 0.0f, 0.0f); glEnable(GL_DEPTH_TEST); //glPolygonMode( GL_FRONT_AND_BACK, GL_LINE ); // Support for transparencies glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_CULL_FACE); glCullFace(GL_BACK); }
Example #28
Source File: Window.java From lwjglbook with Apache License 2.0 | 4 votes |
public void init() { // Setup an error callback. The default implementation // will print the error message in System.err. GLFWErrorCallback.createPrint(System.err).set(); // Initialize GLFW. Most GLFW functions will not work before doing this. if (!glfwInit()) { throw new IllegalStateException("Unable to initialize GLFW"); } glfwDefaultWindowHints(); // optional, the current window hints are already the default glfwWindowHint(GLFW_VISIBLE, GL_FALSE); // the window will stay hidden after creation glfwWindowHint(GLFW_RESIZABLE, GL_TRUE); // the window will be resizable glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2); if (opts.compatibleProfile) { glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_COMPAT_PROFILE); } else { glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); } boolean maximized = false; // If no size has been specified set it to maximized state if (width == 0 || height == 0) { // Set up a fixed width and height so window initialization does not fail width = 100; height = 100; glfwWindowHint(GLFW_MAXIMIZED, GLFW_TRUE); maximized = true; } // Create the window windowHandle = glfwCreateWindow(width, height, title, NULL, NULL); if (windowHandle == NULL) { throw new RuntimeException("Failed to create the GLFW window"); } glfwSetFramebufferSizeCallback(windowHandle, (window, width, height) -> { this.width = width; this.height = height; this.setResized(true); }); // Setup a key callback. It will be called every time a key is pressed, repeated or released. glfwSetKeyCallback(windowHandle, (window, key, scancode, action, mods) -> { if (key == GLFW_KEY_ESCAPE && action == GLFW_RELEASE) { glfwSetWindowShouldClose(window, true); // We will detect this in the rendering loop } }); if (maximized) { glfwMaximizeWindow(windowHandle); } else { // Get the resolution of the primary monitor GLFWVidMode vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor()); // Center our window glfwSetWindowPos( windowHandle, (vidmode.width() - width) / 2, (vidmode.height() - height) / 2 ); } // Make the OpenGL context current glfwMakeContextCurrent(windowHandle); if (isvSync()) { // Enable v-sync glfwSwapInterval(1); } // Make the window visible glfwShowWindow(windowHandle); GL.createCapabilities(); // Set the clear color glClearColor(0.0f, 0.0f, 0.0f, 0.0f); glEnable(GL_DEPTH_TEST); glEnable(GL_STENCIL_TEST); if (opts.showTriangles) { glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); } if (opts.cullFace) { glEnable(GL_CULL_FACE); glCullFace(GL_BACK); } // Antialiasing if (opts.antialiasing) { glfwWindowHint(GLFW_SAMPLES, 4); } }
Example #29
Source File: Window.java From lwjglbook with Apache License 2.0 | 4 votes |
public void init() { // Setup an error callback. The default implementation // will print the error message in System.err. GLFWErrorCallback.createPrint(System.err).set(); // Initialize GLFW. Most GLFW functions will not work before doing this. if (!glfwInit()) { throw new IllegalStateException("Unable to initialize GLFW"); } glfwDefaultWindowHints(); // optional, the current window hints are already the default glfwWindowHint(GLFW_VISIBLE, GL_FALSE); // the window will stay hidden after creation glfwWindowHint(GLFW_RESIZABLE, GL_TRUE); // the window will be resizable glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2); if (opts.compatibleProfile) { glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_COMPAT_PROFILE); } else { glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); } boolean maximized = false; // If no size has been specified set it to maximized state if (width == 0 || height == 0) { // Set up a fixed width and height so window initialization does not fail width = 100; height = 100; glfwWindowHint(GLFW_MAXIMIZED, GLFW_TRUE); maximized = true; } // Create the window windowHandle = glfwCreateWindow(width, height, title, NULL, NULL); if (windowHandle == NULL) { throw new RuntimeException("Failed to create the GLFW window"); } // Setup resize callback glfwSetFramebufferSizeCallback(windowHandle, (window, width, height) -> { this.width = width; this.height = height; this.setResized(true); }); // Setup a key callback. It will be called every time a key is pressed, repeated or released. glfwSetKeyCallback(windowHandle, (window, key, scancode, action, mods) -> { if (key == GLFW_KEY_ESCAPE && action == GLFW_RELEASE) { glfwSetWindowShouldClose(window, true); // We will detect this in the rendering loop } }); if (maximized) { glfwMaximizeWindow(windowHandle); } else { // Get the resolution of the primary monitor GLFWVidMode vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor()); // Center our window glfwSetWindowPos( windowHandle, (vidmode.width() - width) / 2, (vidmode.height() - height) / 2 ); } // Make the OpenGL context current glfwMakeContextCurrent(windowHandle); if (isvSync()) { // Enable v-sync glfwSwapInterval(1); } // Make the window visible glfwShowWindow(windowHandle); GL.createCapabilities(); // Set the clear color glClearColor(0.0f, 0.0f, 0.0f, 0.0f); glEnable(GL_DEPTH_TEST); glEnable(GL_STENCIL_TEST); if (opts.showTriangles) { glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); } // Support for transparencies glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); if (opts.cullFace) { glEnable(GL_CULL_FACE); glCullFace(GL_BACK); } // Antialiasing if (opts.antialiasing) { glfwWindowHint(GLFW_SAMPLES, 4); } }
Example #30
Source File: Window.java From lwjglbook with Apache License 2.0 | 4 votes |
public void init() { // Setup an error callback. The default implementation // will print the error message in System.err. GLFWErrorCallback.createPrint(System.err).set(); // Initialize GLFW. Most GLFW functions will not work before doing this. if (!glfwInit()) { throw new IllegalStateException("Unable to initialize GLFW"); } glfwDefaultWindowHints(); // optional, the current window hints are already the default glfwWindowHint(GLFW_VISIBLE, GL_FALSE); // the window will stay hidden after creation glfwWindowHint(GLFW_RESIZABLE, GL_TRUE); // the window will be resizable glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2); if (opts.compatibleProfile) { glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_COMPAT_PROFILE); } else { glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); } boolean maximized = false; // If no size has been specified set it to maximized state if (width == 0 || height == 0) { // Set up a fixed width and height so window initialization does not fail width = 100; height = 100; glfwWindowHint(GLFW_MAXIMIZED, GLFW_TRUE); maximized = true; } // Create the window windowHandle = glfwCreateWindow(width, height, title, NULL, NULL); if (windowHandle == NULL) { throw new RuntimeException("Failed to create the GLFW window"); } glfwSetFramebufferSizeCallback(windowHandle, (window, width, height) -> { this.width = width; this.height = height; this.setResized(true); }); // Setup a key callback. It will be called every time a key is pressed, repeated or released. glfwSetKeyCallback(windowHandle, (window, key, scancode, action, mods) -> { if (key == GLFW_KEY_ESCAPE && action == GLFW_RELEASE) { glfwSetWindowShouldClose(window, true); // We will detect this in the rendering loop } }); if (maximized) { glfwMaximizeWindow(windowHandle); } else { // Get the resolution of the primary monitor GLFWVidMode vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor()); // Center our window glfwSetWindowPos( windowHandle, (vidmode.width() - width) / 2, (vidmode.height() - height) / 2 ); } // Make the OpenGL context current glfwMakeContextCurrent(windowHandle); if (isvSync()) { // Enable v-sync glfwSwapInterval(1); } // Make the window visible glfwShowWindow(windowHandle); GL.createCapabilities(); // Set the clear color glClearColor(0.0f, 0.0f, 0.0f, 0.0f); glEnable(GL_DEPTH_TEST); glEnable(GL_STENCIL_TEST); if (opts.showTriangles) { glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); } // Support for transparencies glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); if (opts.cullFace) { glEnable(GL_CULL_FACE); glCullFace(GL_BACK); } // Antialiasing if (opts.antialiasing) { glfwWindowHint(GLFW_SAMPLES, 4); } }