public SingleARMarker(NyARParam i_cparam) throws Exception { JmfCaptureDeviceList devlist = new JmfCaptureDeviceList(); this._ar_param = i_cparam; // キャプチャリソースの準備 this._capture = devlist.getDevice(0); if (!this._capture.setCaptureFormat(SCREEN_X, SCREEN_Y, 30.0f)) { throw new NyARException(); } this._capture.setOnCapture(this); this._cap_image = new JmfNyARRGBRaster(this._capture.getCaptureFormat()); this._code_table[0] = NyARCode.createFromARPattFile(new FileInputStream(CARCODE_FILE1), 16, 16); this._code_table[1] = NyARCode.createFromARPattFile(new FileInputStream(CARCODE_FILE2), 16, 16); // OpenGLフレームの準備(OpenGLリソースの初期化、カメラの撮影開始は、initコールバック関数内で実行) Frame frame = new Frame("NyARToolkit[" + this.getClass().getName() + "]"); GLCanvas canvas = new GLCanvas(); frame.add(canvas); canvas.addGLEventListener(this); frame.addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); // ウインドウサイズの調整 frame.setVisible(true); Insets ins = frame.getInsets(); frame.setSize(SCREEN_X + ins.left + ins.right, SCREEN_Y + ins.top + ins.bottom); canvas.setBounds(ins.left, ins.top, SCREEN_X, SCREEN_Y); return; }
public SimpleLiteMStandard(INyARMarkerSystemConfig i_config) throws NyARException { JmfCaptureDeviceList devlist = new JmfCaptureDeviceList(); JmfCaptureDevice d = devlist.getDevice(0); d.setCaptureFormat(i_config.getScreenSize(), 30.0f); this._camera = new NyARJmfCamera(d); // create sensor system this._nyar = new NyARGlMarkerSystem(i_config); // create MarkerSystem this.ids[0] = this._nyar.addARMarker(ARCODE_FILE2, 16, 25, 80); this.ids[1] = this._nyar.addARMarker(ARCODE_FILE, 16, 25, 80); Frame frame = new Frame("NyARTK program"); frame.addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); GLCanvas canvas = new GLCanvas(); frame.add(canvas); canvas.addGLEventListener(this); NyARIntSize s = i_config.getNyARParam().getScreenSize(); frame.setVisible(true); Insets ins = frame.getInsets(); frame.setSize(s.w + ins.left + ins.right, s.h + ins.top + ins.bottom); canvas.setBounds(ins.left, ins.top, s.w, s.h); this._camera.start(); }
public void draw(GLCanvas canvas) { canvas.save(GLCanvas.SAVE_FLAG_ALPHA); canvas.multiplyAlpha(mAlpha / 255.0f); Rect b = mBounds; draw(canvas, b.left, b.top, b.width(), b.height()); canvas.restore(); }
public void recycle(GLCanvas canvas) { if (mBufferNames != null) { canvas.deleteBuffer(mBufferNames[0]); canvas.deleteBuffer(mBufferNames[1]); canvas.deleteBuffer(mBufferNames[2]); mBufferNames = null; } }
public Teste() { super("colormatrix"); caps = new GLCapabilities(); canvas = new GLCanvas(caps); canvas.addGLEventListener(this); canvas.addKeyListener(this); add(canvas); }
private void prepareBuffers(GLCanvas canvas) { mBufferNames = new int[3]; GL11 gl = canvas.getGLInstance(); GLId.glGenBuffers(3, mBufferNames, 0); gl.glBindBuffer(GL11.GL_ARRAY_BUFFER, mBufferNames[0]); gl.glBufferData( GL11.GL_ARRAY_BUFFER, mXyBuffer.capacity() * (Float.SIZE / Byte.SIZE), mXyBuffer, GL11.GL_STATIC_DRAW); gl.glBindBuffer(GL11.GL_ARRAY_BUFFER, mBufferNames[1]); gl.glBufferData( GL11.GL_ARRAY_BUFFER, mUvBuffer.capacity() * (Float.SIZE / Byte.SIZE), mUvBuffer, GL11.GL_STATIC_DRAW); gl.glBindBuffer(GL11.GL_ELEMENT_ARRAY_BUFFER, mBufferNames[2]); gl.glBufferData( GL11.GL_ELEMENT_ARRAY_BUFFER, mIndexBuffer.capacity(), mIndexBuffer, GL11.GL_STATIC_DRAW); // These buffers are never used again. mXyBuffer = null; mUvBuffer = null; mIndexBuffer = null; }
@Override public boolean onGLIdle(final GLCanvas canvas, final boolean renderRequested) { if (!mCancelled) { try { canvas.beginRenderTarget(mTexture); mRootPane.render(canvas); canvas.endRenderTarget(); } catch (final RuntimeException e) { mTexture = null; } } else { mTexture = null; } mResultReady.open(); return false; }
public void run() { setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setSize(640, 480); setLocationRelativeTo(null); setVisible(true); canvas.requestFocusInWindow(); }
// Draws the texture on to the specified rectangle. @Override public void draw(GLCanvas canvas, int x, int y, int width, int height) { RectF src = mSrcRect; RectF dest = mDestRect; float scaleX = (float) width / mWidth; float scaleY = (float) height / mHeight; synchronized (mTiles) { for (int i = 0, n = mTiles.length; i < n; ++i) { Tile t = mTiles[i]; src.set(0, 0, t.contentWidth, t.contentHeight); src.offset(t.offsetX, t.offsetY); mapRect(dest, src, 0, 0, x, y, scaleX, scaleY); src.offset(BORDER_SIZE - t.offsetX, BORDER_SIZE - t.offsetY); canvas.drawTexture(t, mSrcRect, mDestRect); } } }
// Draws a sub region of this texture on to the specified rectangle. public void draw(GLCanvas canvas, RectF source, RectF target) { RectF src = mSrcRect; RectF dest = mDestRect; float x0 = source.left; float y0 = source.top; float x = target.left; float y = target.top; float scaleX = target.width() / source.width(); float scaleY = target.height() / source.height(); synchronized (mTiles) { for (int i = 0, n = mTiles.length; i < n; ++i) { Tile t = mTiles[i]; src.set(0, 0, t.contentWidth, t.contentHeight); src.offset(t.offsetX, t.offsetY); if (!src.intersect(source)) continue; mapRect(dest, src, x0, y0, x, y, scaleX, scaleY); src.offset(BORDER_SIZE - t.offsetX, BORDER_SIZE - t.offsetY); canvas.drawTexture(t, src, dest); } } }
@Override public void draw(GLCanvas canvas, int x, int y, int width, int height) { synchronized (this) { if (!mHasTexture) return; mSurfaceTexture.updateTexImage(); mSurfaceTexture.getTransformMatrix(mTransform); // Flip vertically. canvas.save(GLCanvas.SAVE_FLAG_MATRIX); int cx = x + width / 2; int cy = y + height / 2; canvas.translate(cx, cy); canvas.scale(1, -1, 1); canvas.translate(-cx, -cy); canvas.drawTexture(mExtTexture, mTransform, x, y, width, height); canvas.restore(); } }
public static RawTexture newInstance(GLCanvas canvas) { int[] textureId = new int[1]; GL11 gl = canvas.getGLInstance(); gl.glGenTextures(1, textureId, 0); return new RawTexture(canvas, textureId[0]); }
public void draw(GLCanvas canvas, NinePatchTexture tex, int x, int y) { if (mBufferNames == null) { prepareBuffers(canvas); } canvas.drawMesh(tex, x, y, mBufferNames[0], mBufferNames[1], mBufferNames[2], mIdxCount); }