コード例 #1
0
bool ShaderTextureInterface::InitProgram() {
	if (!loadVertexProgram("CG/shaderTexture.cg", "VertexMain")) return false;

	if (!loadFragmentProgram("CG/shaderTexture.cg", "FragmentMain")) return false;

	// build some parameters by name such that we can set them later...
	vertexModelViewProj = cgGetNamedParameter(vertexProgram, "modelViewProj");
	fragmentTex = cgGetNamedParameter(fragmentProgram, "tex");

	return true;
}
コード例 #2
0
ファイル: viewer.cpp プロジェクト: bsmr-opengl/cal3d
bool Viewer::onInit()
{
  // load all textures and store the opengl texture id in the corresponding map in the material
  int materialId;
  for(materialId = 0; materialId < m_calCoreModel->getCoreMaterialCount(); materialId++)
  {
    // get the core material
    CalCoreMaterial *pCoreMaterial;
    pCoreMaterial = m_calCoreModel->getCoreMaterial(materialId);

    // loop through all maps of the core material
    int mapId;
    for(mapId = 0; mapId < pCoreMaterial->getMapCount(); mapId++)
    {
      // get the filename of the texture
      std::string strFilename;
      strFilename = pCoreMaterial->getMapFilename(mapId);

      // load the texture from the file
      GLuint textureId;
      textureId = loadTexture(strFilename);

      // store the opengl texture id in the user data of the map
      pCoreMaterial->setMapUserData(mapId, (Cal::UserData)textureId);
    }
  }

  // attach all meshes to the model
  int meshId;
  for(meshId = 0; meshId < m_calCoreModel->getCoreMeshCount(); meshId++)
  {
    m_calModel->attachMesh(meshId);
  }

  // set the material set of the whole model
  m_calModel->setMaterialSet(0);

  // set initial animation state
  if(m_calCoreModel->getCoreAnimationCount() > 0)
  {
    m_currentAnimationId = 0;
    m_leftAnimationTime = m_calCoreModel->getCoreAnimation(m_currentAnimationId)->getDuration() - m_blendTime;
    if(m_calCoreModel->getCoreAnimationCount() > 1)
    {
      m_calModel->getMixer()->executeAction(m_currentAnimationId, 0.0f, m_blendTime);
    }
    else
    {
      m_calModel->getMixer()->blendCycle(m_currentAnimationId, 1.0f, 0.0f);
    }
  }
  else
  {
    m_currentAnimationId = -1;
    m_leftAnimationTime = -1.0f;
  }


  // Disable internal data
  // this disable spring system


  std::cout << "Disable internal." << std::endl;
  m_calModel->disableInternalData();

  m_lastTick = Tick::getTick();

  glewInit();

  if (!GLEW_ARB_vertex_program)
  {
      std::cerr << "Error ARB_vertex_program OpenGL extension not found." << std::endl;
	  return false;
  }

  if (!GLEW_ARB_vertex_buffer_object)
  {
      std::cerr << "Error ARB_vertex_buffer_object OpenGL extension not found." << std::endl;
	  return false;
  }


  if(!loadBufferObject())
  {
      std::cerr << "Error loading vertex buffer object." << std::endl;
	  return false;
  }


  if(!loadVertexProgram())
  {
      std::cerr << "Error loading vertex program." << std::endl;
	  return false;
  }
  


  // we're done
  std::cout << "Initialization done." << std::endl;
  std::cout << std::endl;
  std::cout << "Quit the viewer by pressing 'q' or ESC" << std::endl;
  std::cout << std::endl;

  

  return true;
}