org.lwjgl.opengl.GL Java Examples
The following examples show how to use
org.lwjgl.opengl.GL.
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: WindowManager.java From LWJGUI with MIT License | 6 votes |
/** * Method provided for migration of project into the new multi-thread system. * Generates a {@link Window} from a native glfwWindow * * <p> * This function must only be called from the main thread. * </p> * * @param windowID * @return */ public static Window generateWindow(long windowID) { // Initialize window manager if ( mainThread == -1 ) WindowManager.init(); Window window = new Window(windowID, 0, 0, ""); LWJGUI.setThreadWindow(window); window.capabilities = GL.getCapabilities(); window.init(); int[] h = new int[1]; int[] w = new int[1]; glfwGetFramebufferSize(windowID, w, h); window.framebufferHeight = h[0]; window.framebufferWidth = w[0]; glfwGetWindowSize(windowID, w, h); window.height = h[0]; window.width = w[0]; window.pixelRatio = (float) window.framebufferWidth / (float) window.width; window.lastLoopTime = getTime(); window.created = true; return window; }
Example #2
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 #3
Source File: OpenGLRenderer.java From ldparteditor with MIT License | 6 votes |
/** * Disposes old textures */ public synchronized void disposeOldTextures() { final GLCanvas canvas = c3d.getCanvas(); if (!canvas.isCurrent()) { canvas.setCurrent(); GL.setCapabilities(c3d.getCapabilities()); } Iterator<GTexture> ti = textureSet.iterator(); for (GTexture tex = null; ti.hasNext() && (tex = ti.next()) != null;) { if (tex.isTooOld()) { NLogger.debug(getClass(), "Dispose old texture: {0}", tex); //$NON-NLS-1$ tex.dispose(this); ti.remove(); } } }
Example #4
Source File: vboWithRGBA.java From ldparteditor with MIT License | 6 votes |
@Override public void drawScene(float mouseX, float mouseY) { final GLCanvas canvas = cp.getCanvas(); if (!canvas.isCurrent()) { canvas.setCurrent(); GL.setCapabilities(cp.getCapabilities()); } GL11.glColorMask(true, true, true, true); GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT | GL11.GL_STENCIL_BUFFER_BIT); Rectangle bounds = cp.getBounds(); GL11.glViewport(0, 0, bounds.width, bounds.height); shaderProgram.use(); GL30.glBindVertexArray(VAO); GL11.glDrawArrays(GL11.GL_TRIANGLES, 0, 3); GL30.glBindVertexArray(0); canvas.swapBuffers(); }
Example #5
Source File: vboWithIndices.java From ldparteditor with MIT License | 6 votes |
@Override public void drawScene(float mouseX, float mouseY) { final GLCanvas canvas = cp.getCanvas(); if (!canvas.isCurrent()) { canvas.setCurrent(); GL.setCapabilities(cp.getCapabilities()); } GL11.glColorMask(true, true, true, true); GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT | GL11.GL_STENCIL_BUFFER_BIT); Rectangle bounds = cp.getBounds(); GL11.glViewport(0, 0, bounds.width, bounds.height); shaderProgram.use(); GL30.glBindVertexArray(VAO); // GL20.glEnableVertexAttribArray(POSITION_SHADER_LOCATION); // <-- Not necessary! GL11.glDrawElements(GL11.GL_TRIANGLES, 6, GL11.GL_UNSIGNED_INT, 0); // GL20.glDisableVertexAttribArray(POSITION_SHADER_LOCATION); // <-- Not necessary! GL30.glBindVertexArray(0); canvas.swapBuffers(); }
Example #6
Source File: Window.java From mars-sim with GNU General Public License v3.0 | 5 votes |
public void create() { if (!GLFW.glfwInit()) { System.err.println("ERROR: GLFW wasn't initializied"); return; } input = new Input(); window = GLFW.glfwCreateWindow(width, height, title, isFullscreen ? GLFW.glfwGetPrimaryMonitor() : 0, 0); if (window == 0) { System.err.println("ERROR: Window wasn't created"); return; } GLFWVidMode videoMode = GLFW.glfwGetVideoMode(GLFW.glfwGetPrimaryMonitor()); windowPosX[0] = (videoMode.width() - width) / 2; windowPosY[0] = (videoMode.height() - height) / 2; GLFW.glfwSetWindowPos(window, windowPosX[0], windowPosY[0]); GLFW.glfwMakeContextCurrent(window); GL.createCapabilities(); GL11.glEnable(GL11.GL_DEPTH_TEST); createCallbacks(); GLFW.glfwShowWindow(window); GLFW.glfwSwapInterval(1); time = System.currentTimeMillis(); System.out.println("OpenGL version: " + GL11.glGetString(GL11.GL_VERSION)); }
Example #7
Source File: OpenGLUtils.java From CodeChickenLib with GNU Lesser General Public License v2.1 | 5 votes |
public static void onModelRegistryEvent(ModelRegistryEvent event) { GLCapabilities caps = GL.getCapabilities(); openGL20 = caps.OpenGL20; openGL21 = caps.OpenGL21; openGL32 = caps.OpenGL32; openGL40 = caps.OpenGL40; openGL43 = caps.OpenGL43; openGL44 = caps.OpenGL44; openGL45 = caps.OpenGL45; openGL46 = caps.OpenGL46; }
Example #8
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 #9
Source File: Window.java From Lwjgl3-Game-Engine-Programming-Series with MIT License | 5 votes |
public void create(int width, int height) { setWidth(width); setHeight(height); 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); window = glfwCreateWindow(width, height, "OREON ENGINE Programming Tutorial Series", 0, 0); if(window == 0) { throw new RuntimeException("Failed to create window"); } ByteBuffer bufferedImage = ImageLoader.loadImageToByteBuffer("./res/logo/oreon_lwjgl_icon32.png"); GLFWImage image = GLFWImage.malloc(); image.set(32, 32, bufferedImage); GLFWImage.Buffer images = GLFWImage.malloc(1); images.put(0, image); glfwSetWindowIcon(window, images); glfwMakeContextCurrent(window); GL.createCapabilities(); glfwShowWindow(window); }
Example #10
Source File: LWJGUIUtil.java From LWJGUI with MIT License | 5 votes |
private static long createOpenGLWindow(String name, int width, int height, boolean resizable, boolean ontop, boolean modernOpenGL, boolean vsync) { // Configure GLFW glfwDefaultWindowHints(); glfwWindowHint(GLFW_VISIBLE, GL_FALSE); glfwWindowHint(GLFW_RESIZABLE, GL_TRUE); // Hints hints(modernOpenGL); glfwWindowHint(GLFW.GLFW_FLOATING, ontop?GL_TRUE:GL_FALSE); glfwWindowHint(GLFW.GLFW_RESIZABLE, resizable?GL_TRUE:GL_FALSE); // Create the window long window = glfwCreateWindow(width, height, name, NULL, NULL); if ( window == NULL ) throw new RuntimeException("Failed to create the GLFW window"); // Finalize window glfwMakeContextCurrent(window); glfwSwapInterval(vsync ? 1 : 0); // Get the resolution of the primary monitor GLFWVidMode vidmode = GLFW.glfwGetVideoMode(GLFW.glfwGetPrimaryMonitor()); // Center the window GLFW.glfwSetWindowPos( window, (vidmode.width() - width) / 2, (vidmode.height() - height) / 2 ); // Create context GL.createCapabilities(); System.out.println("Creating opengl window: " + glGetString(GL_VERSION)); return window; }
Example #11
Source File: WindowManager.java From LWJGUI with MIT License | 5 votes |
/** * Creates OpenGL and NanoVG contexts in the caller's thread. * * @param handle * @param window * @param vsync */ public static void createWindow(WindowHandle handle, Window window, boolean vsync) { long windowID = window.getID(); glfwMakeContextCurrent(windowID); glfwSwapInterval(vsync ? 1 : 0); window.capabilities = GL.createCapabilities(!handle.legacyGL); window.init(); window.lastLoopTime = getTime(); window.resetViewport(); window.created = true; }
Example #12
Source File: DesktopMini2DxGame.java From mini2Dx with Apache License 2.0 | 5 votes |
/** * Enables or disables GL debug messages for the specified severity level. Returns false if the severity * level could not be set (e.g. the NOTIFICATION level is not supported by the ARB and AMD extensions). * * See {@link Lwjgl3ApplicationConfiguration#enableGLDebugOutput(boolean, PrintStream)} */ public static boolean setGLDebugMessageControl (GLDebugMessageSeverity severity, boolean enabled) { GLCapabilities caps = GL.getCapabilities(); final int GL_DONT_CARE = 0x1100; // not defined anywhere yet if (caps.OpenGL43) { GL43.glDebugMessageControl(GL_DONT_CARE, GL_DONT_CARE, severity.gl43, (IntBuffer) null, enabled); return true; } if (caps.GL_KHR_debug) { KHRDebug.glDebugMessageControl(GL_DONT_CARE, GL_DONT_CARE, severity.khr, (IntBuffer) null, enabled); return true; } if (caps.GL_ARB_debug_output && severity.arb != -1) { ARBDebugOutput.glDebugMessageControlARB(GL_DONT_CARE, GL_DONT_CARE, severity.arb, (IntBuffer) null, enabled); return true; } if (caps.GL_AMD_debug_output && severity.amd != -1) { AMDDebugOutput.glDebugMessageEnableAMD(GL_DONT_CARE, severity.amd, (IntBuffer) null, enabled); return true; } return false; }
Example #13
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 #14
Source File: GLTexture.java From oreon-engine with GNU General Public License v3.0 | 5 votes |
public void anisotropicFilter(){ if (GL.getCapabilities().GL_EXT_texture_filter_anisotropic){ float maxfilterLevel = glGetFloat(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT); glTexParameterf(target, GL_TEXTURE_MAX_ANISOTROPY_EXT, maxfilterLevel); } else{ System.err.println("anisotropic not supported"); } }
Example #15
Source File: Window.java From LWJGUI with MIT License | 5 votes |
/** * Unloads any native resource, destroys the OpenGL context and it's data. * * <p> * This function must only be called from the window thread. * </p> */ public void dispose() { scene.dispose(); context.dispose(); glfwMakeContextCurrent(NULL); GL.setCapabilities(null); this.destroy = true; }
Example #16
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 #17
Source File: GLContainer.java From settlers-remake with MIT License | 5 votes |
public void wrapNewContext() { if(cc instanceof JAWTContextCreator) ((JAWTContextCreator)cc).makeCurrent(true); if(context != null) context.disposeAll(); GLCapabilities caps = GL.createCapabilities(); if(caps.OpenGL20) { context = new LWJGL20DrawContext(caps, debug); } else if(caps.OpenGL15 && caps.GL_ARB_texture_non_power_of_two) { context = new LWJGL15DrawContext(caps, debug); } else { context = null; errorGLVersion(); } }
Example #18
Source File: GLXContextCreator.java From settlers-remake with MIT License | 5 votes |
@Override protected void onInit() { int screen = X11.XDefaultScreen(windowConnection); int[] xvi_attrs = new int[]{ GLX.GLX_RGBA, GLX.GLX_DOUBLEBUFFER, GLX.GLX_STENCIL_SIZE, 1, 0}; GLXCapabilities glxcaps = GL.createCapabilitiesGLX(windowConnection, screen); if(glxcaps.GLX13 && glxcaps.GLX_ARB_create_context && glxcaps.GLX_ARB_create_context_profile) { PointerBuffer fbc = GLX13.glXChooseFBConfig(windowConnection, screen, new int[] {0}); if(fbc == null || fbc.capacity() < 1) throw new Error("GLX could not find any FBConfig!"); int i = debug ? 0 : 3; while(context == 0 && ctx_attrs.length > i) { context = GLXARBCreateContext.glXCreateContextAttribsARB(windowConnection, fbc.get(), 0, true, ctx_attrs[i]); } } else { if(debug) throw new Error("GLX could not create a debug context!"); XVisualInfo xvi = GLX.glXChooseVisual(windowConnection, screen, xvi_attrs); context = GLX.glXCreateContext(windowConnection, xvi, 0, true); } if (context == 0) throw new Error("Could not create GLX context!"); parent.wrapNewContext(); }
Example #19
Source File: WGLContextCreator.java From settlers-remake with MIT License | 5 votes |
@Override protected void onNewConnection() { PIXELFORMATDESCRIPTOR pfd = PIXELFORMATDESCRIPTOR.calloc(); pfd.dwFlags(GDI32.PFD_DRAW_TO_WINDOW | GDI32.PFD_SUPPORT_OPENGL | GDI32.PFD_DOUBLEBUFFER); pfd.iPixelType(GDI32.PFD_TYPE_RGBA); pfd.cColorBits((byte) 32); pfd.cStencilBits((byte) 1); pfd.cDepthBits((byte) 24); int pixel_format = GDI32.ChoosePixelFormat(windowDrawable, pfd); if(pixel_format == 0) throw new Error("Could not find pixel format!"); GDI32.SetPixelFormat(windowDrawable, pixel_format, pfd); pfd.free(); context = WGL.wglCreateContext(windowDrawable); WGL.wglMakeCurrent(windowDrawable, context); WGLCapabilities caps = GL.createCapabilitiesWGL(); if(caps.WGL_ARB_create_context && caps.WGL_ARB_create_context_profile) { WGL.wglDeleteContext(context); context = 0; int i = debug ? 0 : 3; while(context == 0 && ctx_attrs.length > i) { context = WGLARBCreateContext.wglCreateContextAttribsARB(windowDrawable, 0, ctx_attrs[i]); } } else { if(debug) { WGL.wglDeleteContext(context); throw new Error("WGL could not create a debug context!"); } } if(context == 0) throw new Error("Could not create WGL context!"); parent.wrapNewContext(); }
Example #20
Source File: GLTexture.java From oreon-engine with GNU General Public License v3.0 | 5 votes |
public void mirrorRepeatEXT(){ if (GL.getCapabilities().GL_EXT_texture_mirror_clamp){ glTexParameteri(target, GL_TEXTURE_WRAP_S, GL_MIRROR_CLAMP_TO_EDGE_EXT); glTexParameteri(target, GL_TEXTURE_WRAP_T, GL_MIRROR_CLAMP_TO_EDGE_EXT); } else{ System.err.println("texture mirror not supported"); } }
Example #21
Source File: OpenGLRenderer.java From ldparteditor with MIT License | 5 votes |
/** * Disposes all textures */ public void disposeAllTextures() { final GLCanvas canvas = c3d.getCanvas(); if (!canvas.isCurrent()) { canvas.setCurrent(); GL.setCapabilities(c3d.getCapabilities()); } for (Iterator<GTexture> it = textureSet.iterator() ; it.hasNext();) { GTexture tex = it.next(); NLogger.debug(getClass(), "Dispose texture: {0}", tex); //$NON-NLS-1$ tex.dispose(this); it.remove(); } }
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); 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 #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); 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 #24
Source File: PlatformLinuxGLCanvas.java From lwjgl3-swt with MIT License | 4 votes |
private void populateContextAttribs(GLData data, IntBuffer attribList, GLXCapabilities caps) { attribList.put(GLX_CONTEXT_MAJOR_VERSION_ARB).put(data.majorVersion); attribList.put(GLX_CONTEXT_MINOR_VERSION_ARB).put(data.minorVersion); int profile = 0; if (data.api == API.GL) { if (data.profile == Profile.COMPATIBILITY) { profile = GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB; } else if (data.profile == Profile.CORE) { profile = GLX_CONTEXT_CORE_PROFILE_BIT_ARB; } } else if (data.api == API.GLES) { if (!caps.GLX_EXT_create_context_es2_profile) { throw new SWTException("OpenGL ES API requested but GLX_EXT_create_context_es2_profile is unavailable"); } profile = GLX_CONTEXT_ES2_PROFILE_BIT_EXT; } if (profile > 0) { if (!caps.GLX_ARB_create_context_profile) { throw new SWTException("OpenGL profile requested but GLX_ARB_create_context_profile is unavailable"); } attribList.put(GLX_CONTEXT_PROFILE_MASK_ARB).put(profile); } // Context Flags int contextFlags = 0; if (data.debug) contextFlags |= GLX_CONTEXT_DEBUG_BIT_ARB; if (data.forwardCompatible) contextFlags |= GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB; if (data.noErrorContext) { contextFlags |= KHRNoError.GL_CONTEXT_FLAG_NO_ERROR_BIT_KHR; attribList.put(GLX_CONTEXT_OPENGL_NO_ERROR_ARB).put(1); } if (data.robustness) { // Check for GLX_ARB_create_context_robustness if (!caps.GLX_ARB_create_context_robustness) { throw new SWTException("Context with robust buffer access requested but GLX_ARB_create_context_robustness is unavailable"); } contextFlags |= GLX_CONTEXT_ROBUST_ACCESS_BIT_ARB; if (data.loseContextOnReset) { attribList.put(GLX_CONTEXT_RESET_NOTIFICATION_STRATEGY_ARB).put( GLX_LOSE_CONTEXT_ON_RESET_ARB); // Note: GLX_NO_RESET_NOTIFICATION_ARB is default behaviour and need not be specified. } if (data.contextResetIsolation) { // Check for GLX_ARB_robustness_application_isolation or GLX_ARB_robustness_share_group_isolation if (!caps.GLX_ARB_robustness_application_isolation && !caps.GLX_ARB_robustness_share_group_isolation) { throw new SWTException( "Robustness isolation requested but neither GLX_ARB_robustness_application_isolation nor GLX_ARB_robustness_share_group_isolation available"); } contextFlags |= GLX_CONTEXT_RESET_ISOLATION_BIT_ARB; } } if (contextFlags > 0) attribList.put(GLX_CONTEXT_FLAGS_ARB).put(contextFlags); // Release behavior if (data.contextReleaseBehavior != null) { if (!caps.GLX_ARB_context_flush_control) { throw new SWTException("Context release behavior requested but GLX_ARB_context_flush_control is unavailable"); } if (data.contextReleaseBehavior == ReleaseBehavior.NONE) attribList.put(GLX_CONTEXT_RELEASE_BEHAVIOR_ARB).put(GLX_CONTEXT_RELEASE_BEHAVIOR_NONE_ARB); else if (data.contextReleaseBehavior == ReleaseBehavior.FLUSH) attribList.put(GLX_CONTEXT_RELEASE_BEHAVIOR_ARB).put(GLX_CONTEXT_RELEASE_BEHAVIOR_FLUSH_ARB); } attribList.put(0); attribList.flip(); }
Example #25
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 #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); // 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 #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); // 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 #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); 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 #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); 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 #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); 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); } }