예제 #1
0
파일: example7.cpp 프로젝트: wthibault/ssg
void init (int argc, char **argv)
{
  
  controlPoints.push_back ( vec3(0,0,0) );
  controlPoints.push_back ( vec3(3,0,0) );
  controlPoints.push_back ( vec3(-2,1,-3) );
  controlPoints.push_back ( vec3(2,2,-6) );

  //  create a primitive.  if supplied on command line, read a .obj wavefront file
  ObjFilePrimitive *background, *movingObject;
  if ( argc == 3 ) {
    background = new ObjFilePrimitive ( argv[1] );
    movingObject = new ObjFilePrimitive ( argv[2] );
  } else {
    cout << "usage: " << argv[0] << " backgroundObjFile moverObjfile\n";
    //    exit(1);
    background = new ObjFilePrimitive ( "objfiles/cube.obj" );
    movingObject = new ObjFilePrimitive ( "objfiles/cube.obj" );
  }

  // create the graph
  // the second child of the root must be an instance: it will have its matrix changed
  Instance *scene = new Instance();
  scene->setMatrix ( mat4() );
  scene->addChild ( background );
  Instance *mover = new Instance();
  mover->addChild ( movingObject );
  scene->addChild ( mover );



  // enable camera trackball
  camera.enableTrackball (true);

  // the lights are global for all objects in the scene
  RenderingEnvironment::getInstance().lightPosition = vec4 ( 4,10,5,1 );
  RenderingEnvironment::getInstance().lightColor = vec4 ( 1,1,1,1 );

  // create a material to use
  Material *mat = new Material;
  mat->ambient = vec4 ( 0.1, 0.1, 0.2, 1.0 );
  mat->diffuse = vec4 ( 0.5, 0.5, 0.1, 1.0 );
  mat->specular = vec4 ( 1.0, 1.0, 1.0, 1.0 );
  mat->shininess = 133.0;
  mat->program = mat->loadShaders ( "PhongShading" );

  // attach the material to the primitive
  scene->setMaterial ( mat );

  // set the instance as the scene root
  root = scene;

  // misc OpenGL state
  glClearColor (0.0, 0.0, 0.0, 1.0);
  glEnable(GL_DEPTH_TEST);

}
예제 #2
0
파일: depthrender.cpp 프로젝트: Sudoka/ssg
void 
init (int argc, char **argv)
{
  
  // create a primitive.  if supplied on command line, read a .obj wavefront file

  if ( argc >= 2 ) {
    prim = new ObjFilePrimitive ( argv[1] );
  } else {
    std::cout << "usage: " << argv[0] << " [objfile.obj]\n";
    exit(1);
  }

  // create a root Instance to contain this primitive
  Instance *instance = new Instance();
  instance->setMatrix ( mat4() );
  instance->addChild ( prim );

  // the lights are global for all objects in the scene
  RenderingEnvironment::getInstance().lightPosition = vec4 ( 0,0,10,1 );
  RenderingEnvironment::getInstance().lightColor = vec4 ( 1,1,1,1 );

  // create a material to use
  Material *mat = new Material;
  mat->ambient = vec4 ( 0.1, 0.1, 0.1, 1.0 );
  mat->diffuse = vec4 ( 0.8, 0.8, 0.8, 1.0 );
  mat->specular = vec4 ( 1.0, 1.0, 1.0, 1.0 );
  mat->shininess = 300.0;
  mat->program = mat->loadShaders ( "DepthMap" );

  // attach the material
  instance->setMaterial ( mat );
  // override the materials read from the objfile
  ObjFilePrimitive *op;
  if ( op = dynamic_cast<ObjFilePrimitive*>(prim) ) {
    for ( int i = 0; i < op->materials_.size(); i++ ) {
      op->materials_[i] = mat;
    }
  }

  // set the instance as the scene root
  root = instance;

  // misc OpenGL state
  glClearColor (0.0, 0.0, 0.0, 1.0);
  glEnable(GL_DEPTH_TEST);
  glPointSize(1.0);
  glLineWidth(1.0);

}
예제 #3
0
파일: example7.cpp 프로젝트: wthibault/ssg
void display ()
{
  glClear ( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
  static float lastFrame = getNow();
  float now = getNow();

  root->update(now-lastFrame);

  //  Instance *iroot = dynamic_cast<Instance*>(root);
  //  Instance *mover = dynamic_cast<Instance*> ( iroot->getChild(1) ); 
  Ptr<Instance> mover ( root->getChild(1) );

  // interpolate along a quadratic Bezier curve
  float motionStartTime = 5.0;
  float motionEndTime = motionStartTime+4.0;

  // move the mover

  float u = ((now - motionStartTime) / (motionEndTime - motionStartTime) );
  if ( u < 0.0 )
    mover->setMatrix ( translate(mat4(), controlPoints[0]) );
  else if ( u > 1.0 )
    mover->setMatrix ( translate(mat4(), controlPoints[3]) );
  else 
    mover->setMatrix ( translate(mat4(), deCasteljau3 (controlPoints, u ) ) );

  // add a marker to the scene at each position
  Instance *marker = new Instance();
  marker->addChild ( new Marker() );
  marker->setMatrix ( mover->getMatrix() );
  root->addChild ( marker );

  camera.draw(root);

  glutSwapBuffers();
  lastFrame = now;

  //  std::cout << now << std::endl;
}
예제 #4
0
파일: shadows.cpp 프로젝트: wthibault/ssg
void init (int argc, char **argv)
{
  
  //  create a primitive.  if supplied on command line, read a .obj wavefront file
  ObjFilePrimitive *prim;
  if ( argc == 2 ) {
    prim = new ObjFilePrimitive ( argv[1] );
    //    prim->setMaterial(NULL); // make room for the shadowing shader (add a way to override baked in materials???)
  } else {
    cout << "usage: " << argv[0] << " objfile\n";
    //    exit(1);
    prim = new ObjFilePrimitive ( "objfiles/bone6.obj" );
  }

  // create a root Instance to contain this primitive
  Instance *instance = new Instance();
  instance->setMatrix ( mat4() );
  instance->addChild ( prim );


  // enable camera trackball
  camera.enableTrackball (true);
  camera.setDistance ( 2 );

  // the lights are global for all objects in the scene
  // XXX old deprecated XXX
  //  RenderingEnvironment::getInstance().lightPosition = vec4 ( 4,10,5,1 );
  //  RenderingEnvironment::getInstance().lightColor = vec4 ( 1,1,1,1 );
  


  // create a material to use
  mat = new Material;
  mat->ambient = vec4 ( 0.1, 0.1, 0.1, 1.0 );
  mat->diffuse = vec4 ( 0.9, 0.9, 0.0, 1.0 );
  mat->specular = vec4 ( 1.0, 1.0, 1.0, 1.0 );
  mat->shininess = 133.0;
  mat->program = mat->loadShaders ( "PhongShadingShadows" );

  // attach the material to the instance
  instance->setMaterial ( mat );

  // PointLights do shadows...
  // XXX must call this AFTER compiling the shader!!! certain things in the shadow code glsl won't compile until the shader is built.
  RenderingEnvironment::getInstance().addPointLight ( vec3(4,6,5), vec3(0,0,0) );
  GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
  if (status != GL_FRAMEBUFFER_COMPLETE) {
    printf("FB error, status: 0x%x\n", status);
  }

  // setup to draw the shadow texture
  shadowTexture = RenderingEnvironment::getInstance().getPointLight(0).getShadowTexture();
  //shadowTexture = new Texture("textures/lichen.bmp", false, false, 0 );
  shadowTexture->setupRenderFullscreenQuad("shaders120/DebugShadows.vert","shaders120/DebugShadows.frag");



  // set the instance as the scene root
  root = instance;

  // misc OpenGL state
  glClearColor (0.0, 0.0, 0.0, 1.0);
  glEnable(GL_DEPTH_TEST);
  glHint(GL_PERSPECTIVE_CORRECTION_HINT,GL_NICEST);
}