Ejemplo n.º 1
0
void display()
{
    /*
     *  A Simple display function to run the entire show
     *  static variables are used to save past state of
     *  the worm, and reflect future motion based on state
     */    static float trans;
    static float timer;
    static float dt;
    if(dt == 0.0f){
        dt = DELTA_T;
        trans = START_CORD;
    }
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrtho(-2.0 * 64/48.0, 2.0 * 64/48.0, -2.0, 2.0, 0.1, 100);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    //  Angular (maybe isometric) view
    gluLookAt(2.0, 2.0, 2.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
    //  Side View
    //gluLookAt(1.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
    //  Top View
    //gluLookAt(0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0);
    glClear(GL_COLOR_BUFFER_BIT);
    glColor4f(0,0,1.0,1.0);
    glTranslatef(trans, 0.0, 0.0);
    capsule();
    glTranslatef(0.5f, 0.0, 0.0);
    glRotatef(ANGLE_MAX*(timer), 0.0, 0.0, 1.0f);
    body();
    glTranslatef(0.5f, 0.0, 0.0);
    glRotatef(-2*ANGLE_MAX*(timer), 0.0, 0.0, 1.0f);
    body();
    glTranslatef(0.5f, 0.0, 0.0);
    glRotatef(ANGLE_MAX*(timer), 0.0, 0.0, 1.0f);
    body();
    if(timer == 1 || (timer==0 && dt<0)){
        dt = -dt;
    }
#ifdef __APPLE__
    glSwapAPPLE();
#else
    glSwapBuffers();
#endif
    trans = trans + 0.1f*timer;
    timer = timer + dt;
    
    
}
Ejemplo n.º 2
0
// Render method runs repeatedly in a loop
void Game::Render() 
{
	
	// Clear the buffers and enable depth testing (z-buffering)
	glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glEnable(GL_DEPTH_TEST);

	// Set up a matrix stack
	glutil::MatrixStack modelViewMatrixStack;
	modelViewMatrixStack.SetIdentity();
	modelViewMatrixStack.LookAt(m_pCamera->GetPosition(), m_pCamera->GetView(), m_pCamera->GetUpVector());


	// Use the main shader program 
	CShaderProgram *pMainProgram = (*m_pShaderPrograms)[0];
	pMainProgram->UseProgram();

	// Set light and materials in main shader program
	glm::vec4 vPosition(-100, 100, 50, 1);
	glm::mat3 normalMatrix = m_pCamera->ComputeNormalMatrix(modelViewMatrixStack.Top());
	glm::vec4 vLightEye = modelViewMatrixStack.Top()*vPosition;
	pMainProgram->SetUniform("light1.position", vLightEye);		// Position of light source in eye coordinates
	pMainProgram->SetUniform("light1.La", glm::vec3(0.15f, 0.15f, 0.15f));
	pMainProgram->SetUniform("light1.Ld", glm::vec3(1.0f, 1.0f, 1.0f));
	pMainProgram->SetUniform("light1.Ls", glm::vec3(1.0f, 1.0f, 1.0f));
	pMainProgram->SetUniform("material1.Ma", glm::vec3(0.5f, 0.5f, 0.5f));
	pMainProgram->SetUniform("material1.Md", glm::vec3(0.5f, 0.5f, 0.5f));
	pMainProgram->SetUniform("material1.Ms", glm::vec3(0.5f, 0.5f, 0.5f));
	pMainProgram->SetUniform("material1.shininess", 15.0f);
	pMainProgram->SetUniform("bUseTexture", false);
	pMainProgram->SetUniform("sampler0", 0);


	// Render the grid
	modelViewMatrixStack.Push();
		pMainProgram->SetUniform("matrices.projMatrix", m_pCamera->GetPerspectiveProjectionMatrix());
		pMainProgram->SetUniform("matrices.modelViewMatrix", modelViewMatrixStack.Top());
		pMainProgram->SetUniform("matrices.normalMatrix", m_pCamera->ComputeNormalMatrix(modelViewMatrixStack.Top()));
		m_pGrid->Render();
	modelViewMatrixStack.Pop();

	
	// Switch to the sphere program
	CShaderProgram *pSphereProgram = (*m_pShaderPrograms)[2];
	pSphereProgram->UseProgram();

	// Set light and materials in sphere programme
	pSphereProgram->SetUniform("material1.Ma", glm::vec3(0.0f, 1.0f, 0.0f));
	pSphereProgram->SetUniform("material1.Md", glm::vec3(0.0f, 1.0f, 0.0f));
	pSphereProgram->SetUniform("material1.Ms", glm::vec3(1.0f, 1.0f, 1.0f));
	pSphereProgram->SetUniform("material1.shininess", 50.0f);
	pSphereProgram->SetUniform("light1.La", glm::vec3(0.15f, 0.15f, 0.15f));
	pSphereProgram->SetUniform("light1.Ld", glm::vec3(1.0f, 1.0f, 1.0f));
	pSphereProgram->SetUniform("light1.Ls", glm::vec3(1.0f, 1.0f, 1.0f));
	pSphereProgram->SetUniform("light1.position", vLightEye); 

	// Render the sphere
	modelViewMatrixStack.Push();
		modelViewMatrixStack.Translate(glm::vec3(0.0f, 5.0f, 50.0f));
		modelViewMatrixStack.Scale(5.0f);
		pSphereProgram->SetUniform("matrices.projMatrix", m_pCamera->GetPerspectiveProjectionMatrix());
		pSphereProgram->SetUniform("matrices.modelViewMatrix", modelViewMatrixStack.Top());
		pSphereProgram->SetUniform("matrices.normalMatrix", m_pCamera->ComputeNormalMatrix(modelViewMatrixStack.Top()));
		
		pSphereProgram->SetUniform("t",m_elapsedTime);
			
		pSphereProgram->SetUniform("levels",m_levels);

		glEnable(GL_BLEND);
		glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
		m_pSphere->Render();
	modelViewMatrixStack.Pop();

#ifdef __WIN32
    void swapBuffers();
#endif
#ifdef __APPLE__
    glSwapAPPLE();
#endif

}
Ejemplo n.º 3
0
void paint_bar(Stimulus *st, Substim *sst, int mode)
{
   Locator *pos = &sst->pos;
  int i,ci,w,h;
  float x[2],z[2],vcolor[3],*xc,*yc,*cc,*rc,cval;
  float angle,val;

    val = (st->background) * (1+ pos->contrast);
  if(pos->contrast > 2)
    val = 1.0;
  else if (st->background == 0)
    val = pos->contrast;
  cval = dogamma(val);
  vcolor[0] = vcolor[1] = vcolor[2] = cval;

  glPushMatrix();
  glTranslatef((pos->xy[0]),pos->xy[1],0);
  angle = (float) (pos->angle * 180.0/M_PI);
  glRotatef(angle,0,0,1);

  if(mode == LEFTMODE)
  {
    rc = cc = &vcolor[0];
  }
  else if(mode == RIGHTMODE)
  {
    cc = &vcolor[1];
    rc = &vcolor[2];
  }
   val = pos->phase;
   while(val > (2 * M_PI))
     val -= (M_PI * 2);

/*
* for bars, pos->f determines the width of the bar, while
* pos->radius[1] determines the field over which the bar moves
*/
   h = pos->radius[0];
   w = deg2pix(1/(2*st->f));
  z[0] = (-pos->radius[0]);
/*
 * if SQUARE, have constant velocity sweeps in one direction. Sign reversal 
 * is so that direction matches sines/rds
 */

  if(st->flag & STIMULUS_IS_SQUARE)
    z[1] = -w/2 - ((pos->radius[1]) * (val/M_PI -1));
  else
    z[1] = ((pos->radius[1]) * cos(val)) - w/2;
  glBegin(GL_POLYGON);
  mycolor(vcolor);	
  x[0] = z[0];
  x[1] = z[1];
  myvx(x);
  x[1] = z[1] + w;
  myvx(x);
  x[0] = z[0] +2 *  pos->radius[0];
  myvx(x);
  x[1] = z[1];
  myvx(x);
  glEnd();

  if(optionflag & ANTIALIAS_BIT)
    {
  glPolygonMode(GL_FRONT_AND_BACK,GL_LINE);
  glLineWidth(1.0);
  glEnable(GL_BLEND);
  glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  glEnable(GL_LINE_SMOOTH);
  glBegin(GL_POLYGON);
  mycolor(vcolor);	
  x[0] = z[0];
  x[1] = z[1];
  myvx(x);
  x[1] = z[1] + w;
  myvx(x);
  x[0] = z[0] +2 *  pos->radius[0];
  myvx(x);
  x[1] = z[1];
  myvx(x);
  glEnd();
  glDisable(GL_BLEND);
  glDisable(GL_LINE_SMOOTH);
  glPolygonMode(GL_FRONT_AND_BACK,GL_FILL);
    }
  glPopMatrix();
  for(i = 0; i < sst->nbars; i++){
    glPushMatrix();
    glTranslatef(sst->xpos[i],sst->ypos[i],0);
    angle = (float) (sst->imb[i] * 180.0/M_PI);
    glRotatef(angle,0,0,1);
  glBegin(GL_POLYGON);
  mycolor(vcolor);	
  x[0] = z[0];
  x[1] = z[1];
  myvx(x);
  x[1] = z[1] + w;
  myvx(x);
  x[0] = z[0] +2 *  pos->radius[0];
  myvx(x);
  x[1] = z[1];
  myvx(x);
  glEnd();
    glPopMatrix();
      if(debug){
      glFlushRenderAPPLE();
          glSwapAPPLE();
      }
  }

}