public void beginExecution() { if (cam == null) { int numBuffers = 2; env = GraphicsEnvironment.getLocalGraphicsEnvironment(); device = env.getDefaultScreenDevice(); // MultiBufferTest test = new MultiBufferTest(numBuffers, device); try { GraphicsConfiguration gc = device.getDefaultConfiguration(); mainFrame = new Frame(gc); mainFrame.setUndecorated(true); mainFrame.setIgnoreRepaint(true); device.setFullScreenWindow(mainFrame); if (device.isDisplayChangeSupported()) { chooseBestDisplayMode(device); } mainFrame.createBufferStrategy(numBuffers); bufferStrategy = mainFrame.getBufferStrategy(); } catch (Exception e) { e.printStackTrace(); } } }
/** Pasa a modo grafico en pantalla completa. */ private void initFullScreen(int width, int height, int depth, int refresh) { this.width = width; this.height = height; window.setUndecorated(true); window.setIgnoreRepaint(true); try { graphicsDevice.setFullScreenWindow(window); graphicsDevice.setDisplayMode(new DisplayMode(width, height, depth, refresh)); timer = new N3Timer(1, this); } catch (Exception e) { shutdown(); } }
public MultiBufferTest(int numBuffers, GraphicsDevice device) { try { GraphicsConfiguration gc = device.getDefaultConfiguration(); mainFrame = new Frame(gc); mainFrame.setUndecorated(true); mainFrame.setIgnoreRepaint(true); device.setFullScreenWindow(mainFrame); // if (device.isDisplayChangeSupported()) { // chooseBestDisplayMode(device); // } Rectangle bounds = mainFrame.getBounds(); mainFrame.createBufferStrategy(numBuffers); BufferStrategy bufferStrategy = mainFrame.getBufferStrategy(); for (float lag = 2000.0f; lag > 0.00000006f; lag = lag / 1.33f) { System.out.println("lag = " + lag); for (int i = 0; i < numBuffers; i++) { Graphics g = bufferStrategy.getDrawGraphics(); if (!bufferStrategy.contentsLost()) { g.setColor(COLORS[i]); // g.fillRect(0,0,bounds.width, bounds.height); g.fillRect(0, 0, 20, 20); bufferStrategy.show(); g.dispose(); } try { Thread.sleep((int) lag); } catch (InterruptedException e) { } } } } catch (Exception e) { logger.error(e.getMessage(), e); } finally { device.setFullScreenWindow(null); } }
public static void main(String[] args) { UEyeCameraInfo[] uEyeCameraInfoArray = {new UEyeCameraInfo(), new UEyeCameraInfo()}; UEyeCameraList uEyeCameraList = new UEyeCameraList(uEyeCameraInfoArray); // write struct to native memory uEyeCameraList.write(); int result = UEyeCapturerLibrary.GetCameraNames(uEyeCameraList.getPointer()); System.out.println("GetCameraNames result: " + result); uEyeCameraList.read(); final IntByReference cameraHandle = new IntByReference(0); char[] windowName = null; for (int i = 0; i < uEyeCameraList.dwCount; i++) { UEyeCameraInfo ueye_CAMERA_INFO = uEyeCameraList.uci[i]; windowName = Native.toCharArray(ueye_CAMERA_INFO.getModelInfo()); System.out.println("WindowName returned: " + windowName); cameraHandle.setValue(ueye_CAMERA_INFO.dwCameraID); } uEyeCameraList.clear(); String settingsFile = "C:/Documents and Settings/Administrator/My Documents/uEye/1495LE3.90.ini"; result = UEyeCapturerLibrary.InitializeCamera(cameraHandle); System.out.println("initCamera result: " + result); System.out.println("Camera handle returned: " + cameraHandle.getValue()); IntByReference monitorId = new IntByReference(WindowManager.getDefaultMonitorId()); UEyeCapturerLibrary.OnWndShowCallback onWndShowCallback = new UEyeCapturerLibrary.OnWndShowCallback() { public void invoke(boolean visible) { System.out.println("Window visibility set to " + visible); } }; Frame frame = new Frame(String.valueOf(windowName)); Canvas canvas = new Canvas(); frame.add(canvas); frame.setIgnoreRepaint(true); frame.setBackground(Color.black); frame.setSize(1440, 900); frame.setVisible(true); frame.pack(); Pointer newPointer = Native.getComponentPointer(canvas); result = UEyeCapturerLibrary.StartRunning( cameraHandle, settingsFile, monitorId, onWndShowCallback, newPointer); try { Thread.sleep(5000); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } result = UEyeCapturerLibrary.StopRunning(cameraHandle); frame.remove(canvas); frame.validate(); try { Thread.sleep(2000); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } frame.add(canvas); frame.validate(); Pointer otherPointer = Native.getComponentPointer(canvas); assert (otherPointer.equals(newPointer)); result = UEyeCapturerLibrary.StartRunning( cameraHandle, settingsFile, monitorId, onWndShowCallback, otherPointer); try { Thread.sleep(3000); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } System.out.println(UEyeCapturerLibrary.Dispose(cameraHandle)); }