コード例 #1
0
void CRhGLShaderProgram::SetupLight(const ON_Light& light)
{
  GLfloat amb[4]  = { light.Ambient().FractionRed(),  light.Ambient().FractionGreen(),  light.Ambient().FractionBlue(),  1.0f };
  GLfloat diff[4] = { light.Diffuse().FractionRed(),  light.Diffuse().FractionGreen(),  light.Diffuse().FractionBlue(),  1.0f };
  GLfloat spec[4] = { light.Specular().FractionRed(), light.Specular().FractionGreen(), light.Specular().FractionBlue(), 1.0f };
  float   pos[3]  = { light.Direction().x, light.Direction().y, light.Direction().z };
  
  if ( m_Uniforms.rglLightAmbient >= 0 )
    glUniform4fv( m_Uniforms.rglLightAmbient, 1, amb );
  if ( m_Uniforms.rglLightDiffuse >= 0 )
    glUniform4fv( m_Uniforms.rglLightDiffuse, 1, diff );
  if ( m_Uniforms.rglLightSpecular >= 0 )
    glUniform4fv( m_Uniforms.rglLightSpecular, 1, spec );
  if ( m_Uniforms.rglLightPosition >= 0 )
    glUniform3fv( m_Uniforms.rglLightPosition, 1, pos );
}
コード例 #2
0
ファイル: opennurbs_gl.cpp プロジェクト: Bardo91/pcl
void ON_GL( const ON_Light& light, GLenum light_index )
{
  ON_BOOL32 bPopModelViewMatrix = false;
  ON_BOOL32 bPopProjectionMatrix = false;

  switch ( light.CoordinateSystem() ) 
  {
  case ON::world_cs:
    break;
  case ON::clip_cs:
    bPopProjectionMatrix = true;
    glMatrixMode(GL_PROJECTION);
    glPushMatrix();
    glLoadIdentity();
    // no break here
  case ON::camera_cs:
    bPopModelViewMatrix = true;
    glMatrixMode(GL_MODELVIEW);
    glPushMatrix();
    glLoadIdentity();
    break;
  case ON::screen_cs:
    break;
  }

  GLfloat ambient[4], diffuse[4], specular[4];
  ON_GL( light.Ambient(), ambient );
  ON_GL( light.Diffuse(), diffuse );
  ON_GL( light.Specular(), specular );
  glLightfv( light_index, GL_AMBIENT, ambient );
  glLightfv( light_index, GL_DIFFUSE, diffuse );
  glLightfv( light_index, GL_SPECULAR, specular );

  ON_3dPoint loc = light.Location();
  GLfloat f[4] = {(GLfloat)loc.x,(GLfloat)loc.y,(GLfloat)loc.z,(GLfloat)1.0};
  glLightfv( light_index, GL_POSITION, f );

  ON_3dVector dir = light.Direction();
  f[0] = (GLfloat)dir.x; 
  f[1] = (GLfloat)dir.y; 
  f[2] = (GLfloat)dir.z;
  glLightfv( light_index, GL_SPOT_DIRECTION, f );

  glLightf( light_index, GL_SPOT_EXPONENT, (GLfloat)(light.SpotExponent()*128.0)  );
  glLightf( light_index, GL_SPOT_CUTOFF, (GLfloat)light.SpotAngleRadians() );

  ON_3dVector attenuation = light.Attenuation();
  glLightf( light_index, GL_CONSTANT_ATTENUATION,  (GLfloat)attenuation.x  );
  glLightf( light_index, GL_LINEAR_ATTENUATION,    (GLfloat)attenuation.y  );
  glLightf( light_index, GL_QUADRATIC_ATTENUATION, (GLfloat)attenuation.z  );

  if ( light.IsEnabled() )
    glEnable( light_index );
  else
    glDisable( light_index );
  if ( bPopProjectionMatrix ) {
    glMatrixMode(GL_PROJECTION);
    glPopMatrix();
  }
  if ( bPopModelViewMatrix ) {
    glMatrixMode(GL_MODELVIEW);
    glPopMatrix();
  }
}