void loop()
{
    if (digitalRead(buttonPin))
    {
        if (state == 0)
        {
            setLights(HIGH, LOW, LOW);
            state = 1;
        }
        else if (state == 1)
        {
            setLights(HIGH, HIGH, LOW);
            state = 2;
        }
        else if (state == 2)
        {
            setLights(LOW, LOW, HIGH);
            state = 3;
        }
        else if (state == 3)
        {
            setLights(LOW, HIGH, LOW);
            state = 0;
        }
        delay(1000);
    }
}
Esempio n. 2
0
/**
 *	Head & Torso & Upper Body
 *
 **/
void upper_body(void){

	setLights(shirtRed, shirtGreen, shirtBlue);

	glColor3f(shirtRed, shirtGreen, shirtBlue);
	
	glTranslatef(0.0, 4.0, 0.0);
	
	glPushMatrix();
	
	glScalef(6.0, 3.0, 1.0);
	
	glutSolidCube(1.0);
	
	glPopMatrix();
	
	glPushMatrix();
	left_sholder();
	glPopMatrix();
	
	glPushMatrix();
	right_sholder();
	glPopMatrix();

	setLights(1.0, 0.92, 0.80);

	glColor3f(1.0, 0.92, 0.80);
	
}
Esempio n. 3
0
// Setup the environment for drawing
void Game::Render(){
	if( active ){
		//glClearColor(0, 0, 0, 0);
		glClearColor(79/255.0, 173/255.0, 240/255.0, 0);
		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

		glMatrixMode(GL_PROJECTION);
		glLoadMatrixf(camera.getProjectionMatrix());

		glMatrixMode(GL_MODELVIEW);
		glLoadMatrixf(camera.getViewMatrix());

		setLights(light, 0.5);

		// If in picking mode, draw the picking scene, else draw the normal scene
		if( picked ){
			draw_picking_scene();
			process_pick();
		}
		else{
			drawScene();
			SDL_GL_SwapBuffers();
		}
	}
}
void GLViewer::setStates()
{
  glClearColor(0.25f, 0.25f, 0.5f, 1.0f);

  glEnable(GL_DEPTH_TEST);
  glEnable(GL_CULL_FACE);
  glEnable(GL_LIGHTING);
  glEnable(GL_COLOR_MATERIAL);
  glEnable(GL_TEXTURE_2D);
  glEnable(GL_NORMALIZE);

  glMatrixMode(GL_PROJECTION);
   glPushMatrix();
   //glLoadIdentity();

  glMatrixMode(GL_MODELVIEW);
    glPushMatrix();
 // glLoadIdentity();

  setLights();

  float materialSpecular[] = {0.5f, 0.5f, 0.5f, 1.0f};
  glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, materialSpecular);
  glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 32.0f);


}
int initDEVICE(DEVICE *ret) {
	int i=0;

	if( startConnectionUE9(&ret->ue9) != 0 )
	{
		return -1;
	}

	for(i=0;i<4;i++)
	{
		ret->activeTrack[i]=false;
		ret->activeTrackSensor[i]=false;
	}
	ret->trafficLightStatus=4;
	if(setLights(ret) != 0)
		return -2;
	if( setPower( ret,0,false) !=0)
		return -2;
	if( setPower( ret,1,false) !=0)
		return -2;
	if( setPower( ret,2,false) !=0)
		return -2;
	if( setPower( ret,3,false) !=0)
		return -2;
	
	return 0;
}
Esempio n. 6
0
void torso(void){
	glTranslatef(0.0, 1.0, 0.0);

	setLights(shirtRed, shirtGreen, shirtBlue);

	glColor3f(shirtRed, shirtGreen, shirtBlue);
	
	glPushMatrix();
	
	glScalef(3.5, 3.0, 1.0);
	
	glutSolidCube(1.0);
	
	glPopMatrix();
	
	glPushMatrix();
	left_hip();
	glPopMatrix();
	
	glPushMatrix();
	right_hip();
	glPopMatrix();
	
	glColor3f(1.0, 0.92, 0.80);
	
}
Esempio n. 7
0
bool gxScene::begin( const vector<gxLight*> &lights ){

	if( dir3dDev->BeginScene()!=D3D_OK ) return false;

	//clear textures!
	int n;
	for( n=0;n<tex_stages;++n ){
		texstate[n].canvas=0;
		setTSS( n,D3DTSS_COLOROP,D3DTOP_DISABLE );
		setTSS( n,D3DTSS_ALPHAOP,D3DTOP_DISABLE );
		dir3dDev->SetTexture( n,0 );
	}

	//set light states
	_curLights.clear();
	for( n=0;n<8;++n ){
		if( n<lights.size() ){
			_curLights.push_back( lights[n] );
			dir3dDev->SetLight( n,&_curLights[n]->d3d_light );
		}else{
			dir3dDev->LightEnable( n,false );
		}
	}
	setLights();

	return true;
}
Esempio n. 8
0
void View::paintStatues(){
    // Clear the screen in preparation for the next frame. (Use a gray background instead of a
    // black one for drawing wireframe or normals so they will show up against the background.)
//    glClearColor(0, 0, 0, 0);
//    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glUseProgram(m_statueShaderProgramID);
    glEnable(GL_DEPTH_TEST);

    // Set scene uniforms.
    //clear lights first
    for (int i = 0; i < 10; i++) {
        std::ostringstream os;
        os << i;
        std::string indexString = "[" + os.str() + "]"; // e.g. [0], [1], etc.
        glUniform3f(glGetUniformLocation(m_statueShaderProgramID, ("lightColors" + indexString).c_str()), 0, 0, 0);
    }
    setLights(m_view);
    glUniformMatrix4fv(m_uniformLocs["p"], 1, GL_FALSE,
            glm::value_ptr(m_projection));
    glUniformMatrix4fv(m_uniformLocs["v"], 1, GL_FALSE,
            glm::value_ptr(m_view));
    glUniformMatrix4fv(m_uniformLocs["m"], 1, GL_FALSE,
            glm::value_ptr(glm::mat4()));
    glUniform3f(m_uniformLocs["allBlack"], 1, 1, 1);


    drawStatues();
    glDisable(GL_DEPTH_TEST);

    glUseProgram(0);
}
Esempio n. 9
0
// Fonction d'affichage avec gestion mode
void display(void)
{


    // Suppression du buffer
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    // Dessin des lumières
    if(iLight == 0) {
        glDisable(GL_LIGHTING);	// Désactive l'éclairage
        glDisable(GL_LIGHT0); // Désactive la lumière 1
    } else {
        glEnable(GL_LIGHTING);	// Active l'éclairage
        glEnable(GL_LIGHT0);	// Active la lumière 1
        setLights();

    }

    // Mode solide ou file de fer
    if(iMode == 1)
    {
        glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
    }
    else if(iMode == 0)
    {
        glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
    }

    // Gl Texture 2D
    if(iTexture) {
        glEnable(GL_TEXTURE_2D);
    }
    else {
        glDisable(GL_TEXTURE_2D);
    }

    // Dessin du monde avec ses éléments
    //drawWorld();
    drawWorld2();

    // Affichage des erreurs
    if(glGetError()) {
        int iGL_Error = glGetError();
        if(iGL_Error == 1282)
        {
            printf("Window close by user !");
            close();
            exit(0);
        }
        else if(iGL_Error != 0)
        {
            printf("Erreur OpenGL:%s\n",gluErrorString(glGetError()));
        }
    }


    glutSwapBuffers();
}
Esempio n. 10
0
void head(void){
	
	glTranslatef(0.0, -headUpDown, -headForward - 0.5);

       	setLights(1.0, 0.92, 0.80);
	
	glColor3f(1.0, 0.92, 0.80);
	
	glutSolidSphere(1.0, 10.0, 10.0);
	
}
Esempio n. 11
0
void left_foot(void){
	
	glTranslatef(0.0, -3.5, 0.0);

	setLights(0.0, 0.0, 0.0);
	
	glColor3f(0.0, 0.0, 0.0);
	glutSolidSphere(0.50, 10.0, 10.0);

	glColor3f(1.0, 0.92, 0.80);

}
Esempio n. 12
0
void GameScene::setStates()
{
    //    glShadeModel(GL_SMOOTH);
    glClearColor(0.0,0.65,1.0,0.5);
    //    glClearColor(0.0,0.0,0.0,0.2);
    glClearDepth(1.0f);
    glEnable(GL_DEPTH_TEST);                //启用深度测试
    glDepthFunc(GL_LEQUAL);
    glHint(GL_PERSPECTIVE_CORRECTION_HINT,GL_NICEST);

    glEnable(GL_CULL_FACE);                     //正面消隐
    glEnable(GL_LIGHTING);                          //光照
    //    glEnable(GL_COLOR_MATERIAL);
    glEnable(GL_TEXTURE_2D);                //2D材质
    glEnable(GL_NORMALIZE);                 //法线

    //        glBlendFunc(GL_SRC_ALPHA,GL_ONE);
    //            glDepthRange(0.0f,1.0f);
    //            glClearDepth(1.0f);
    //                glDepthFunc(GL_LEQUAL);
    //                glDepthMask(GL_FALSE);
    //反锯齿
    //    glEnable(GL_BLEND);
    //    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    //    glEnable(GL_POINT_SMOOTH);
    //    glHint(GL_POINT_SMOOTH_HINT, GL_NICEST);
    //    glEnable(GL_LINE_SMOOTH);
    //    glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
    //    glEnable(GL_POLYGON_SMOOTH);
    //    glHint(GL_POLYGON_SMOOTH_HINT, GL_NICEST);
    //    glHint(GL_PERSPECTIVE_CORRECTION_HINT,GL_DONT_CARE);
    //    glHint(GL_PERSPECTIVE_CORRECTION_HINT,GL_FASTEST);

    //png透明
    glEnable(GL_ALPHA_TEST);
    glAlphaFunc(GL_GREATER,0.1);

    glMatrixMode(GL_PROJECTION);            //设置矩阵模式
    glPushMatrix();
    glLoadIdentity();;

    glMatrixMode(GL_MODELVIEW);
    glPushMatrix();
    glLoadIdentity();

    setLights();

//    float materialSpecular[]={0.5f,0.5f,0.5f,1.0f};
//    glMaterialfv(GL_FRONT_AND_BACK,GL_SPECULAR,materialSpecular);           //设置有质感的光照效果
//    glMaterialf(GL_FRONT_AND_BACK,GL_SHININESS,32.0f);
}
Esempio n. 13
0
void OpenGLScene::render(SupportCanvas3D *context)
{
    // Clear the screen in preparation for the next frame. (Use a gray background instead of a
    // black one for drawing wireframe or normals so they will show up against the background.)
    if (settings.drawWireframe || settings.drawNormals) glClearColor(0.5f, 0.5f, 0.5f, 0.5f);
    else glClearColor(0, 0, 0, 0);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    // Get the active camera
    Camera *camera = context->getCamera();
    assert(camera);
    glm::mat4 viewMatrix = camera->getViewMatrix();

    glUseProgram(m_shader);

    // Set scene uniforms.
    clearLights();
    setLights(viewMatrix);
    glUniform1i(m_uniformLocs["useLighting"], settings.useLighting);
    glUniform1i(m_uniformLocs["useArrowOffsets"], GL_FALSE);
    glUniformMatrix4fv(m_uniformLocs["p"], 1, GL_FALSE,
            glm::value_ptr(camera->getProjectionMatrix()));
    glUniformMatrix4fv(m_uniformLocs["v"], 1, GL_FALSE,
            glm::value_ptr(viewMatrix));
    glUniformMatrix4fv(m_uniformLocs["m"], 1, GL_FALSE,
            glm::value_ptr(glm::mat4()));
    glUniform3f(m_uniformLocs["allBlack"], 1, 1, 1);


    renderGeometry();

    if (settings.drawWireframe)
    {
        glUniform3f(m_uniformLocs["allBlack"], 0, 0, 0);
        glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);

        renderGeometry();

        glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
    }
    // Render normals if specified.
    if (settings.drawNormals)
    {
        glUseProgram(m_shader);
        glUniform3f(m_uniformLocs["allBlack"], 0, 0, 0);
        this->renderNormals();
    }

    glUseProgram(0);
}
Esempio n. 14
0
void right_foot(void){
	
	glTranslatef(0.0, -3.5, 0.0);
	
	materialShininess[0] = 10.0;

	setLights(0.0, 0.0, 0.0);

	glColor3f(0.0, 0.0, 0.0);
	
	glutSolidSphere(0.50, 10.0, 10.0);

	glColor3f(1.0, 0.92, 0.80);
}
Esempio n. 15
0
void right_sholder(void){
	
	glTranslatef(-3.0, 0.2, 0.0);

	setLights(shirtRed, shirtGreen, shirtBlue);
	
	glColor3f(shirtRed, shirtGreen, shirtBlue);
	
	glRotatef(((fistPump / 5) - 70.0), 0.0, 0.0, 1.0);
	
	glutSolidSphere(0.80, 10.0, 10.0);
	
	right_arm();
}
Esempio n. 16
0
void Channel::frameDraw( const eq::uint128_t& )
{
    // Setup frustum
    EQ_GL_CALL( applyBuffer( ));
    EQ_GL_CALL( applyViewport( ));

    EQ_GL_CALL( glMatrixMode( GL_PROJECTION ));
    EQ_GL_CALL( glLoadIdentity( ));
    EQ_GL_CALL( applyFrustum( ));

    EQ_GL_CALL( glMatrixMode( GL_MODELVIEW ));
    EQ_GL_CALL( glLoadIdentity( ));

    // Setup lights before applying head transform, so the light will be
    // consistent in the cave
    const FrameData&    frameData   = _getFrameData();
    const eq::Matrix4f& rotation    = frameData.getRotation();
    const eq::Vector3f& translation = frameData.getTranslation();

    eq::Matrix4f     invRotationM;
    rotation.inverse( invRotationM );
    setLights( invRotationM );

    EQ_GL_CALL( applyHeadTransform( ));

    glTranslatef(  translation.x(), translation.y(), translation.z() );
    glMultMatrixf( rotation.array );

    Pipe*     pipe     = static_cast<Pipe*>( getPipe( ));
    Renderer* renderer = pipe->getRenderer();
    LBASSERT( renderer );

    const eq::Matrix4f& modelview = _computeModelView();

    // set fancy data colors
    const eq::Vector4f taintColor = _getTaintColor( frameData.getColorMode(),
                                                    getUniqueColor( ));
    const int normalsQuality = _getFrameData().getNormalsQuality();

    const eq::Range& range = getRange();
    renderer->render( range, modelview, invRotationM, taintColor,
                      normalsQuality );
    checkError( "error during rendering " );

    _drawRange = range;

#ifndef NDEBUG
    outlineViewport();
#endif
}
Esempio n. 17
0
void right_hip(void){

	setLights(pantsRed, pantsGreen, pantsBlue);
	
	glColor3f(pantsRed, pantsGreen, pantsBlue);

	glTranslatef(-1.5, -2.0, 0.0);

	glRotatef(headUpDown * 10, 1.0, 0.0, 0.0);
	
	glutSolidSphere(0.80, 10.0, 10.0);
	
	left_leg();
	
}
Esempio n. 18
0
/**
 *	Right Arm
 *
 **/
void right_arm(void){
	
	glTranslatef(-1.0, 0.0, 0.0);
	
	glPushMatrix();
	glScalef(3.0, 1.0, 1.0);
	glutSolidCube(1.0);
	
	glPopMatrix();
	
	setLights(1.0, 0.92, 0.80);

	glColor3f(1.0, 0.92, 0.80);
	
	right_elbow();
}
Esempio n. 19
0
void right_knee(void){
	
	glTranslatef(0.0, -2.0, 0.0);

	glRotatef(-headUpDown * 20, 1.0, 0.0, 0.0);
	
	glutSolidSphere(0.50, 10.0, 10.0);

	setLights(1.0, 0.92, 0.80);

	glColor3f(1.0, 0.92, 0.80);
	
	lower_right_leg();
	
	
}
Esempio n. 20
0
void Channel::frameDraw( const eq::uint128_t& frameID )
{
    // Setup frustum
    EQ_GL_CALL( applyBuffer( ));
    EQ_GL_CALL( applyViewport( ));
    
    EQ_GL_CALL( glMatrixMode( GL_PROJECTION ));
    EQ_GL_CALL( glLoadIdentity( ));
    EQ_GL_CALL( applyFrustum( ));

    EQ_GL_CALL( glMatrixMode( GL_MODELVIEW ));
    EQ_GL_CALL( glLoadIdentity( ));

    // Setup lights before applying head transform, so the light will be
    // consistent in the cave
    const FrameData&    frameData   = _getFrameData();
    const eq::Matrix4f& rotation    = frameData.getRotation();
    const eq::Vector3f& translation = frameData.getTranslation();

    eq::Matrix4f     invRotationM;
    rotation.inverse( invRotationM );
    setLights( invRotationM );

    EQ_GL_CALL( applyHeadTransform( ));

    glTranslatef(  translation.x(), translation.y(), translation.z() );
    glMultMatrixf( rotation.array );

    Pipe*     pipe     = static_cast<Pipe*>( getPipe( ));
    Renderer* renderer = pipe->getRenderer();
    EQASSERT( renderer );

    eq::Matrix4f  modelviewM;     // modelview matrix
    eq::Matrix3f  modelviewITM;   // modelview inversed transposed matrix
    _calcMVandITMV( modelviewM, modelviewITM );

    const eq::Range& range = getRange();
    renderer->render( range, modelviewM, modelviewITM, invRotationM );

    checkError( "error during rendering " );

    _drawRange = range;

#ifndef NDEBUG
    outlineViewport();
#endif
}
Esempio n. 21
0
void Scene::setStates()
{
    // glEnable(GL_BRAINS) // ;)

    // glEnable(GL_BLEND); // На старых картах ATI вызывает проблемы в шейдере (цветовая глубина в профиле для блендинга должна быть 32 т.е. с альфой)

    glEnable(GL_DEPTH_TEST);  // без этого у нас не будет эффекта глубины (включаем буфер глубины)
    //glEnable(GL_CULL_FACE); // активирует устранение спрятанных поверхностей.
    glEnable(GL_LIGHTING);
    glEnable(GL_COLOR_MATERIAL);  // было отключено
    glEnable(GL_TEXTURE_2D);
    glEnable(GL_NORMALIZE);

    setLights();

    float materialSpecular[] = {0.5f, 0.5f, 0.5f, 1.0f};
    glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, materialSpecular);
    glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 32.0f);
}
Esempio n. 22
0
void display(void) {
	glClear(GL_COLOR_BUFFER_BIT);

	glPushMatrix();
	glRotatef(spin, 0, 1, 0);

	aimLights();
	setLights();

	glPushMatrix();
	glRotatef(-90.0, 1, 0, 0);
	glScalef(1.9, 1.9, 1.0);
	glTranslatef(-0.5, -0.5, 0.0);
	drawPlane(16, 16);
	glPopMatrix();

	drawLights();
	glPopMatrix();

	glutSwapBuffers();
}
Esempio n. 23
0
void
display(void)
{
    glClear(GL_COLOR_BUFFER_BIT);

    glPushMatrix();

    glEnable(GL_LIGHTING);
    initLights();
    setLights();

    glPushMatrix();
    glRotatef(-90.0, 1, 0, 0);
    glTranslatef(-1, -1, 0.0);
    drawPlane(200, 200); // xy plane
    glPopMatrix();

    //drawLights();
    glPopMatrix();

    glutSwapBuffers();
}
	static void render()
	{
		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //clear the draw buffer

		glEnable( GL_BLEND );

		currentCamera->setAspectRatio(resolution.x/resolution.y);
		setCameraTransMatrix(currentCamera->getCameraTransformationMatrix());
		setPerspectiveMatrix(currentCamera->getPerspectiveMatrix());
		setCameraPosition(currentCamera->getTranslate());
		setLights(wLights,LIGHT_COUNT);
		setAmbientLightColor(vec3(.1,.05,.075));
		setAmbientLightColor(vec3(.1,.1,.2));

		//
		//Draw non-transparent models, pushing transparent ones onto a max-heap
		TransparencyQueue transparencyQueue;
		drawOpaqueEntities(wEntities, transparencyQueue); //Draw Every GameEntity
		drawOpaqueEntities(wWalls, transparencyQueue); //Draw Every Wall
		drawOpaqueEntities(wSoftEntities, transparencyQueue);

		//Draw transparent models, furthest from camera first
		//Disable updating the z-buffer, but still conduct the
		//test so that nearer opaque objects completely occlude
		//farther transparent objects.

		glEnable( GL_BLEND );
		glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
		glDepthMask(GL_FALSE);
		while(!transparencyQueue.empty()) {
			transparencyQueue.top()->draw();
			transparencyQueue.pop();
		}
		glDepthMask(GL_TRUE);

		glDisable(GL_BLEND);
	}
Esempio n. 25
0
TSceneTree::TSceneTree (TScene* ptSCENE)
{

  Gtk::Tree*       ptSubtree;
  Gtk::TreeItem*   ptItem;
  bool            gSubtree = false;

  ptScene = ptSCENE;
  
  if ( ptScene )
  {
    ptSubtree = new Gtk::Tree;

    gSubtree |= setCamera (ptSubtree);
    gSubtree |= setLights (ptSubtree);
    gSubtree |= setObjects (ptSubtree);

    ptItem = new Gtk::TreeItem ("Scene");
    ptItem->show();

    ptItem->button_press_event.connect(bind(slot(this, &TSceneTree::manageButtonPress), (TProcedural*) ptScene));

    append (*ptItem);
    
    if ( gSubtree )
    {
      ptSubtree->show();
      ptItem->set_subtree (*ptSubtree);
    }
    else
    {
      delete ptSubtree;
    }
  }
  
}  /* TSceneTree() */
Esempio n. 26
0
int runApp( options::variables_map const& opts )
{
  // Create renderer
  std::string cullingEngine = opts["cullingengine"].as<std::string>();
  dp::culling::Mode cullingMode = dp::culling::Mode::AUTO;
  if ( cullingEngine == "cpu" )
  {
    cullingMode = dp::culling::Mode::CPU;
  }
  else if ( cullingEngine == "gl_compute" )
  {
    cullingMode = dp::culling::Mode::OPENGL_COMPUTE;
  }
  else if ( cullingEngine == "cuda" )
  {
    cullingMode = dp::culling::Mode::CUDA;
  }
  else if ( cullingEngine != "auto" )
  {
    std::cerr << "unknown culling engine, abort" << std::endl;
    return -1;
  }

  CFRPipelineSharedPtr renderer = CFRPipeline::create
  (
      opts["renderengine"].as<std::string>().c_str()
    , getShaderManager( opts["shadermanager"].as<std::string>() )
    , cullingMode
  );
  //renderer->setCullingEnabled( opts["culling"].as<bool>() );

  dp::sg::ui::ViewStateSharedPtr viewStateHandle = loadScene( opts["filename"].as<std::string>() );

  g_viewState = viewStateHandle;

  if ( opts.count("replace") )
  {
    // process replacements
    std::vector< std::string> replacementStrings = opts["replace"].as< std::vector<std::string > >();
    dp::sg::algorithm::ReplacementMapNames replacements;
    for ( std::vector<std::string>::iterator it = replacementStrings.begin(); it != replacementStrings.end(); ++it )
    {
      size_t equalChar = it->find_first_of(':');
      if ( equalChar != std::string::npos && equalChar < it->size() - 1)
      {
        std::string str1 = it->substr( 0, equalChar );
        std::string str2 = it->substr( equalChar + 1, it->size() - equalChar - 1);
        replacements[str1] = str2;
      }
      else
      {
        std::cerr << "invalid replacement token: " << *it << std::endl;
      }
    }
    dp::sg::algorithm::replacePipelineData( viewStateHandle->getScene(), replacements );
  }

  if ( !opts["statistics"].empty() )
  {
    showStatistics( viewStateHandle );
  }

  dp::sg::ui::setupDefaultViewState( viewStateHandle );

  if ( !opts["combineVertexAttributes"].empty() )
  {
    combineVertexAttributes( viewStateHandle );
  }

  {
    // Replace MatrixCamera by PerspectiveCamera to get all manipulator features
    if ( viewStateHandle->getCamera()->getObjectCode() == dp::sg::core::ObjectCode::MATRIX_CAMERA )
    {
      dp::sg::core::PerspectiveCameraSharedPtr perspectiveCamera = dp::sg::core::PerspectiveCamera::create();
      perspectiveCamera->setOrientation(viewStateHandle->getCamera()->getOrientation());
      perspectiveCamera->setDirection((viewStateHandle->getCamera()->getDirection()));
      perspectiveCamera->setPosition(viewStateHandle->getCamera()->getPosition());

      viewStateHandle->setAutoClipPlanes(true);
      viewStateHandle->setCamera(perspectiveCamera);
    }
  }

  if ( !opts["headlight"].empty() )
  {
    // TODO is this still a bug?
    // Bug 914976 containsLight() doesn't find lights in the scene. Force adding the headlight anyway when the user specified it.
    if ( viewStateHandle /* && viewStateHandle->getScene() && !SceneLock( viewStateHandle->getScene() )->containsLight() */
      && viewStateHandle->getCamera() && ( viewStateHandle->getCamera()->getNumberOfHeadLights() == 0 ) )
    {
      // Use the defaults! Note that LightSource ambientColor is black.
      viewStateHandle->getCamera()->addHeadLight( dp::sg::core::createStandardPointLight() );
    }
  }

  // Setup default OpenGL format descriptor
  // We need to create a default format first to be able to check if a stereo pixelformat is available later.
  // (An unfortunate RenderContextFormat.isAvailable() interface due to Linux.)
  dp::gl::RenderContextFormat format;

  // create a widget which shows the scene
  //dp::sg::ui::glut::SceneRendererWidget w( format );
  GLUTMinimalCFR w;

  // TODO format is not yet supported
#if 0
  if (stereo)
  {
    format.setStereo( stereo );
    if ( !w.setFormat( format ) )  // This automatically checks if the format is available.
    {
      std::cout << "Warning: No stereo pixelformat available." << std::endl;
    }
  }
#endif

  viewStateHandle->setAutoClipPlanes( opts["autoclipplanes"].as<bool>() );

  w.setViewState( viewStateHandle );
  w.setSceneRenderer( renderer );
//always on  if ( !opts["continuous"].empty() )
  {
    w.setContinuousUpdate( true );
    w.setShowFrameRate( true );
  }

  if( opts["frames"].as<int>() != -1 )
  {
    w.setNumberOfFrames( opts["frames"].as<int>() );
  }
  w.setDuration( opts["duration"].as<double>() );

  w.setWindowSize( 1280, 720 );
  //w.show();

  // Keep only once reference to the renderer in the widget. This is necessary since the OpenGL resources
  // used by the renderer must be deleted before the window gets destroyed.
  renderer.reset();

  g_viewState->getCamera()->setPosition(dp::math::Vec3f(0.0f, 0.0f, 5.0f));
  setLights();

  glutMainLoop();

  return w.getExitCode();
}
Esempio n. 27
0
void gxScene::setRenderState( const RenderState &rs ){
	bool setmat=false;
	if( memcmp( rs.color,&material.diffuse.r,12 ) ){
		memcpy( &material.diffuse.r,rs.color,12 );
		memcpy( &material.ambient.r,rs.color,12 );
		setmat=true;
	}
	if( rs.alpha!=material.diffuse.a ){
		material.diffuse.a=rs.alpha;
		if( rs.fx&FX_ALPHATEST ){
			int alpharef=(rs.fx&FX_VERTEXALPHA)?0:128*rs.alpha;
			setRS( D3DRENDERSTATE_ALPHAREF,alpharef );
		}
		setmat=true;
	}
	if( rs.shininess!=shininess ){
		shininess=rs.shininess;
		float t=shininess>0 ? (shininess<1 ? shininess : 1) : 0;
		material.specular.r=material.specular.g=material.specular.b=t;
		material.power=shininess*128;
		setRS( D3DRENDERSTATE_SPECULARENABLE,shininess>0 ? true : false );
		setmat=true;
	}
	if( rs.blend!=blend ){
		blend=rs.blend;
		switch( blend ){
		case BLEND_REPLACE:
			setRS( D3DRENDERSTATE_ALPHABLENDENABLE,false );
			break;
		case BLEND_ALPHA:
			setRS( D3DRENDERSTATE_ALPHABLENDENABLE,true );
			setRS( D3DRENDERSTATE_SRCBLEND,D3DBLEND_SRCALPHA );
			setRS( D3DRENDERSTATE_DESTBLEND,D3DBLEND_INVSRCALPHA );
			break;
		case BLEND_MULTIPLY:
			setRS( D3DRENDERSTATE_ALPHABLENDENABLE,true );
			setRS( D3DRENDERSTATE_SRCBLEND,D3DBLEND_DESTCOLOR );
			setRS( D3DRENDERSTATE_DESTBLEND,D3DBLEND_ZERO );
			break;
		case BLEND_ADD:
			setRS( D3DRENDERSTATE_ALPHABLENDENABLE,true );
			setRS( D3DRENDERSTATE_SRCBLEND,D3DBLEND_SRCALPHA );
			setRS( D3DRENDERSTATE_DESTBLEND,D3DBLEND_ONE );
			break;
		}
	}
	if( rs.fx!=fx ){
		int t=rs.fx^fx;fx=rs.fx;
		if( t & (FX_FULLBRIGHT|FX_CONDLIGHT) ){
			setLights();
			setAmbient();
		}
		if( t&FX_VERTEXCOLOR ){
			setRS( D3DRENDERSTATE_COLORVERTEX,fx & FX_VERTEXCOLOR ? true : false );
		}
		if( t&FX_FLATSHADED ){
			setRS( D3DRENDERSTATE_SHADEMODE,fx & FX_FLATSHADED ? D3DSHADE_FLAT : D3DSHADE_GOURAUD );
		}
		if( t&FX_NOFOG ){
			setFogMode();
		}
		if( t&FX_DOUBLESIDED ){
			setTriCull();
		}
		if( t&FX_EMISSIVE ){
			//Q3 Hack!
			int n=fx & FX_EMISSIVE;
			setRS( D3DRENDERSTATE_DIFFUSEMATERIALSOURCE,n ? D3DMCS_MATERIAL : D3DMCS_COLOR1 );
			setRS( D3DRENDERSTATE_AMBIENTMATERIALSOURCE,n ? D3DMCS_MATERIAL : D3DMCS_COLOR1 );
			setRS( D3DRENDERSTATE_EMISSIVEMATERIALSOURCE,n ? D3DMCS_COLOR1 : D3DMCS_MATERIAL );
			setRS( D3DRENDERSTATE_COLORVERTEX,n ? true : false );
		}
		if( t&FX_ALPHATEST ){
			if( fx&FX_ALPHATEST ){
				int alpharef=(rs.fx&FX_VERTEXALPHA)?0:128*rs.alpha;
				setRS( D3DRENDERSTATE_ALPHAREF,alpharef );
			}
			setRS( D3DRENDERSTATE_ALPHATESTENABLE,fx & FX_ALPHATEST ? true : false );
		}
	}
	if( setmat ){
		dir3dDev->SetMaterial( &material );
	}

	n_texs=0;
	TexState *hw=texstate;
	for( int k=0;k<MAX_TEXTURES;++k ){
		const RenderState::TexState &ts=rs.tex_states[k];
		if( !ts.canvas || !ts.blend ) continue;
		bool settex=false;
		ts.canvas->getTexSurface();	//force mipmap rebuild
		if( ts.canvas!=hw->canvas ){ hw->canvas=ts.canvas;settex=true; }
		if( ts.blend!=hw->blend ){ hw->blend=ts.blend;settex=true; }
		if( ts.flags!=hw->flags ){ hw->flags=ts.flags;settex=true; }
		if( ts.matrix || hw->mat_valid ){
			if( ts.matrix ){
				memcpy( &hw->matrix._11,ts.matrix->elements[0],12 );
				memcpy( &hw->matrix._21,ts.matrix->elements[1],12 );
				memcpy( &hw->matrix._31,ts.matrix->elements[2],12 );
				memcpy( &hw->matrix._41,ts.matrix->elements[3],12 );
				hw->mat_valid=true;
			}else{
				hw->mat_valid=false;
			}
			settex=true;
		}
		if( settex && n_texs<tex_stages ){
			setTexState( n_texs,*hw,true );
		}
		++hw;++n_texs;
	}
	if( n_texs<tex_stages && hw->canvas ){
		hw->canvas=0;
		setTSS( n_texs,D3DTSS_COLOROP,D3DTOP_DISABLE );
		setTSS( n_texs,D3DTSS_ALPHAOP,D3DTOP_DISABLE );
		dir3dDev->SetTexture( n_texs,0 );
	}
}