Example #1
0
int main (int argc, char **argv)
{  
  //Initialize GLUT
  initGlut(argc, argv);
  
  Kernel kernel;
  kernel.enableVerticalSync( false );
  renderer = kernel.getRenderer();
  printf( "Kernel loaded\n" );
  
  //Load shape model
  LoaderObj ldr;
  File f( "zekko.obj" );
  ldr.setUVMeshClass( Class( ETexMesh ));
  
  int start = GE::Time::GetTicks();
  ldr.loadFile( f.getPathName() );
  int end = GE::Time::GetTicks();
  printf( "Time: %d\n", end - start );
  
  PolyMesh *dmesh;
  uvmesh = (ETexMesh*) ldr.getFirstResource( Class(TexMesh) );
  dmesh = (PolyMesh*) ldr.getFirstResource( Class(PolyMesh) );
  zekko = (PolyMeshActor*) ldr.getFirstObject( Class(PolyMeshActor) );
  if (dmesh == NULL) return EXIT_FAILURE;
  if (uvmesh == NULL) return EXIT_FAILURE;
  if (zekko == NULL) return EXIT_FAILURE;
  
  //Check if UV mesh type correct
  printf( "uvmesh = %s\n", StringOf( ClassOf( zekko->getTexMesh() )));
  
  printf( "uvmesh %s ETexMesh\n",
          SafeCast( ETexMesh, zekko->getTexMesh() ) ?
          "IS" : "is NOT");
  
  printf( "uvmesh %s TexMesh\n",
          SafeCast( TexMesh, zekko->getTexMesh() ) ?
          "IS" : "is NOT");
  
  printf( "uvmesh %s Resource\n",
          SafeCast( Resource, zekko->getTexMesh() ) ?
          "IS" : "is NOT");
  
  printf( "uvmesh %s PolyMesh\n",
          SafeCast( PolyMesh, zekko->getTexMesh() ) ?
          "IS" : "is NOT");
  
  //Setup camera
  cam3D.translate( 0,35,-100 );
  cam3D.setCenter( center );
  //cam3D.setNearClipPlane(100.0f);
  //cam3D.setFarClipPlane(100000.0f);
  
  //Find model center
  findCenter();
  
  //Set half bunny green
  for (PolyMesh::FaceIter f(dmesh); !f.end(); ++f) {
    //f->smoothGroups = 0x1;
    if (f->firstHedge()->dstVertex()->point.y > center.y)
      dmesh->setMaterialID( *f, 1 ); }

  //Convert to static mesh
  //dmesh->updateNormals();
  smesh.fromPoly( dmesh, uvmesh );
  
  //Load texture image
  imgDiff.readFile( "texture.jpg", "" );
  
  //Create texture from image
  texDiff = new Texture;
  texDiff->fromImage( &imgDiff );
  
  //Load specularity image
  Image imgSpec;
  imgSpec.readFile( "specularity.jpg", "" );

  //Create specularity texture
  texSpec = new Texture();
  texSpec->fromImage(&imgSpec);
  
  //Create material using texture
  PhongMaterial mat;
  mat.setDiffuseTexture( texDiff );
  //mat.setSpecularityTexture( texSpec );
  mat.setDiffuseColor( Vector3( 1,0.0f,0.0f ));
  mat.setAmbientColor( Vector3( 0.2f,0.2f,0.2f ));
  mat.setSpecularity( 1.0f );
  mat.setGlossiness( 0.2f );
  
  PhongMaterial mat2;
  mat2.setDiffuseTexture( texDiff );
  //mat2.setSpecularityTexture( texSpec );
  mat2.setDiffuseColor( Vector3( 0.0f, 1.0f, 0.0f ));
  mat2.setAmbientColor( Vector3( 0.2f, 0.2f, 0.2f ));
  mat2.setSpecularity( 1.0f );
  mat2.setGlossiness( 0.2f );
  
  MultiMaterial mm;
  mm.setNumSubMaterials( 2 );
  mm.setSubMaterial( 0, &mat );
  mm.setSubMaterial( 1, &mat2 );
  zekko->setMaterial( &mm );

  scene = new Scene;
  scene->addChild( zekko );

  //Light *light = new SpotLight( Vector3(-200,200,-200), Vector3(1,-1,1), 60, 0 );
  Light *light = new HeadLight;
  scene->addChild( light );
  
  lblFps.setLocation( Vector2( 0.0f,(Float)resY ));
  lblFps.setColor( Vector3( 1.0f,1.0f,1.0f ));
  
  //Run application
  atexit( cleanup );
  glutMainLoop();
  cleanup();

  return EXIT_SUCCESS;
}