Java Code Examples for org.lwjgl.opengl.GL#createCapabilities()
The following examples show how to use
org.lwjgl.opengl.GL#createCapabilities() .
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: GLWindow.java From oreon-engine with GNU General Public License v3.0 | 6 votes |
public void create() { glfwWindowHint(GLFW_RESIZABLE, GL_TRUE); glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); setId(glfwCreateWindow(getWidth(), getHeight(), getTitle(), 0, 0)); if(getId() == 0) { throw new RuntimeException("Failed to create window"); } setIcon("textures/logo/oreon_lwjgl_icon32.png"); glfwMakeContextCurrent(getId()); glfwSwapInterval(0); if (BaseContext.getConfig().isGlfwGLVSync()){ WGLEXTSwapControl.wglSwapIntervalEXT(1); glfwSwapInterval(1); } GL.createCapabilities(); }
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: OpenGLAPI.java From WraithEngine with Apache License 2.0 | 5 votes |
@Override public void init() { GL.createCapabilities(); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); if (debugMode) GLUtil.setupDebugMessageCallback(new PrintStream(new OutputStreamWrapper(LogLevel.DEBUG, new LoggerAPI()))); }
Example 4
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 5
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 6
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 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); 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 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); 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 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); 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 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); // 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 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"); } 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 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); 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 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); //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 17
Source File: DrawOnDemandTest.java From lwjgl3-awt with MIT License | 4 votes |
public static void main(String[] args) { AWTGLCanvas canvas = new AWTGLCanvas() { private static final long serialVersionUID = 1L; @Override public void initGL() { GL.createCapabilities(); glClearColor(0.3f, 0.4f, 0.5f, 1); } @Override public void paintGL() { int w = getWidth(); int h = getHeight(); if (w == 0 || h == 0) { return; } float aspect = (float) w / h; GL11.glClear(GL11.GL_COLOR_BUFFER_BIT); GL11.glViewport(0, 0, w, h); GL11.glBegin(GL11.GL_QUADS); GL11.glColor3f(quadColor.getRed()/255f, quadColor.getGreen()/255f, quadColor.getBlue()/255f); GL11.glVertex2f(-0.75f / aspect, 0.0f); GL11.glVertex2f(0, -0.75f); GL11.glVertex2f(+0.75f / aspect, 0); GL11.glVertex2f(0, +0.75f); GL11.glEnd(); swapBuffers(); } @Override public void repaint() { if (SwingUtilities.isEventDispatchThread()) { render(); } else { SwingUtilities.invokeLater(() -> render()); } } }; JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.getContentPane().setLayout(new BorderLayout()); frame.getContentPane().add(canvas, BorderLayout.CENTER); canvas.setPreferredSize(new Dimension(200, 200)); canvas.addComponentListener(new ComponentAdapter() { public void componentResized(java.awt.event.ComponentEvent e) { canvas.repaint(); }; }); JColorChooser colorChooser = new JColorChooser(quadColor); frame.getContentPane().add(colorChooser, BorderLayout.SOUTH); colorChooser.getSelectionModel().addChangeListener((e)->{ quadColor = colorChooser.getColor(); canvas.repaint(); }); SwingUtilities.invokeLater(() -> { frame.pack(); frame.setVisible(true); }); }
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); //glPolygonMode( GL_FRONT_AND_BACK, GL_LINE ); }
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); glEnable(GL_DEPTH_TEST); }