void QuickTimePlayer::draw()
{
	gl::clear( Color( 0, 0, 0 ) );
	gl::enableAlphaBlending();

	if( mFrameTexture ) {
		Rectf centeredRect = Rectf( mFrameTexture.getBounds() ).getCenteredFit( getWindowBounds(), true );
		gl::draw( mFrameTexture, centeredRect  );
		
		if (bInitialized)
		{
			spoutsender.SendTexture(mFrameTexture.getId(), mFrameTexture.getTarget(), g_Width, g_Height, false);
		}
	}

	if( mInfoTexture ) {
		glDisable( GL_TEXTURE_RECTANGLE_ARB );
		gl::draw( mInfoTexture, Vec2f( 20, getWindowHeight() - 20 - mInfoTexture.getHeight() ) );
	}
}
Esempio n. 2
0
void ARTestApp::update()
{

	ARMarkerInfo    *marker_info;					// Pointer to array holding the details of detected markers.
    int             marker_num;						// Count of number of markers detected.
    int             j, k;
	
	// Grab a video frame.
#if defined( USE_AR_VIDEO )
	ARUint8 *image;
	if ((image = arVideoGetImage()) != NULL) {
#else
	if( mCapture->checkNewFrame() ) {
#endif

#if defined( USE_AR_VIDEO )
		gARTImage = image;	// Save the fetched image.
		mTexture->enableAndBind();
#else
		const fli::Surface8u &surface( mCapture->getSurface() );
		mTexture->update( surface );
		gARTImage = const_cast<uint8_t*>( surface.getData() );
#endif

		gCallCountMarkerDetect++; // Increment ARToolKit FPS counter.
		
		// Detect the markers in the video frame.
		if (arDetectMarker(gARTImage, gARTThreshhold, &marker_info, &marker_num) < 0) {
			exit(-1);
		}
		
		// check for known patterns
		for( int i = 0; i < objectnum; i++ ) {
			k = -1;
			for( j = 0; j < marker_num; j++ ) {
				if( object[i].id == marker_info[j].id) {

					/* you've found a pattern */
					if( k == -1 ) k = j;
					else /* make sure you have the best pattern (highest confidence factor) */
						if( marker_info[k].cf < marker_info[j].cf ) k = j;
				}
			}
			if( k == -1 ) {
				object[i].visible = 0;
				continue;
			}
			/* calculate the transform for each marker */
			if( object[i].visible == 0 ) {
				arGetTransMat(&marker_info[k],
							  object[i].marker_center, object[i].marker_width,
							  object[i].trans);
			}
			else {
				arGetTransMatCont(&marker_info[k], object[i].trans,
							  object[i].marker_center, object[i].marker_width,
							  object[i].trans);
			}
			object[i].visible = 1;
		}
	}

	if( mLockedMode >= 0 ) {
		for( int i = 0; i < objectnum; i++ ) {
			object[i].visible = 0;
		}
		object[mLockedMode].visible = 1;
	}

	for( int mod = 0; mod < objectnum; ++mod )
		mModules[mod]->update( this, object[mod].visible );
}

void ARTestApp::draw()
{
    GLdouble p[16];
	GLdouble m[16];
	
	// Select correct buffer for this context.
	glClearColor( 0, 0, 0, 1 ); // Clear the buffers for new frame.
	gl::enableDepthWrite();
	glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); // Clear the buffers for new frame.
	
	gl::disableDepthRead();
	gl::disableDepthWrite();
	gl::enableAlphaBlending();

	if( object[0].visible || object[1].visible || object[2].visible ) 
		mCurrentAlpha += ( 0.0f - mCurrentAlpha ) * 0.05f;
	else
		mCurrentAlpha += ( 1.0f - mCurrentAlpha ) * 0.05f;
	
	gl::setMatricesScreenOrtho( getWindowWidth(), getWindowHeight() );
	// draw the camera image centered
	glColor4f( 1, 1, 1, 1 );//0.2f + mCurrentAlpha * 0.8f );
	float width = ( getWindowHeight() * ( mTexture->getWidth() / (float)mTexture->getHeight() ) );
	mTexture->draw( ( getWindowWidth() - width ) / 2.0f, 0, width, getWindowHeight() );
	glDisable( mTexture->getTarget() );
	
#if defined( USE_AR_VIDEO )	
	arVideoCapNext();
	gARTImage = NULL; // Image data is no longer valid after calling arVideoCapNext().
#endif				

	// Projection transformation.
	arglCameraFrustumRH( &gARTCparam, VIEW_DISTANCE_MIN, VIEW_DISTANCE_MAX, p );
	glMatrixMode( GL_PROJECTION );
	glLoadMatrixd( p );
		
	// Calculate the camera position relative to the marker.
	// Replace VIEW_SCALEFACTOR with 1.0 to make one drawing unit equal to 1.0 ARToolKit units (usually millimeters).
	for( int mod = 0; mod < objectnum; ++mod ) {
		if( object[mod].visible ) {
			arglCameraViewRH( object[mod].trans, m, VIEW_SCALEFACTOR );
			glMatrixMode(GL_MODELVIEW);
			glLoadMatrixd( m );
			fli::Matrix44d mvd( m );
			mModules[mod]->draw( this, mvd * Vec4d( 0, 0, 0, 1 ) );
		}
	}
}
void FadeCandyClientApp::draw()
{
	unsigned int width, height;
	char txt[256];

	// clear out the window with black
	gl::clear( Color( 0, 0, 0 ) );
	gl::setViewport( getWindowBounds() );
	gl::color( Color(1,1,1) );
	gl::setMatrices( mMayaCam.getCamera() );
	effectRunner->draw();

	//draw debug info
	gl::setMatricesWindow( getWindowSize() );
	
	Font mDefault;
	#if defined( CINDER_COCOA )        
				mDefault = Font( "Helvetica", 16 );
	#elif defined( CINDER_MSW )    
				mDefault = Font( "Arial", 16 );
	#endif
	gl::enableAlphaBlending();
	gl::drawStringCentered(effectRunner->getDebugString(),Vec2f(getWindowCenter().x,5),Color(1,1,1),mDefault);
	gl::disableAlphaBlending();

	// Save current global width and height - they will be changed
	// by receivetexture if the sender changes dimensions
	width  = g_Width;
	height = g_Height;
	//
	// Try to receive the texture at the current size 
	//
	// NOTE :
	// if the host calls SendTexture with a framebuffer object actively bound
	// the host must provide the GL handle to its EXT_framebuffer_object
	// so that the dll can restore that binding because it makes use of its
	// own FBO for intermediate rendering - default is 0 for no bound host FBO - see Spout.h
	//
	if(bInitialized && spoutTexture) {

		if(!ReceiveTexture(SenderName, spoutTexture.getId(), spoutTexture.getTarget(), width, height)) {
			//
			// Receiver failure :
			//	1)	width and height are zero for read failure.
			//	2)	width and height are changed for sender change
			//		The local texture then has to be resized.
			//
			if(width == 0 || height == 0) {
				// width and height are returned zero if there has been 
				// a texture read failure which might happen if the sender
				// is closed. Spout will keep trying and if the same sender opens again
				// will use it. Otherwise the user can select another sender.
				return;
			}

			if(width != g_Width || height != g_Height ) {
				// The sender dimensions have changed
				// Update the global width and height
				g_Width  = width;
				g_Height = height;
				// Update the local texture to receive the new dimensions
				spoutTexture =  gl::Texture(g_Width, g_Height);
				
				return; // quit for next round
			}
		}
		else {

			spoutSurf = Surface(spoutTexture);
			e->mSurf = spoutSurf;
			
		}
	}
}