void GlObject::render(glm::mat4 projMatrix, glm::mat4 viewMatrix)
{
	glUseProgram(shader->program);

	safe_glUniformMatrix4fv(shader->h_uModelMatrix, &modelMatrix[0][0]);
	safe_glUniformMatrix4fv(shader->h_uViewMatrix, &viewMatrix[0][0]);
	safe_glUniformMatrix4fv(shader->h_uProjMatrix, &projMatrix[0][0]);
	safe_glUniform3f(shader->h_uLightPosition, Game::Instance().lightPos.x, Game::Instance().lightPos.y, Game::Instance().lightPos.z);
	safe_glUniform3f(shader->h_uLightIntensity, Game::Instance().lightIntensity.x, Game::Instance().lightIntensity.y, Game::Instance().lightIntensity.z);

	glEnableVertexAttribArray(shader->h_aPosition);
	glEnableVertexAttribArray(shader->h_aColor);
	glEnableVertexAttribArray(shader->h_aNormal);

	glBindBuffer(GL_ARRAY_BUFFER, vboPos);
	glVertexAttribPointer(shader->h_aPosition, 3, GL_FLOAT, GL_FALSE, 0, 0);

	glBindBuffer(GL_ARRAY_BUFFER, vboColor);
	glVertexAttribPointer(shader->h_aColor, 3, GL_FLOAT, GL_FALSE, 0, 0);

	glBindBuffer(GL_ARRAY_BUFFER, vboNormals);
	glVertexAttribPointer(shader->h_aNormal, 3, GL_FLOAT, GL_TRUE, 0, 0);

	glDrawArrays(GL_TRIANGLES, 0, numVerts);

	glDisableVertexAttribArray(shader->h_aPosition);
	glDisableVertexAttribArray(shader->h_aColor);
	glDisableVertexAttribArray(shader->h_aNormal);
}
/*-----------------------------------------------*/
void RigidBody::draw(RigTForm respectFrame_, Matrix4 respectScale_)
{
   /*	PURPOSE:		Draws the RigidBody with respect to parent object
      RECEIVES:	respectFrame_ - Parent Object frame
      respectScale_ - Parent Object scale
      RETURNS:
      REMARKS:		 Recursive function
      */

   const MySdlApplication::ShaderState& curSS = MySdlApplication::setupShader(material);

   safe_glUniform3f(curSS.h_uColor, (GLfloat)color[0], (GLfloat)color[1], (GLfloat)color[2]);

   // Draw Parent
   RigTForm respectFrame = respectFrame_ * rtf;
   Matrix4 respectScale = respectScale_ * scale;
   Matrix4 MVM = RigTForm::makeTRmatrix(respectFrame, respectScale);

   if (isVisible)
   {
      if (geom != NULL)
         geom->draw(curSS, MVM, mode);
   }

   //Draw Children
   if (isChildVisible)
   {
      for (int i = 0; i < numOfChildren; i++)
      {
         children[i]->draw(respectFrame, respectScale);
      }
   }

}
Example #3
0
/* helper function to set up material for shading */
void World::SetMaterial(int i) {
   glUseProgram(handles->ShadeProg);
   switch (i) {
      case 0:
         safe_glUniform3f(handles->uMatAmb, 0.2, 0.2, 0.2);
         safe_glUniform3f(handles->uMatDif, 0.4, 0.4, 0.4);
         safe_glUniform3f(handles->uMatSpec, 0.2, 0.2, 0.2);
         safe_glUniform1f(handles->uMatShine, .2);
         break;
      case GROUND_MAT:
         safe_glUniform3f(handles->uMatAmb, 0.1, 0.3, 0.1);
         safe_glUniform3f(handles->uMatDif, 0.1, 0.3, 0.1);
         safe_glUniform3f(handles->uMatSpec, 0.3, 0.3, 0.4);
         safe_glUniform1f(handles->uMatShine, 1.0);
         break;
   }
}
Example #4
0
/**
* @param i an int between 0-3, sends the material info to shaders
*/
void PhongShader::setMaterial(int i) {
  glUseProgram(shadeProg);
  switch (i) {
    case 0:
      safe_glUniform3f(h_uMatAmb, 0.2, 0.2, 0.2);
      safe_glUniform3f(h_uMatDif, 0.97, 0.77, 0.1);
      safe_glUniform3f(h_uMatSpec, 0.4, 0.4, 0.4);
      safe_glUniform1f(h_uMatShine, 200.0);
      break;
    case 1:
      safe_glUniform3f(h_uMatAmb, 0.5, 0.13, 0.14);
      safe_glUniform3f(h_uMatDif, 1, 0, 0);
      safe_glUniform3f(h_uMatSpec, 0.3, 0.3, 0.4);
      safe_glUniform1f(h_uMatShine, 4.0);
      break;
    case 2:
      safe_glUniform3f(h_uMatAmb, 0.2, 0.4, 0.6);
      safe_glUniform3f(h_uMatDif, 0.3, 0.5, 0.4);
      safe_glUniform3f(h_uMatSpec, 0.6, 0.3, 0.4);
      safe_glUniform1f(h_uMatShine, 10.0);
      break;
    case 3:
      safe_glUniform3f(h_uMatAmb, 0.1, 0.5, 0.1);
      safe_glUniform3f(h_uMatDif, 0.2, 0.2, 0.2);
      safe_glUniform3f(h_uMatSpec, 0.4, 0.4, 0.4);
      safe_glUniform1f(h_uMatShine, 4.0);
      break;
    case 4:
      safe_glUniform3f(h_uMatAmb, 0.1, 0.1, 0.1);
      safe_glUniform3f(h_uMatDif, 0.2, 0.2, 0.2);
      safe_glUniform3f(h_uMatSpec, 0.4, 0.4, 0.4);
      safe_glUniform1f(h_uMatShine, 4.0);
      break;
    case 5:
      safe_glUniform3f(h_uMatAmb, 0.3, 0.1, 0.0);
      safe_glUniform3f(h_uMatDif, 0.2, 0.2, 0.2);
      safe_glUniform3f(h_uMatSpec, 0.4, 0.4, 0.4);
      safe_glUniform1f(h_uMatShine, 4.0);
      break;
  }
}