예제 #1
0
void
WorkflowRenderer::startPreview()
{
    if ( m_mainWorkflow->getLengthFrame() <= 0 )
        return ;
    if ( paramsHasChanged( m_width, m_height, m_outputFps, m_aspectRatio ) == true )
    {
        m_width = width();
        m_height = height();
        m_outputFps = outputFps();
        m_aspectRatio = aspectRatio();
    }
    initFilters();

    setupRenderer( m_width, m_height, m_outputFps );

    m_mainWorkflow->setFullSpeedRender( false );
    m_mainWorkflow->startRender( m_width, m_height, m_outputFps );
    m_isRendering = true;
    m_paused = false;
    m_stopping = false;
    m_pts = 0;
    m_audioPts = 0;
    m_sourceRenderer->start();
}
예제 #2
0
bool VolumetricFog::onAdd()
{
	if (!Parent::onAdd())
		return false;

	if (!VFRTM->IsInitialized())
	{
		Con::errorf("No VolumetricFogRTManager present!!");
		return false;
	}

	resetWorldBox();

	mShapeLoaded = LoadShape();

	setRenderTransform(mObjToWorld);

	addToScene();
	ColBox.set(getTransform(), (mObjBox.getExtents() * getScale() * COLBOX_SCALE));
	mObjSize = mWorldBox.getGreatestDiagonalLength();
	mObjScale = getScale();
	mTexTiles = mAbs(mTexTiles);
	mSpeed.set(mSpeed1.x, mSpeed1.y, mSpeed2.x, mSpeed2.y);
	mInvScale = (1.0f / getMax(getMax(mObjScale.x, mObjScale.y), mObjScale.z));
	if (isClientObject())
	{
		InitTexture();
		return setupRenderer();
	}

	VFRTM->IncFogObjects();

	return true;
}
예제 #3
0
bool Window::create(const Vec2i& size, const std::string& title, uint32_t flags) {
    // Clean up
    close();

    // Make sure SDL video was initialized
    if(!SDL_WasInit(SDL_INIT_VIDEO)) {
        ERR_PRINT(priv::c_prefError, "SDL Video was not initialized yet");

        return false;
    }

    // Create the window
    m_handle = SDL_CreateWindow(title.c_str(),
                                SDL_WINDOWPOS_CENTERED,
                                SDL_WINDOWPOS_CENTERED,
                                size.w,
                                size.h,
                                flags | SDL_WINDOW_OPENGL);

    m_context = SDL_GL_CreateContext(m_handle);
    // Make sure window context was created, print errors otherwise
    if(!m_context) {
        ERR_PRINT(
                priv::c_prefError,
                "Failed to crate window context with following errors: " +
                std::string(SDL_GetError())
        );

        // Also make sure to cleanup the window
        SDL_DestroyWindow(m_handle);

        return false;
    }

    // If Glew failed to initialize
    if(!initGlew()) {
        // Clean up
        close();

        return false;
    }

    // Setup renderer buffers
    setupRenderer(size);

    // Turn off V-sync (if enabled by the graphics card)
    if(SDL_GL_SetSwapInterval(0) < 0) {
        ERR_PRINT(
                priv::c_prefError,
                "Failed to set swap interval with following errors: " +
                std::string(SDL_GetError())
        );
    }

    m_isOpen = true;
    return true;
}
예제 #4
0
bool VolumetricFog::onAdd()
{
    if (!Parent::onAdd())
        return false;

    if (!VFRTM->IsInitialized())
    {
        Con::errorf("No VolumetricFogRTManager present!!");
        return false;
    }

    resetWorldBox();

    mShapeLoaded = LoadShape();

    setRenderTransform(mObjToWorld);

    addToScene();
    ColBox.set(getTransform(), (mObjBox.getExtents() * getScale() * COLBOX_SCALE));
    mObjSize = mWorldBox.getGreatestDiagonalLength();
    mObjScale = getScale();
    mTexTiles = mAbs(mTexTiles);
    mSpeed.set(mSpeed1.x, mSpeed1.y, mSpeed2.x, mSpeed2.y);
    mInvScale = (1.0f / getMax(getMax(mObjScale.x, mObjScale.y), mObjScale.z));

    if (isClientObject())
    {
        conn = GameConnection::getConnectionToServer();
        if (!conn)
        {
            Con::errorf("VolumetricFog::onAdd - No Serverconnection");
            return false;
        }

        glowFX = static_cast<PostEffect*>(Sim::findObject("VolFogGlowPostFx"));

        mOldLightRayStrength = Con::getFloatVariable("$LightRayPostFX::brightScalar",1.0f);

        GuiCanvas* cv = dynamic_cast<GuiCanvas*>(Sim::findObject("Canvas"));
        if (cv == NULL)
        {
            Con::errorf("VolumetricFog::onAdd - Canvas not found!!");
            return false;
        }
        mPlatformWindow = cv->getPlatformWindow();
        VolumetricFogRTManager::getVolumetricFogRTMResizeSignal().notify(this, &VolumetricFog::handleResize);
        GuiCanvas::getCanvasSizeChangeSignal().notify(this, &VolumetricFog::handleCanvasResize);

        InitTexture();
        return setupRenderer();
    }

    VFRTM->IncFogObjects();

    return true;
}
예제 #5
0
파일: main.cpp 프로젝트: karmeli87/cg
int main(int argc, char* argv[])
{
  const unsigned int uiWidth = 800;
  const unsigned int uiHeight = 600;

  glutInit( &argc, argv );                                      // initialize library

  glutInitContextVersion(3, 2);                                 // open a OpenGL 3.2 context

  glutInitWindowSize( uiWidth, uiHeight );                      // set desired window size
  // asks for double buffering and z-buffer as well as anti-aliasing support
  glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH | GLUT_MULTISAMPLE);

  glutCreateWindow( "OpenGL Example Program" );                 // opens the window and return the window id

  glewExperimental = GL_TRUE;                                   // To support also drivers that are not fully implemented
  glewInit();                                                   // initialize glew, OpenGL context must already be available!!

  // setup the renderer
  setupRenderer( );
  g_pcRenderer->setWindowSize(uiWidth, uiHeight);
  // initialize the scene and OpenGL state
  g_pcRenderer->initGL();

  // set callback functions
  glutDisplayFunc( &displayCallback );                          // sets the callback for redrawing
  glutReshapeFunc( &reshapeCallback );                          // set the callback in case of window resizing
  glutKeyboardFunc( &keyboardCallback );                        // set the callback for key presses
  glutMotionFunc(onMouseDrag);
  glutMouseFunc(onMouseClick);

  std::cout << "press q to quit" << std::endl;
  std::cout << "press k to turn left" << std::endl;
  std::cout << "press l to turn right" << std::endl;
  std::cout << "press a to turn forward" << std::endl;
  std::cout << "press y to turn backward" << std::endl;
  std::cout << "press + to move forward" << std::endl;
  std::cout << "press - to move backward" << std::endl;
  std::cout << "press n for next demo" << std::endl;

  glutMainLoop();

  // free renderer
  if( g_pcRenderer) 
  {
    g_pcRenderer->uninitGL();
    delete g_pcRenderer;
  }

  return 0;
}
예제 #6
0
파일: CCEngine.cpp 프로젝트: Shushman/multi
bool CCEngine::setupEngineThread()
{
    CCCameraBase::SetVisibleSortFunction( &ZCompare );

    const bool rendererSetup = setupRenderer();

    controls = new CCDeviceControls();

    if( rendererSetup )
    {
        start();
    }

    engineThreadRunning = true;
    return rendererSetup;
}
예제 #7
0
파일: main.cpp 프로젝트: karmeli87/cg
void keyboardCallback( unsigned char key, int x, int y)
{
  switch( key ) 
  {
  case 'q':
    glutLeaveMainLoop();
    break;

  case 'k':
    g_pcRenderer->rotY( 2.0f );
    break;

  case 'l':
    g_pcRenderer->rotY( -2.0f );
    break;

  case 'a':
    g_pcRenderer->rotX(2.0f);
    break;

  case 'y':
    g_pcRenderer->rotX(-2.0f);
    break;

  case '+':
    g_pcRenderer->transZ(0.98f);
    break;

  case '-':
    g_pcRenderer->transZ(1.0f/0.98f);
    break;

  case 'n':
    g_iRenderer++;
    setupRenderer();
    g_pcRenderer->initGL();
    break;

  default:
    g_pcRenderer->keyPressed(key);
  }

  g_pcRenderer->renderCamera();
  glutPostRedisplay();                                          // creates an event for redrawing (calls displayCallback() )
}
예제 #8
0
int Renderer::begin() {
	setupRenderer();
    if (fragmentShaderPath == "" || vertexShaderPath == "") {
        std::cout << "WARNING: no shader loaded..." << std::endl;
    }
    if (objects.size() == 0) {
        std::cout << "WARNING: no objects loaded..." << std::endl;
    }
	_shaderProgram = setupShaders();
	if (!_shaderProgram) {
		std::cout << "ERROR: Falied to initialize shaders." << std::endl;
		return 1;
	}
	std::cout << "Started visualization with " << objects.size() << " objects." << std::endl;
	runMainLoop(_window, _shaderProgram);
	terminate();
	return 0;
}
예제 #9
0
파일: main.cpp 프로젝트: karmeli87/cg
void
setupRenderer()
{
  if( g_pcRenderer ) 
  {
    g_pcRenderer->uninitGL();
    delete g_pcRenderer;
    g_pcRenderer = NULL;
  }

  if( 0 == g_iRenderer ) 
  {
    std::cout << std::endl << "Render a simple triangle" << std::endl;
    g_pcRenderer = new RenderTriangle;
  }
  else 
  {
    g_iRenderer = 0;
    setupRenderer();
  }
}
예제 #10
0
void setup(){
	initRenderer();
	setupRenderer();
	trackball (qCamera, 0, 0, 0, 0); // qCameraOld[3] = 1.0;

	lists = new ListKeeper( 16 );

/*
	int ifree = lists->getFree();
	int igl=glGenLists(1);
	glNewList( igl , GL_COMPILE);
		//drawLines( nlinks, links, (Vec3d*) points );
		drawBox( -0.5, +0.5,   -0.5, +0.5,   -0.5, +0.5,   0.5, 0.8, 0.5 );
	glEndList();
	lists->data[ ifree ] = igl;
*/

/*
	int ndiv = 5;
	Vec3d pos; pos.set(0,0,0);
	int ifree = lists->getFree();
	int igl=glGenLists(1);
	glNewList( igl , GL_COMPILE);
		glShadeModel ( GL_SMOOTH );
		int nvert = drawSphere_oct( ndiv, 2.5, pos );
	glEndList();
	lists->data[ ifree ] = igl;
	printf( " sphere %i nvert %i \n", ndiv, nvert );
*/

	//Vec3f tip;   tip.set(3.00,0,0);
	//Vec3f base;  base.set(0,0.0,0.0); 

/*
	Vec3f tip;   tip.set (0.000,0.00,0.00);
	Vec3f base;  base.set(1.0,2.0,3.0); 

	int ndiv = 16;
	Vec3d pos; pos.set(0,0,0);
	int ifree = lists->getFree();
	int igl=glGenLists(1);
	glNewList( igl , GL_COMPILE);
		glShadeModel ( GL_SMOOTH );
		//int nvert = drawConeFan( ndiv, 0.5, base, tip );
		int nvert = drawCylinderStrip( ndiv, 0.5, 1.0, base, tip );
	glEndList();
	lists->data[ ifree ] = igl;
	printf( " sphere %i nvert %i \n", ndiv, nvert );
*/



	int npoints,nbonds;
	int   * bonds;
	int   * bondTypes;
	Vec3d * points;

	int ndiv = 16;
	Vec3d dir,side,up;
	dir .set( 1,0,0 );
	side.set( 0,0,1 );
	up  .set( 0,1,0 );
	makeGirder_Type1( ndiv, 32.0, 1.0, dir,side,up,  npoints, nbonds, points, bonds, bondTypes); 
 
	int ifree = lists->getFree();
	int igl=glGenLists(1);
	glNewList( igl , GL_COMPILE);
		int nvert = drawGirder( npoints, nbonds, points, bonds, bondTypes );
	glEndList();
	lists->data[ ifree ] = igl;
	printf( " girder ndiv = %i nvert %i \n", ndiv, nvert );

	bondTypeBook = new BondTypes( def_nBondTypes, def_bondTypes_area, def_bondTypes_material );
	truss        = new SoftBody( npoints, nbonds, 4, points, NULL, NULL, bonds, bondTypes, *bondTypeBook, &def_fix[0] );

	//colors= &colors_def[0];
	//radii = &radii_def [0];

}
예제 #11
0
파일: iARenderer.cpp 프로젝트: 3dct/open_iA
void iARenderer::initialize( vtkImageData* ds, vtkPolyData* pd, int e )
{
	imageData = ds;
	polyData = pd;
	cellLocator->SetDataSet(polyData);
	if(polyData)
		if( polyData->GetNumberOfCells() )
			cellLocator->BuildLocator();
	ext = e;
	double spacing[3];	ds->GetSpacing(spacing);
	ren->SetLayer(0);
	ren->UseDepthPeelingOn();
#if (VTK_MAJOR_VERSION >= 8 && defined(VTK_OPENGL2_BACKEND) && QT_VERSION >= 0x050400 )
	ren->UseDepthPeelingForVolumesOn();
#endif
	labelRen->SetLayer(1);
	labelRen->InteractiveOff();
	labelRen->UseDepthPeelingOn();
	renWin->SetNumberOfLayers(5);
	renWin->AddRenderer(ren);
	renWin->AddRenderer(labelRen);
	interactor = renWin->GetInteractor();
	setPointPicker();	
	InitObserver();

	QImage img;
	img.load(":/images/fhlogo.png");
	logoImage->SetQImage(&img);
	logoImage->Update();
	logoRep->SetImage(logoImage->GetOutput( ));
	logoWidget->SetInteractor(interactor);
	logoWidget->SetRepresentation(logoRep);
	logoWidget->SetResizable(false);
	logoWidget->SetSelectable(true);
	logoWidget->On();

	interactor->Initialize();

	// setup cube source
	cSource->SetXLength(ext * spacing[0]);
	cSource->SetYLength(ext * spacing[1]);
	cSource->SetZLength(ext * spacing[2]);
	cMapper->SetInputConnection(cSource->GetOutputPort());
	cActor->SetMapper(cMapper);
	cActor->GetProperty()->SetColor(1,0,0);

	setupCutter();
	setupCube();
	setupAxes(spacing);
	setupOrientationMarker();
	setupRenderer();

	labelRen->SetActiveCamera(cam);
	ren->SetActiveCamera(cam);
	setCamPosition( 0,0,1, 1,1,1 ); // +Z

	m_profileLineMapper->SetInputConnection(m_profileLineSource->GetOutputPort());
	m_profileLineActor->SetMapper(m_profileLineMapper);
	m_profileLineStartPointMapper->SetInputConnection(m_profileLineStartPointSource->GetOutputPort());
	m_profileLineStartPointActor->SetMapper(m_profileLineStartPointMapper);
	m_profileLineEndPointMapper->SetInputConnection(m_profileLineEndPointSource->GetOutputPort());
	m_profileLineEndPointActor->SetMapper(m_profileLineEndPointMapper);
	m_profileLineActor->GetProperty()->SetColor(0.59, 0.73, 0.94);//ffa800//150, 186, 240
	m_profileLineActor->GetProperty()->SetLineWidth(2.0);
	m_profileLineActor->GetProperty()->SetLineStipplePattern(0x00ff);//0xf0f0
	m_profileLineActor->GetProperty()->SetLineStippleRepeatFactor(1);
	m_profileLineActor->GetProperty()->SetPointSize(2);
	m_profileLineStartPointSource->SetRadius(2 * spacing[0]);
	m_profileLineEndPointSource->SetRadius(2 * spacing[0]);
	m_profileLineStartPointActor->GetProperty()->SetColor(1.0, 0.65, 0.0);
	m_profileLineEndPointActor->GetProperty()->SetColor(0.0, 0.65, 1.0);


	 //slicing cube settings for surface extraction
	 m_sliceCubeMapper->SetInputConnection(m_slicingCube->GetOutputPort());
	 m_sliceCubeActor->SetMapper(m_sliceCubeMapper);
	 m_sliceCubeActor->GetProperty()->SetColor(1.0, 0, 0);
	 m_sliceCubeActor->GetProperty()->SetRepresentationToWireframe();
	 m_sliceCubeActor->GetProperty()->SetOpacity(1); 
	 m_sliceCubeActor->GetProperty()->SetLineWidth(2.3); 	 
	 m_sliceCubeActor->GetProperty()->SetAmbient(1.0);
	 m_sliceCubeActor->GetProperty()->SetDiffuse(0.0);
	 m_sliceCubeActor->GetProperty()->SetSpecular(0.0);
	 
	 m_sliceCubeActor->SetVisibility(false);

	 this->	setArbitraryProfileOn(false);

	double center[3], origin[3];
	const int * dim = imageData->GetDimensions();
	if (dim[0] == 0 || dim[1] == 0 || dim[2] == 0)
		return;
	const double * spc = imageData->GetSpacing();
	for (int i = 0; i < 3; ++i)
	{
		center[i] = dim[i] * spc[i] / 2;
		origin[i] = 0;
	}
	for (int s = 0; s < 3; ++s)
	{
		m_slicePlaneSource[s]->SetOrigin(origin);
		double point1[3], point2[3];
		for (int j = 0; j < 3; ++j)
		{
			point1[j] = 0;
			point2[j] = 0;
		}
		point1[GetSliceAxis(s, 0)] += 1.1 * dim[GetSliceAxis(s, 0)] * spc[GetSliceAxis(s, 0)];
		point2[GetSliceAxis(s, 1)] += 1.1 * dim[GetSliceAxis(s, 1)] * spc[GetSliceAxis(s, 1)];
		m_slicePlaneSource[s]->SetPoint1(point1);
		m_slicePlaneSource[s]->SetPoint2(point2);
		m_slicePlaneSource[s]->SetCenter(center);
		m_slicePlaneMapper[s]->SetInputConnection(m_slicePlaneSource[s]->GetOutputPort());
		m_slicePlaneActor[s]->SetMapper(m_slicePlaneMapper[s]);
		m_slicePlaneActor[s]->GetProperty()->SetColor( (s == 0) ? 1:0, (s == 1) ? 1 : 0, (s == 2) ? 1 : 0);
		m_slicePlaneActor[s]->GetProperty()->SetOpacity(1.0);
		m_slicePlaneActor[s]->SetVisibility(false);
		m_slicePlaneMapper[s]->Update();
	}
}
OMX_ERRORTYPE NonTextureEngine::onCameraEventParamOrConfigChanged()
{

	ofLogVerbose(__func__) << "START";
	
	OMX_ERRORTYPE error = OMX_SendCommand(camera, OMX_CommandStateSet, OMX_StateIdle, NULL);
	if (error != OMX_ErrorNone) 
	{
		ofLog(OF_LOG_ERROR, "camera OMX_SendCommand OMX_StateIdle FAIL error: 0x%08x", error);
	}
	
	//Enable Camera Output Port
	OMX_CONFIG_PORTBOOLEANTYPE cameraport;
	OMX_INIT_STRUCTURE(cameraport);
	cameraport.nPortIndex = CAMERA_OUTPUT_PORT;
	cameraport.bEnabled = OMX_TRUE;
	
	error =OMX_SetParameter(camera, OMX_IndexConfigPortCapturing, &cameraport);	
	if (error != OMX_ErrorNone) 
	{
		ofLog(OF_LOG_ERROR, "camera enable Output Port FAIL error: 0x%08x", error);
	}
	
	
	
	if (omxCameraSettings.doRecording) 
	{		
		if (omxCameraSettings.doRecordingPreview) 
		{
			//Set up renderer
			setupRenderer();
		} 
		
		
		//set up encoder
		OMX_CALLBACKTYPE encoderCallbacks;
		encoderCallbacks.EventHandler		= &BaseEngine::encoderEventHandlerCallback;
		encoderCallbacks.EmptyBufferDone	= &BaseEngine::encoderEmptyBufferDone;
		encoderCallbacks.FillBufferDone		= &NonTextureEngine::encoderFillBufferDone;
		
		
		string encoderComponentName = "OMX.broadcom.video_encode";
		
		error =OMX_GetHandle(&encoder, (OMX_STRING)encoderComponentName.c_str(), this , &encoderCallbacks);
		if (error != OMX_ErrorNone) 
		{
			ofLog(OF_LOG_ERROR, "encoder OMX_GetHandle FAIL error: 0x%08x", error);
		}
		
		configureEncoder();
		
		if (omxCameraSettings.doRecordingPreview) 
		{
			//Create camera->video_render Tunnel
			error = OMX_SetupTunnel(camera, CAMERA_PREVIEW_PORT, render, VIDEO_RENDER_INPUT_PORT);
			if (error != OMX_ErrorNone) 
			{
				ofLog(OF_LOG_ERROR, "camera->video_render OMX_SetupTunnel FAIL error: 0x%08x", error);
			}
		}

		// Tunnel camera video output port and encoder input port
		error = OMX_SetupTunnel(camera, CAMERA_OUTPUT_PORT, encoder, VIDEO_ENCODE_INPUT_PORT);
		if(error != OMX_ErrorNone) 
		{
			ofLog(OF_LOG_ERROR, "CAMERA_OUTPUT_PORT->VIDEO_ENCODE_INPUT_PORT OMX_SetupTunnel FAIL error: 0x%08x", error);
		}

		
		//Set encoder to Idle
		error = OMX_SendCommand(encoder, OMX_CommandStateSet, OMX_StateIdle, NULL);
		if (error != OMX_ErrorNone) 
		{
			ofLog(OF_LOG_ERROR, "encoder OMX_SendCommand OMX_StateIdle FAIL error: 0x%08x", error);
		}
		
		//Set camera to Idle
		error = OMX_SendCommand(camera, OMX_CommandStateSet, OMX_StateIdle, NULL);
		if (error != OMX_ErrorNone) 
		{
			ofLog(OF_LOG_ERROR, "camera OMX_SendCommand OMX_StateIdle FAIL error: 0x%08x", error);
		}
		
		if (omxCameraSettings.doRecordingPreview)
		{
			//Enable camera preview port
			error = OMX_SendCommand(camera, OMX_CommandPortEnable, CAMERA_PREVIEW_PORT, NULL);
			if (error != OMX_ErrorNone) 
			{
				ofLog(OF_LOG_ERROR, "camera OMX_CommandPortEnable CAMERA_PREVIEW_PORT FAIL error: 0x%08x", error);
			}
		}
	
		//Enable camera output port
		error = OMX_SendCommand(camera, OMX_CommandPortEnable, CAMERA_OUTPUT_PORT, NULL);
		if (error != OMX_ErrorNone) 
		{
			ofLog(OF_LOG_ERROR, "camera OMX_CommandPortEnable CAMERA_OUTPUT_PORT FAIL error: 0x%08x", error);
		}
		
		//Enable encoder input port
		error = OMX_SendCommand(encoder, OMX_CommandPortEnable, VIDEO_ENCODE_INPUT_PORT, NULL);
		if (error != OMX_ErrorNone) 
		{
			ofLog(OF_LOG_ERROR, "encoder OMX_CommandPortEnable VIDEO_ENCODE_INPUT_PORT FAIL error: 0x%08x", error);
		}
		
		//Enable encoder output port
		error = OMX_SendCommand(encoder, OMX_CommandPortEnable, VIDEO_ENCODE_OUTPUT_PORT, NULL);
		if (error != OMX_ErrorNone) 
		{
			ofLog(OF_LOG_ERROR, "encoder OMX_CommandPortEnable VIDEO_ENCODE_OUTPUT_PORT FAIL error: 0x%08x", error);
		}
		
		if (omxCameraSettings.doRecordingPreview) 
		{
			//Enable render input port
			error = OMX_SendCommand(render, OMX_CommandPortEnable, VIDEO_RENDER_INPUT_PORT, NULL);
			if (error != OMX_ErrorNone) 
			{
				ofLog(OF_LOG_ERROR, "render enable output port FAIL error: 0x%08x", error);
			}
		}

		OMX_PARAM_PORTDEFINITIONTYPE encoderOutputPortDefinition;
		OMX_INIT_STRUCTURE(encoderOutputPortDefinition);
		encoderOutputPortDefinition.nPortIndex = VIDEO_ENCODE_OUTPUT_PORT;
		error =OMX_GetParameter(encoder, OMX_IndexParamPortDefinition, &encoderOutputPortDefinition);
		if (error != OMX_ErrorNone) 
		{
			ofLog(OF_LOG_ERROR, "encoder OMX_GetParameter OMX_IndexParamPortDefinition FAIL error: 0x%08x", error);
		}else 
		{
			ofLogVerbose(__func__) << "VIDEO_ENCODE_OUTPUT_PORT eColorFormat: " << OMX_Maps::getInstance().colorFormatTypes[encoderOutputPortDefinition.format.video.eColorFormat];
		}

		error =  OMX_AllocateBuffer(encoder, &encoderOutputBuffer, VIDEO_ENCODE_OUTPUT_PORT, NULL, encoderOutputPortDefinition.nBufferSize);
		if (error != OMX_ErrorNone) 
		{
			ofLog(OF_LOG_ERROR, "encoder OMX_AllocateBuffer VIDEO_ENCODE_OUTPUT_PORT FAIL error: 0x%08x", error);
			
		}
		

		//Start camera
		error = OMX_SendCommand(camera, OMX_CommandStateSet, OMX_StateExecuting, NULL);
		if (error != OMX_ErrorNone) 
		{
			ofLog(OF_LOG_ERROR, "camera OMX_StateExecuting FAIL error: 0x%08x", error);
		}
		
		//Start encoder
		error = OMX_SendCommand(encoder, OMX_CommandStateSet, OMX_StateExecuting, NULL);
		if (error != OMX_ErrorNone) 
		{
			ofLog(OF_LOG_ERROR, "encoder OMX_StateExecuting FAIL error: 0x%08x", error);		
		}
		
		if (omxCameraSettings.doRecordingPreview) 
		{
			
			//Start renderer
			error = OMX_SendCommand(render, OMX_CommandStateSet, OMX_StateExecuting, NULL);
			if (error != OMX_ErrorNone) 
			{
				ofLog(OF_LOG_ERROR, "render OMX_StateExecuting FAIL error: 0x%08x", error);		
			}
			
			setupDisplay();
			
		}
		
		
		error = OMX_FillThisBuffer(encoder, encoderOutputBuffer);
		
		if (error != OMX_ErrorNone) 
		{
			ofLog(OF_LOG_ERROR, "encoder OMX_FillThisBuffer FAIL error: 0x%08x", error);		
		}
		
		bool doThreadBlocking	= true;
		startThread(doThreadBlocking);
		
	}else 
	{
		setupRenderer();
		
		
		//Create camera->video_render Tunnel
		error = OMX_SetupTunnel(camera, CAMERA_OUTPUT_PORT, render, VIDEO_RENDER_INPUT_PORT);
		if (error != OMX_ErrorNone) 
		{
			ofLog(OF_LOG_ERROR, "camera->video_render OMX_SetupTunnel FAIL error: 0x%08x", error);
		}
		
		//Enable camera output port
		error = OMX_SendCommand(camera, OMX_CommandPortEnable, CAMERA_OUTPUT_PORT, NULL);
		if (error != OMX_ErrorNone) 
		{
			ofLog(OF_LOG_ERROR, "camera enable output port FAIL error: 0x%08x", error);
		}
		
		//Enable render input port
		error = OMX_SendCommand(render, OMX_CommandPortEnable, VIDEO_RENDER_INPUT_PORT, NULL);
		if (error != OMX_ErrorNone) 
		{
			ofLog(OF_LOG_ERROR, "render enable output port FAIL error: 0x%08x", error);
		}
		
		
		//Start renderer
		error = OMX_SendCommand(render, OMX_CommandStateSet, OMX_StateExecuting, NULL);
		if (error != OMX_ErrorNone) 
		{
			ofLog(OF_LOG_ERROR, "render OMX_StateExecuting FAIL error: 0x%08x", error);		
		}
		
		//Start camera
		error = OMX_SendCommand(camera, OMX_CommandStateSet, OMX_StateExecuting, NULL);
		if (error != OMX_ErrorNone) 
		{
			ofLog(OF_LOG_ERROR, "camera OMX_StateExecuting FAIL error: 0x%08x", error);
		}
		
		setupDisplay();
				
	}

	isOpen = true;
	return error;
}