List of usage examples for org.lwjgl.opengl GL createCapabilities
@SuppressWarnings("AssignmentToMethodParameter") public static GLCapabilities createCapabilities(boolean forwardCompatible)
From source file:lwjgl.test.Gears.java
License:Open Source License
private void createWindow(boolean fullscreen) { int WIDTH = 300; int HEIGHT = 300; long monitor = glfwGetPrimaryMonitor(); GLFWvidmode vidmode = new GLFWvidmode(glfwGetVideoMode(monitor)); long window = fullscreen ? glfwCreateWindow(vidmode.getWidth(), vidmode.getHeight(), "GLFW Gears Demo", monitor, this.window) : glfwCreateWindow(WIDTH, HEIGHT, "GLFW Gears Demo", NULL, this.window); if (window == NULL) throw new RuntimeException("Failed to create the GLFW window"); // Destroy old window if (this.window != NULL) { glfwSetInputMode(this.window, GLFW_CURSOR, GLFW_CURSOR_NORMAL); glfwDestroyWindow(this.window); if (debugProc != null) debugProc.release();//from w w w . j a va2 s . co m } glfwSetKeyCallback(window, keyfun); if (fullscreen) glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_DISABLED); else { // Center window glfwSetWindowPos(window, (vidmode.getWidth() - WIDTH) / 2, (vidmode.getHeight() - HEIGHT) / 2); } glfwMakeContextCurrent(window); GLContext.createFromCurrent(); GL.createCapabilities(false); // debugProc = GLUtil.setupDebugMessageCallback(); glfwSwapInterval(1); glfwShowWindow(window); this.window = window; }
From source file:org.lwjgl.system.jglfw.PlatformLinux.java
License:Open Source License
private boolean createWindowImpl(GLFWwindowLinux window, GLFWwndconfig wndconfig) { long visualInfo = window.visual; long visual = memGetAddress(visualInfo + XVisualInfo.VISUAL); // Every window needs a colormap // Create one based on the visual used by the current context // TODO: Decouple this from context creation window.colormap = nXCreateColormap(x11.display, x11.root, visual, AllocNone); // Create the actual window {/*from w w w. ja v a 2 s.c o m*/ int wamask = CWBorderPixel | CWColormap | CWEventMask; ByteBuffer wa = XSetWindowAttributes.malloc(); XSetWindowAttributes.colormapSet(wa, window.colormap); XSetWindowAttributes.border_pixelSet(wa, 0); XSetWindowAttributes.event_maskSet(wa, StructureNotifyMask | KeyPressMask | KeyReleaseMask | PointerMotionMask | ButtonPressMask | ButtonReleaseMask | ExposureMask | FocusChangeMask | VisibilityChangeMask | EnterWindowMask | LeaveWindowMask | PropertyChangeMask); if (wndconfig.monitor == null) { // HACK: This is a workaround for windows without a background pixel // not getting any decorations on certain older versions of Compiz // running on Intel hardware XSetWindowAttributes.background_pixelSet(wa, XBlackPixel(x11.display, x11.screen)); wamask |= CWBackPixel; } window.handle = nXCreateWindow(x11.display, x11.root, 0, 0, wndconfig.width, wndconfig.height, 0, // Border width memGetInt(visualInfo + XVisualInfo.DEPTH), // Color depth InputOutput, visual, wamask, memAddress(wa)); if (window.handle == NULL) { // TODO: Handle all the various error codes here and translate them // to GLFW errors inputError(GLFW_PLATFORM_ERROR, "X11: Failed to create window"); return false; } if (!wndconfig.decorated) { ByteBuffer hints = createByteBuffer(POINTER_SIZE * 5); PointerBuffer.put(hints, 0 * POINTER_SIZE, (1L << 1)); // flags PointerBuffer.put(hints, 2 * POINTER_SIZE, 0); // decorations XChangeProperty(x11.display, window.handle, x11.MOTIF_WM_HINTS, x11.MOTIF_WM_HINTS, 32, PropModeReplace, hints, 5); } nXSaveContext(x11.display, window.handle, x11.context, memGlobalRefNew(window)); } if (window.monitor != null && !x11.hasEWMH) { // This is the butcher's way of removing window decorations // Setting the override-redirect attribute on a window makes the window // manager ignore the window completely (ICCCM, section 4) // The good thing is that this makes undecorated fullscreen windows // easy to do; the bad thing is that we have to do everything manually // and some things (like iconify/restore) won't work at all, as those // are tasks usually performed by the window manager ByteBuffer attributes = XSetWindowAttributes.malloc(); XSetWindowAttributes.override_redirectSet(attributes, True); XChangeWindowAttributes(x11.display, window.handle, CWOverrideRedirect, attributes); window.overrideRedirect = true; } // Declare the WM protocols supported by GLFW { PointerBuffer protocols = createPointerBuffer(2); // The WM_DELETE_WINDOW ICCCM protocol // Basic window close notification protocol if (x11.WM_DELETE_WINDOW != None) protocols.put(x11.WM_DELETE_WINDOW); // The _NET_WM_PING EWMH protocol // Tells the WM to ping the GLFW window and flag the application as // unresponsive if the WM doesn't get a reply within a few seconds if (x11.NET_WM_PING != None) protocols.put(x11.NET_WM_PING); protocols.flip(); if (protocols.hasRemaining()) XSetWMProtocols(x11.display, window.handle, protocols); } // Set ICCCM WM_HINTS property { ByteBuffer hints = XAllocWMHints(); if (hints == null) { // TODO: IAE above inputError(GLFW_OUT_OF_MEMORY, "X11: Failed to allocate WM hints"); return false; } XWMHints.flagsSet(hints, StateHint); XWMHints.initial_stateSet(hints, NormalState); XSetWMHints(x11.display, window.handle, hints); XFree(hints); } // Set ICCCM WM_NORMAL_HINTS property (even if no parts are set) { ByteBuffer hints = XAllocSizeHints(); XSizeHints.flagsSet(hints, 0); if (wndconfig.monitor != null) { XSizeHints.flagsSet(hints, XSizeHints.flagsGet(hints) | PPosition); getMonitorPos(wndconfig.monitor, memAddress(hints) + XSizeHints.X, memAddress(hints) + XSizeHints.Y); } if (!wndconfig.resizable) { XSizeHints.flagsSet(hints, XSizeHints.flagsGet(hints) | PMinSize | PMaxSize); XSizeHints.min_widthSet(hints, wndconfig.width); XSizeHints.max_widthSet(hints, wndconfig.width); XSizeHints.min_heightSet(hints, wndconfig.height); XSizeHints.max_heightSet(hints, wndconfig.height); } XSetWMNormalHints(x11.display, window.handle, hints); XFree(hints); } if (x11.xi.available) { // Select for XInput2 events ByteBuffer eventmask = XIEventMask.malloc(); ByteBuffer mask = createByteBuffer(1); XIEventMask.deviceidSet(eventmask, 2); XIEventMask.mask_lenSet(eventmask, 1); // sizeof(mask) XIEventMask.maskSet(eventmask, mask); XISetMask(mask, XInput2.XI_Motion); XISelectEvents(x11.display, window.handle, eventmask, 1); } setWindowTitle(window, wndconfig.title); XRRSelectInput(x11.display, window.handle, RRScreenChangeNotifyMask); // TODO: GLFW does not make the context current here glXMakeCurrent(x11.display, window.handle, window.contextHandle); window.context = new LinuxGLContext(GL.createCapabilities(window.glForward), x11.display, window.contextHandle); return true; }
From source file:org.lwjgl.system.jglfw.PlatformWin.java
License:Open Source License
private boolean createContext(GLFWwindowWin window, GLFWwndconfig wndconfig, GLFWfbconfig fbconfig) { long share = wndconfig.share == null ? NULL : wndconfig.share.<GLFWwindowWin>asPlatformWindow().context.getHandle(); window.dc = GetDC(window.handle);//from w ww . j a va 2 s. c o m if (window.dc == NULL) { inputError(GLFW_PLATFORM_ERROR, "Win32: Failed to retrieve DC for window"); return false; } IntBuffer attribs = null; int pixelFormat; ByteBuffer pfd = PIXELFORMATDESCRIPTOR.malloc(); if (window.ARB_pixel_format) { IntBuffer count = BufferUtils.createIntBuffer(1); attribs = BufferUtils.createIntBuffer(40); setWGLattrib(attribs, WGL_SUPPORT_OPENGL_ARB, TRUE); setWGLattrib(attribs, WGL_DRAW_TO_WINDOW_ARB, TRUE); setWGLattrib(attribs, WGL_PIXEL_TYPE_ARB, WGL_TYPE_RGBA_ARB); setWGLattrib(attribs, WGL_DOUBLE_BUFFER_ARB, TRUE); if (fbconfig.redBits != 0) setWGLattrib(attribs, WGL_RED_BITS_ARB, fbconfig.redBits); if (fbconfig.greenBits != 0) setWGLattrib(attribs, WGL_GREEN_BITS_ARB, fbconfig.greenBits); if (fbconfig.blueBits != 0) setWGLattrib(attribs, WGL_BLUE_BITS_ARB, fbconfig.blueBits); if (fbconfig.alphaBits != 0) setWGLattrib(attribs, WGL_ALPHA_BITS_ARB, fbconfig.alphaBits); if (fbconfig.depthBits != 0) setWGLattrib(attribs, WGL_DEPTH_BITS_ARB, fbconfig.depthBits); if (fbconfig.stencilBits != 0) setWGLattrib(attribs, WGL_STENCIL_BITS_ARB, fbconfig.stencilBits); if (fbconfig.auxBuffers != 0) setWGLattrib(attribs, WGL_AUX_BUFFERS_ARB, fbconfig.auxBuffers); if (fbconfig.accumRedBits != 0) setWGLattrib(attribs, WGL_ACCUM_RED_BITS_ARB, fbconfig.accumRedBits); if (fbconfig.accumGreenBits != 0) setWGLattrib(attribs, WGL_ACCUM_GREEN_BITS_ARB, fbconfig.accumGreenBits); if (fbconfig.accumBlueBits != 0) setWGLattrib(attribs, WGL_ACCUM_BLUE_BITS_ARB, fbconfig.accumBlueBits); if (fbconfig.accumAlphaBits != 0) setWGLattrib(attribs, WGL_ACCUM_BLUE_BITS_ARB, fbconfig.accumAlphaBits); if (fbconfig.stereo != 0) setWGLattrib(attribs, WGL_STEREO_ARB, TRUE); if (window.ARB_multisample) { if (fbconfig.samples != 0) { setWGLattrib(attribs, WGL_SAMPLE_BUFFERS_ARB, 1); setWGLattrib(attribs, WGL_SAMPLES_ARB, fbconfig.samples); } } if (window.ARB_framebuffer_sRGB) { if (fbconfig.sRGB) setWGLattrib(attribs, WGL_FRAMEBUFFER_SRGB_CAPABLE_ARB, TRUE); } setWGLattrib(attribs, 0, 0); attribs.flip(); IntBuffer pixelFormatOut = BufferUtils.createIntBuffer(1); if (wglChoosePixelFormatARB(window.dc, attribs, null, pixelFormatOut, count) == FALSE) { inputError(GLFW_PLATFORM_ERROR, "WGL: Failed to find a suitable pixel format"); return false; } pixelFormat = pixelFormatOut.get(0); } else { PIXELFORMATDESCRIPTOR.sizeSet(pfd, PIXELFORMATDESCRIPTOR.SIZEOF); PIXELFORMATDESCRIPTOR.versionSet(pfd, 1); int flags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER; if (fbconfig.stereo != 0) flags |= PFD_STEREO; PIXELFORMATDESCRIPTOR.flagsSet(pfd, flags); PIXELFORMATDESCRIPTOR.pixelTypeSet(pfd, PFD_TYPE_RGBA); PIXELFORMATDESCRIPTOR.colorBitsSet(pfd, fbconfig.redBits + fbconfig.greenBits + fbconfig.blueBits); PIXELFORMATDESCRIPTOR.alphaBitsSet(pfd, fbconfig.alphaBits); PIXELFORMATDESCRIPTOR.accumBitsSet(pfd, fbconfig.accumRedBits + fbconfig.accumGreenBits + fbconfig.accumBlueBits); PIXELFORMATDESCRIPTOR.depthBitsSet(pfd, fbconfig.depthBits); PIXELFORMATDESCRIPTOR.stencilBitsSet(pfd, fbconfig.stencilBits); PIXELFORMATDESCRIPTOR.auxBuffersSet(pfd, fbconfig.auxBuffers); pixelFormat = ChoosePixelFormat(window.dc, pfd); if (pixelFormat == 0) { inputError(GLFW_PLATFORM_ERROR, "WGL: Failed to find a suitable pixel format"); return false; } } if (DescribePixelFormat(window.dc, pixelFormat, pfd) == FALSE) { inputError(GLFW_PLATFORM_ERROR, "Win32: Failed to retrieve PFD for selected pixel format"); return false; } int flags = PIXELFORMATDESCRIPTOR.flagsGet(pfd); if ((flags & PFD_GENERIC_ACCELERATED) == 0 && (flags & PFD_GENERIC_FORMAT) != 0) { inputError(GLFW_PLATFORM_ERROR, "Win32: Failed to find an accelerated pixel format"); return false; } if (SetPixelFormat(window.dc, pixelFormat, pfd) == FALSE) { inputError(GLFW_PLATFORM_ERROR, "Win32: Failed to set selected pixel format"); return false; } long context; if (window.ARB_create_context) { int mask = 0, strategy = 0; flags = 0; if (wndconfig.glForward) flags |= WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB; if (wndconfig.glDebug) flags |= WGL_CONTEXT_DEBUG_BIT_ARB; if (wndconfig.glProfile != 0) { if (wndconfig.glProfile == GLFW_OPENGL_CORE_PROFILE) mask |= WGL_CONTEXT_CORE_PROFILE_BIT_ARB; else if (wndconfig.glProfile == GLFW_OPENGL_COMPAT_PROFILE) mask |= WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB; } if (wndconfig.glRobustness != 0) { if (window.ARB_create_context_robustness) { if (wndconfig.glRobustness == GLFW_NO_RESET_NOTIFICATION) strategy = WGL_NO_RESET_NOTIFICATION_ARB; else if (wndconfig.glRobustness == GLFW_LOSE_CONTEXT_ON_RESET) strategy = WGL_LOSE_CONTEXT_ON_RESET_ARB; flags |= WGL_CONTEXT_ROBUST_ACCESS_BIT_ARB; } } attribs.clear(); if (wndconfig.glMajor != 1 || wndconfig.glMinor != 0) { setWGLattrib(attribs, WGL_CONTEXT_MAJOR_VERSION_ARB, wndconfig.glMajor); setWGLattrib(attribs, WGL_CONTEXT_MINOR_VERSION_ARB, wndconfig.glMinor); } if (flags != 0) setWGLattrib(attribs, WGL_CONTEXT_FLAGS_ARB, flags); if (mask != 0) setWGLattrib(attribs, WGL_CONTEXT_PROFILE_MASK_ARB, mask); if (strategy != 0) setWGLattrib(attribs, WGL_CONTEXT_RESET_NOTIFICATION_STRATEGY_ARB, strategy); setWGLattrib(attribs, 0, 0); attribs.flip(); context = wglCreateContextAttribsARB(window.dc, share, attribs); if (context == NULL) { inputError(GLFW_VERSION_UNAVAILABLE, "WGL: Failed to create OpenGL context"); return false; } } else { context = wglCreateContext(window.dc); if (context == NULL) { inputError(GLFW_PLATFORM_ERROR, "WGL: Failed to create OpenGL context"); return false; } if (share != NULL) { if (wglShareLists(share, context) == FALSE) { inputError(GLFW_PLATFORM_ERROR, "WGL: Failed to enable sharing with specified OpenGL context"); return false; } } } //makeContextCurrent(window); wglMakeCurrent(window.dc, context); currentWindow.set(window); window.context = new WindowsGLContext(GL.createCapabilities(window.glForward), context); initWGLExtensions(window); return true; }