protected static X11GLXGraphicsConfiguration chooseGraphicsConfigurationStatic( Capabilities capabilities, CapabilitiesChooser chooser, AbstractGraphicsScreen absScreen) { if (absScreen == null) { throw new IllegalArgumentException("AbstractGraphicsScreen is null"); } if (!(absScreen instanceof X11GraphicsScreen)) { throw new IllegalArgumentException("Only X11GraphicsScreen are allowed here"); } X11GraphicsScreen x11Screen = (X11GraphicsScreen) absScreen; if (capabilities != null && !(capabilities instanceof GLCapabilities)) { throw new IllegalArgumentException( "This NativeWindowFactory accepts only GLCapabilities objects"); } if (chooser != null && !(chooser instanceof GLCapabilitiesChooser)) { throw new IllegalArgumentException( "This NativeWindowFactory accepts only GLCapabilitiesChooser objects"); } if (capabilities == null) { capabilities = new GLCapabilities(null); } boolean onscreen = capabilities.isOnscreen(); boolean usePBuffer = ((GLCapabilities) capabilities).isPBuffer(); GLCapabilities caps2 = (GLCapabilities) capabilities.clone(); if (!caps2.isOnscreen()) { // OFFSCREEN !DOUBLE_BUFFER // FIXME DBLBUFOFFSCRN caps2.setDoubleBuffered(false); } X11GLXGraphicsConfiguration res; res = chooseGraphicsConfigurationFBConfig( (GLCapabilities) caps2, (GLCapabilitiesChooser) chooser, x11Screen); if (null == res) { if (usePBuffer) { throw new GLException( "Error: Couldn't create X11GLXGraphicsConfiguration based on FBConfig"); } res = chooseGraphicsConfigurationXVisual( (GLCapabilities) caps2, (GLCapabilitiesChooser) chooser, x11Screen); } if (null == res) { throw new GLException("Error: Couldn't create X11GLXGraphicsConfiguration"); } if (DEBUG) { System.err.println( "X11GLXGraphicsConfiguration.chooseGraphicsConfigurationStatic(" + x11Screen + "," + caps2 + "): " + res); } return res; }
public static GLCapabilities fixCaps( GLCapabilities caps, boolean onscreen, boolean pbuffer, boolean undecorated) { GLCapabilities caps2 = (GLCapabilities) caps.clone(); caps2.setOnscreen(onscreen); caps2.setPBuffer(!onscreen && pbuffer); caps2.setDoubleBuffered(!onscreen); return caps2; }
@Override protected GLCanvas createDrawable() { GLCapabilities caps = new GLCapabilities(null); caps.setSampleBuffers(true); // GLCanvas panel = new GLCanvas(caps); panel.addGLEventListener(this); panel.addKeyListener(this); return panel; }
@Override protected GLJPanel createDrawable() { GLCapabilities caps = new GLCapabilities(null); caps.setSampleBuffers(true); // enable sample buffers for aliasing caps.setNumSamples(2); // GLJPanel panel = new GLJPanel(caps); panel.addGLEventListener(this); panel.addKeyListener(this); return panel; }
GLFrame(JTextArea outputArea) { this.outputArea = outputArea; GLCapabilities caps = new GLCapabilities(Configuration.getMaxCompatibleGLProfile()); caps.setAlphaBits(8); caps.setRedBits(8); caps.setGreenBits(8); caps.setBlueBits(8); GLCanvas glCanvas = new GLCanvas(caps); glCanvas.addGLEventListener(this); this.add(glCanvas); this.setSize(200, 200); }
public DrawByLevelFractal() { baseDir = "CS371/assignments/assignment02/ifs/"; ifsFiles = new ArrayList<String>(); ifsFiles.add("carpet.ifs"); ifsFiles.add("chaos.ifs"); ifsFiles.add("coral.ifs"); ifsFiles.add("curl.ifs"); ifsFiles.add("four.ifs"); ifsFiles.add("galaxy.ifs"); ifsFiles.add("dragon.ifs"); ifsFiles.add("leady.ifs"); ifsFiles.add("koch.ifs"); ifsFiles.add("mouse.ifs"); ifsFiles.add("leaf.ifs"); ifsFiles.add("seven.ifs"); ifsFiles.add("three.ifs"); ifsFiles.add("tri.ifs"); pointsToDraw = 80000; left = -7; right = 7; bottom = -7; top = 11; xOrigin = 0; yOrigin = 0; rotate_scale_xx = new double[maximumTransitions]; rotate_scale_xy = new double[maximumTransitions]; rotate_scale_yx = new double[maximumTransitions]; rotate_scale_yy = new double[maximumTransitions]; trans_x = new double[maximumTransitions]; trans_y = new double[maximumTransitions]; prob = new double[maximumTransitions]; caps = new GLCapabilities(GLProfile.getGL2GL3()); caps.setDoubleBuffered(true); // request double buffer display mode caps.setHardwareAccelerated(true); canvas = new GLJPanel(); // canvas.setOpaque(true); canvas.addGLEventListener(this); canvas.addKeyListener(this); animator = new FPSAnimator(canvas, 60); getContentPane().add(canvas); }
public static void main(String[] args) { GLCapabilities caps = new GLCapabilities(null); caps.setSampleBuffers(true); // enable sample buffers for aliasing caps.setNumSamples(2); varray demo = new varray(); JFrame.setDefaultLookAndFeelDecorated(true); JFrame frame = new JFrame("varray"); frame.setSize(512, 256); frame.setLocationRelativeTo(null); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.getContentPane().add(demo.drawable); frame.setVisible(true); demo.drawable.requestFocusInWindow(); }
private void run(int type, PerfModule pm) { int width = 800; int height = 480; pmod = pm; System.err.println("Perftst.run()"); try { GLCapabilities caps = new GLCapabilities(GLProfile.getGL2ES2()); // For emulation library, use 16 bpp caps.setRedBits(5); caps.setGreenBits(6); caps.setBlueBits(5); caps.setDepthBits(16); Window nWindow = null; if (0 != (type & USE_AWT)) { Display nDisplay = NewtFactory.createDisplay(NativeWindowFactory.TYPE_AWT, null); // local display Screen nScreen = NewtFactory.createScreen(NativeWindowFactory.TYPE_AWT, nDisplay, 0); // screen 0 nWindow = NewtFactory.createWindow(NativeWindowFactory.TYPE_AWT, nScreen, caps); window = GLWindow.create(nWindow); } else { window = GLWindow.create(caps); } window.addMouseListener(this); window.addGLEventListener(this); // window.setEventHandlerMode(GLWindow.EVENT_HANDLER_GL_CURRENT); // default // window.setEventHandlerMode(GLWindow.EVENT_HANDLER_GL_NONE); // no current .. // Size OpenGL to Video Surface window.setSize(width, height); window.setFullscreen(true); window.setVisible(true); window.display(); // Shut things down cooperatively window.destroy(); window.getFactory().shutdown(); System.out.println("Perftst shut down cleanly."); } catch (Throwable t) { t.printStackTrace(); } }
private static GLCapabilities stdcaps() { GLProfile prof = GLProfile.getDefault(); GLCapabilities cap = new GLCapabilities(prof); cap.setDoubleBuffered(true); cap.setAlphaBits(8); cap.setRedBits(8); cap.setGreenBits(8); cap.setBlueBits(8); cap.setSampleBuffers(true); cap.setNumSamples(4); return (cap); }
public GLPbufferImpl(GLDrawableImpl pbufferDrawable, GLContext parentContext) { GLCapabilities caps = (GLCapabilities) pbufferDrawable .getNativeWindow() .getGraphicsConfiguration() .getNativeGraphicsConfiguration() .getChosenCapabilities(); if (caps.isOnscreen()) { if (caps.isPBuffer()) { throw new IllegalArgumentException( "Error: Given drawable is Onscreen and Pbuffer: " + pbufferDrawable); } throw new IllegalArgumentException("Error: Given drawable is Onscreen: " + pbufferDrawable); } else { if (!caps.isPBuffer()) { throw new IllegalArgumentException( "Error: Given drawable is not Pbuffer: " + pbufferDrawable); } } this.pbufferDrawable = pbufferDrawable; context = (GLContextImpl) pbufferDrawable.createContext(parentContext); context.setSynchronized(true); }
protected static X11GLXGraphicsConfiguration chooseGraphicsConfigurationXVisual( GLCapabilities capabilities, GLCapabilitiesChooser chooser, X11GraphicsScreen x11Screen) { if (chooser == null) { chooser = new DefaultGLCapabilitiesChooser(); } // Until we have a rock-solid visual selection algorithm written // in pure Java, we're going to provide the underlying window // system's selection to the chooser as a hint GLProfile glProfile = capabilities.getGLProfile(); boolean onscreen = capabilities.isOnscreen(); GLCapabilities[] caps = null; int recommendedIndex = -1; XVisualInfo retXVisualInfo = null; int chosen = -1; AbstractGraphicsDevice absDevice = x11Screen.getDevice(); long display = absDevice.getHandle(); try { NativeWindowFactory.getDefaultFactory().getToolkitLock().lock(); X11Lib.XLockDisplay(display); int screen = x11Screen.getIndex(); boolean isMultisampleAvailable = GLXUtil.isMultisampleAvailable(display); int[] attribs = X11GLXGraphicsConfiguration.GLCapabilities2AttribList( capabilities, false, isMultisampleAvailable, display, screen); XVisualInfo[] infos = null; XVisualInfo recommendedVis = GLX.glXChooseVisualCopied(display, screen, attribs, 0); if (DEBUG) { System.err.print("!!! glXChooseVisual recommended "); if (recommendedVis == null) { System.err.println("null visual"); } else { System.err.println("visual id 0x" + Long.toHexString(recommendedVis.getVisualid())); } } int[] count = new int[1]; XVisualInfo template = XVisualInfo.create(); template.setScreen(screen); infos = X11Lib.XGetVisualInfoCopied(display, X11Lib.VisualScreenMask, template, count, 0); if (infos == null || infos.length < 1) { throw new GLException("Error while enumerating available XVisualInfos"); } caps = new GLCapabilities[infos.length]; for (int i = 0; i < infos.length; i++) { caps[i] = X11GLXGraphicsConfiguration.XVisualInfo2GLCapabilities( glProfile, display, infos[i], onscreen, false, isMultisampleAvailable); // Attempt to find the visual chosen by glXChooseVisual if (recommendedVis != null && recommendedVis.getVisualid() == infos[i].getVisualid()) { recommendedIndex = i; } } try { chosen = chooser.chooseCapabilities(capabilities, caps, recommendedIndex); } catch (NativeWindowException e) { if (DEBUG) { e.printStackTrace(); } chosen = -1; } if (chosen < 0) { // keep on going .. if (DEBUG) { System.err.println( "X11GLXGraphicsConfiguration.chooseGraphicsConfigurationXVisual Failed .. unable to choose config, using first"); } chosen = 0; // default .. } else if (chosen >= caps.length) { throw new GLException( "GLCapabilitiesChooser specified invalid index (expected 0.." + (caps.length - 1) + ")"); } if (infos[chosen] == null) { throw new GLException("GLCapabilitiesChooser chose an invalid visual"); } retXVisualInfo = XVisualInfo.create(infos[chosen]); } finally { X11Lib.XUnlockDisplay(display); NativeWindowFactory.getDefaultFactory().getToolkitLock().unlock(); } return new X11GLXGraphicsConfiguration( x11Screen, caps[chosen], capabilities, chooser, retXVisualInfo, 0, -1); }
protected static X11GLXGraphicsConfiguration chooseGraphicsConfigurationFBConfig( GLCapabilities capabilities, GLCapabilitiesChooser chooser, X11GraphicsScreen x11Screen) { int recommendedIndex = -1; GLCapabilities[] caps = null; PointerBuffer fbcfgsL = null; int chosen = -1; int retFBID = -1; XVisualInfo retXVisualInfo = null; GLProfile glProfile = capabilities.getGLProfile(); boolean onscreen = capabilities.isOnscreen(); boolean usePBuffer = capabilities.isPBuffer(); // Utilizing FBConfig // AbstractGraphicsDevice absDevice = x11Screen.getDevice(); long display = absDevice.getHandle(); try { NativeWindowFactory.getDefaultFactory().getToolkitLock().lock(); X11Lib.XLockDisplay(display); int screen = x11Screen.getIndex(); boolean isMultisampleAvailable = GLXUtil.isMultisampleAvailable(display); int[] attribs = X11GLXGraphicsConfiguration.GLCapabilities2AttribList( capabilities, true, isMultisampleAvailable, display, screen); int[] count = {-1}; fbcfgsL = GLX.glXChooseFBConfigCopied(display, screen, attribs, 0, count, 0); if (fbcfgsL == null || fbcfgsL.limit() < 1) { if (DEBUG) { System.err.println( "X11GLXGraphicsConfiguration.chooseGraphicsConfigurationFBConfig: Failed glXChooseFBConfig (" + x11Screen + "," + capabilities + "): " + fbcfgsL + ", " + count[0]); } return null; } if (!X11GLXGraphicsConfiguration.GLXFBConfigValid(display, fbcfgsL.get(0))) { if (DEBUG) { System.err.println( "X11GLXGraphicsConfiguration.chooseGraphicsConfigurationFBConfig: Failed - GLX FBConfig invalid: (" + x11Screen + "," + capabilities + "): " + fbcfgsL + ", fbcfg: 0x" + Long.toHexString(fbcfgsL.get(0))); } return null; } recommendedIndex = 0; // 1st match is always recommended .. caps = new GLCapabilities[fbcfgsL.limit()]; for (int i = 0; i < fbcfgsL.limit(); i++) { caps[i] = X11GLXGraphicsConfiguration.GLXFBConfig2GLCapabilities( glProfile, display, fbcfgsL.get(i), false, onscreen, usePBuffer, isMultisampleAvailable); } if (null == chooser) { chosen = recommendedIndex; } else { try { chosen = chooser.chooseCapabilities(capabilities, caps, recommendedIndex); } catch (NativeWindowException e) { if (DEBUG) { e.printStackTrace(); } chosen = -1; } } if (chosen < 0) { // keep on going .. if (DEBUG) { System.err.println( "X11GLXGraphicsConfiguration.chooseGraphicsConfigurationFBConfig Failed .. unable to choose config, using first"); } chosen = 0; // default .. } else if (chosen >= caps.length) { throw new GLException( "GLCapabilitiesChooser specified invalid index (expected 0.." + (caps.length - 1) + ")"); } retFBID = X11GLXGraphicsConfiguration.glXFBConfig2FBConfigID(display, fbcfgsL.get(chosen)); retXVisualInfo = GLX.glXGetVisualFromFBConfigCopied(display, fbcfgsL.get(chosen)); if (retXVisualInfo == null) { if (DEBUG) { System.err.println( "X11GLXGraphicsConfiguration.chooseGraphicsConfigurationFBConfig: Failed glXGetVisualFromFBConfig (" + x11Screen + ", " + fbcfgsL.get(chosen) + " (Continue: " + (false == caps[chosen].isOnscreen()) + "):\n\t" + caps[chosen]); } if (caps[chosen].isOnscreen()) { // Onscreen drawables shall have a XVisual .. return null; } } } finally { X11Lib.XUnlockDisplay(display); NativeWindowFactory.getDefaultFactory().getToolkitLock().unlock(); } return new X11GLXGraphicsConfiguration( x11Screen, caps[chosen], capabilities, chooser, retXVisualInfo, fbcfgsL.get(chosen), retFBID); }
/** * Creates and initializes an appropriate OpenGl Context (NS). Should only be called by {@link * makeCurrentImpl()}. */ protected boolean create(boolean pbuffer, boolean floatingPoint) { MacOSXCGLContext other = (MacOSXCGLContext) GLContextShareSet.getShareContext(this); long share = 0; if (other != null) { if (!other.isNSContext()) { throw new GLException("GLContextShareSet is not a NS Context"); } share = other.getHandle(); if (share == 0) { throw new GLException("GLContextShareSet returned a NULL OpenGL context"); } } MacOSXCGLGraphicsConfiguration config = (MacOSXCGLGraphicsConfiguration) drawable.getNativeSurface().getGraphicsConfiguration().getNativeGraphicsConfiguration(); GLCapabilitiesImmutable capabilitiesRequested = (GLCapabilitiesImmutable) config.getRequestedCapabilities(); GLProfile glProfile = capabilitiesRequested.getGLProfile(); if (glProfile.isGL3()) { throw new GLException( "GL3 profile currently not supported on MacOSX, due to the lack of a OpenGL 3.1 implementation"); } // HACK .. bring in OnScreen/PBuffer selection to the DrawableFactory !! GLCapabilities capabilities = (GLCapabilities) capabilitiesRequested.cloneMutable(); capabilities.setPBuffer(pbuffer); capabilities.setPbufferFloatingPointBuffers(floatingPoint); long pixelFormat = MacOSXCGLGraphicsConfiguration.GLCapabilities2NSPixelFormat(capabilities); if (pixelFormat == 0) { throw new GLException("Unable to allocate pixel format with requested GLCapabilities"); } config.setChosenPixelFormat(pixelFormat); try { int[] viewNotReady = new int[1]; // Try to allocate a context with this contextHandle = CGL.createContext(share, drawable.getHandle(), pixelFormat, viewNotReady, 0); if (contextHandle == 0) { if (viewNotReady[0] == 1) { if (DEBUG) { System.err.println("!!! View not ready for " + getClass().getName()); } // View not ready at the window system level -- this is OK return false; } throw new GLException("Error creating NSOpenGLContext with requested pixel format"); } if (!pbuffer && !capabilities.isBackgroundOpaque()) { // Set the context opacity CGL.setContextOpacity(contextHandle, 0); } GLCapabilitiesImmutable caps = MacOSXCGLGraphicsConfiguration.NSPixelFormat2GLCapabilities(glProfile, pixelFormat); config.setChosenCapabilities(caps); } finally { CGL.deletePixelFormat(pixelFormat); } if (!CGL.makeCurrentContext(contextHandle)) { throw new GLException("Error making Context (NS) current"); } isNSContext = true; setGLFunctionAvailability(true, 0, 0, CTX_PROFILE_COMPAT | CTX_OPTION_ANY); GLContextShareSet.contextCreated(this); return true; }
public int chooseCapabilities( Capabilities desired, Capabilities[] available, int windowSystemRecommendedChoice) { GLCapabilities _desired = (GLCapabilities) desired; GLCapabilities[] _available = (GLCapabilities[]) available; if (DEBUG) { System.err.println("Desired: " + _desired); for (int i = 0; i < _available.length; i++) { System.err.println("Available " + i + ": " + _available[i]); } System.err.println("Window system's recommended choice: " + windowSystemRecommendedChoice); } if (windowSystemRecommendedChoice >= 0 && windowSystemRecommendedChoice < _available.length && _available[windowSystemRecommendedChoice] != null) { if (DEBUG) { System.err.println( "Choosing window system's recommended choice of " + windowSystemRecommendedChoice); System.err.println(_available[windowSystemRecommendedChoice]); } return windowSystemRecommendedChoice; } // Create score array int[] scores = new int[_available.length]; int NO_SCORE = -9999999; int DOUBLE_BUFFER_MISMATCH_PENALTY = 1000; int STENCIL_MISMATCH_PENALTY = 500; // Pseudo attempt to keep equal rank penalties scale-equivalent // (e.g., stencil mismatch is 3 * accum because there are 3 accum // components) int COLOR_MISMATCH_PENALTY_SCALE = 36; int DEPTH_MISMATCH_PENALTY_SCALE = 6; int ACCUM_MISMATCH_PENALTY_SCALE = 1; int STENCIL_MISMATCH_PENALTY_SCALE = 3; for (int i = 0; i < scores.length; i++) { scores[i] = NO_SCORE; } // Compute score for each for (int i = 0; i < scores.length; i++) { GLCapabilities cur = _available[i]; if (cur == null) { continue; } if (_desired.isOnscreen() != cur.isOnscreen()) { continue; } if (_desired.getStereo() != cur.getStereo()) { continue; } int score = 0; // Compute difference in color depth // (Note that this decides the direction of all other penalties) score += (COLOR_MISMATCH_PENALTY_SCALE * ((cur.getRedBits() + cur.getGreenBits() + cur.getBlueBits() + cur.getAlphaBits()) - (_desired.getRedBits() + _desired.getGreenBits() + _desired.getBlueBits() + _desired.getAlphaBits()))); // Compute difference in depth buffer depth score += (DEPTH_MISMATCH_PENALTY_SCALE * sign(score) * Math.abs(cur.getDepthBits() - _desired.getDepthBits())); // Compute difference in accumulation buffer depth score += (ACCUM_MISMATCH_PENALTY_SCALE * sign(score) * Math.abs( (cur.getAccumRedBits() + cur.getAccumGreenBits() + cur.getAccumBlueBits() + cur.getAccumAlphaBits()) - (_desired.getAccumRedBits() + _desired.getAccumGreenBits() + _desired.getAccumBlueBits() + _desired.getAccumAlphaBits()))); // Compute difference in stencil bits score += STENCIL_MISMATCH_PENALTY_SCALE * sign(score) * (cur.getStencilBits() - _desired.getStencilBits()); if (cur.getDoubleBuffered() != _desired.getDoubleBuffered()) { score += sign(score) * DOUBLE_BUFFER_MISMATCH_PENALTY; } if ((_desired.getStencilBits() > 0) && (cur.getStencilBits() == 0)) { score += sign(score) * STENCIL_MISMATCH_PENALTY; } scores[i] = score; } // Now prefer hardware-accelerated visuals by pushing scores of // non-hardware-accelerated visuals out boolean gotHW = false; int maxAbsoluteHWScore = 0; for (int i = 0; i < scores.length; i++) { int score = scores[i]; if (score == NO_SCORE) { continue; } GLCapabilities cur = _available[i]; if (cur.getHardwareAccelerated()) { int absScore = Math.abs(score); if (!gotHW || (absScore > maxAbsoluteHWScore)) { gotHW = true; maxAbsoluteHWScore = absScore; } } } if (gotHW) { for (int i = 0; i < scores.length; i++) { int score = scores[i]; if (score == NO_SCORE) { continue; } GLCapabilities cur = _available[i]; if (!cur.getHardwareAccelerated()) { if (score <= 0) { score -= maxAbsoluteHWScore; } else if (score > 0) { score += maxAbsoluteHWScore; } scores[i] = score; } } } if (DEBUG) { System.err.print("Scores: ["); for (int i = 0; i < _available.length; i++) { if (i > 0) { System.err.print(","); } System.err.print(" " + scores[i]); } System.err.println(" ]"); } // Ready to select. Choose score closest to 0. int scoreClosestToZero = NO_SCORE; int chosenIndex = -1; for (int i = 0; i < scores.length; i++) { int score = scores[i]; if (score == NO_SCORE) { continue; } // Don't substitute a positive score for a smaller negative score if ((scoreClosestToZero == NO_SCORE) || (Math.abs(score) < Math.abs(scoreClosestToZero) && ((sign(scoreClosestToZero) < 0) || (sign(score) > 0)))) { scoreClosestToZero = score; chosenIndex = i; } } if (chosenIndex < 0) { throw new NativeWindowException("Unable to select one of the provided GLCapabilities"); } if (DEBUG) { System.err.println("Chosen index: " + chosenIndex); System.err.println("Chosen capabilities:"); System.err.println(_available[chosenIndex]); } return chosenIndex; }