// Initialise and enable lighting
void initialise_lighting()
{	
	
	// Moving overhead lamp
	glLightfv(GL_LIGHT1, GL_SPOT_DIRECTION, moving_spot_direction);
	glLighti(GL_LIGHT1, GL_SPOT_CUTOFF, 35);					// Sets up a light source n, the typ of light used; diffuse for reflections, ambient is monopole distribution, position and spot is directional. Final input sets the position of the light in the x,y,z plane with attenuation factor alpha.
	glLightfv(GL_LIGHT1, GL_AMBIENT, swinging_color);
	glLightfv(GL_LIGHT1, GL_POSITION, ambient_position);
	glLightfv(GL_LIGHT1, GL_DIFFUSE, swinging_color);
	
	// Torch Light (Spotlight)
	
	glLightfv(GL_LIGHT0, GL_SPOT_DIRECTION, spot_direction);
	glLightfv(GL_LIGHT0, GL_POSITION, spot_position);
	glLighti(GL_LIGHT0, GL_SPOT_CUTOFF, 25);		// change to spot_angle
	glLightf(GL_LIGHT0, GL_LINEAR_ATTENUATION, 0.1);
	glLightfv(GL_LIGHT0, GL_AMBIENT, swinging_color);															// directional light shading does not take into account the ordering of surfaces relative to the viewer.


	
	// Material Reflective material
	glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, mat_specular);			// Material affects the surface properties of polygons with lighting. The first input is the polygon back or front faces to the camera being affected. The second input is the parameter of each light source modified, ie. the specular or shininess (reflectivenesS) of a material under lighting. The final input is the co-ordinates of the lighting material.
	glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, mat_shininess);	
	glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, ambient_color);
    glColorMaterial(GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFFUSE);
	
	
	glEnable(GL_COLOR_MATERIAL);

}
Пример #2
0
int Light::setupLights()
{
	#ifdef _DBG
		printf("Setup light%d\n", this->ind);
	#endif

	int lightind = GL_LIGHT0 + this->ind;
	
	if (Light::ctrlSwitch) {
		if (!Light::ctrlSwitch->isOn(this->ind)) { 
			glDisable(lightind);
			return 0;
		}
	}

	glEnable(lightind);
	glLightfv(lightind, GL_AMBIENT, amb);
	glLightfv(lightind, GL_POSITION, pos);
	glLightfv(lightind, GL_DIFFUSE, dif);
	glLightfv(lightind, GL_SPECULAR, spec);

	if (pos[W]==1.0f) { //essa luz e de spot
		glLightfv(lightind, GL_SPOT_DIRECTION, spotDir);
		glLighti(lightind, GL_SPOT_EXPONENT, spotExp);
		glLighti(lightind, GL_SPOT_CUTOFF, spotCutoff);
	}

	return 1;
}
Пример #3
0
//--------------------------------------------------------------
void lightShader::setLighting() 
{	
	glEnable(GL_LIGHTING);
	glEnable(GL_LIGHT0);
	glEnable(GL_NORMALIZE);
	
	// Light model parameters:
	// -------------------------------------------
	
	GLfloat lmKa[] = {0.0, 0.0, 0.0, 0.0 };
	glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmKa);
	
	glLightModelf(GL_LIGHT_MODEL_LOCAL_VIEWER, 1.0);
	glLightModelf(GL_LIGHT_MODEL_TWO_SIDE, 0.0);
	
	// -------------------------------------------
	// Spotlight Attenuation
	
	GLfloat spot_direction[] = {1.0, -1.0, -1.0 };
	GLint spot_exponent = 30;
	GLint spot_cutoff = 180;
	
	glLightfv(GL_LIGHT0, GL_SPOT_DIRECTION, spot_direction);
	glLighti(GL_LIGHT0, GL_SPOT_EXPONENT, spot_exponent);
	glLighti(GL_LIGHT0, GL_SPOT_CUTOFF, spot_cutoff);
    
	GLfloat Kc = 1.0;
	GLfloat Kl = 0.0;
	GLfloat Kq = 0.0;
	
	glLightf(GL_LIGHT0, GL_CONSTANT_ATTENUATION,Kc);
	glLightf(GL_LIGHT0, GL_LINEAR_ATTENUATION, Kl);
	glLightf(GL_LIGHT0, GL_QUADRATIC_ATTENUATION, Kq);

	//diffuse light color variables
	GLfloat dlr = 1.0;
	GLfloat dlg = 1.0;
	GLfloat dlb = 1.0;
	
	//ambient light color variables
	GLfloat alr = 0.95;
	GLfloat alg = 0.85;
	GLfloat alb = 0.0;
	
	//light position variables
	GLfloat lx = 0.0;
	GLfloat ly = -450.0;
	GLfloat lz = -200.0;
	GLfloat lw = 0.0;
	
    GLfloat DiffuseLight[] = {dlr, dlg, dlb}; //set DiffuseLight[] to the specified values
    glLightfv (GL_LIGHT0, GL_DIFFUSE, DiffuseLight); //change the light accordingly
    
	GLfloat AmbientLight[] = {alr, alg, alb}; //set AmbientLight[] to the specified values
	glLightfv (GL_LIGHT0, GL_AMBIENT, AmbientLight); //change the light accordingly
    
    GLfloat LightPosition[] = {lx, ly, lz, lw}; //set the LightPosition to the specified values
    glLightfv (GL_LIGHT0, GL_POSITION, LightPosition); //change the light accordingly
}
Пример #4
0
void __glXDisp_Lighti(GLbyte *pc)
{
	glLighti( 
		*(GLenum   *)(pc + 0),
		*(GLenum   *)(pc + 4),
		*(GLint    *)(pc + 8)
	);
}
Пример #5
0
//场景===========================================================
void baiscobj::light0()
{	//GLfloat light_position[] = {1.0,5.0,1.0,1.0};
    //glLightModelf(GL_LIGHT_MODEL_LOCAL_VIEWER, GL_TRUE);
	//glLightModelf(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE);
	GLfloat light_position[] = {g_look[0], g_look[1], g_look[2], 1.0};
	GLfloat dir[] = {g_look[0]-g_eye[0], g_look[1]-g_eye[1], g_look[1]-g_eye[1]};
	glLightfv(GL_LIGHT0, GL_POSITION, light_position);
	glLightfv(GL_LIGHT0, GL_AMBIENT, light_Ka);
	glLightfv(GL_LIGHT0, GL_DIFFUSE, light_Kd);
	glLightfv(GL_LIGHT0, GL_SPECULAR, light_Ks);
	glLightfv(GL_LIGHT0, GL_SPOT_DIRECTION, dir);
	glLighti(GL_LIGHT0, GL_SPOT_EXPONENT, 30);
	glLighti(GL_LIGHT0, GL_SPOT_CUTOFF, 45.0);
	
	glEnable(GL_LIGHTING);
	glEnable(GL_LIGHT0);
	glEnable(GL_DEPTH_TEST);
	glEnable(GL_COLOR_MATERIAL);
}
void LightSource::init() {
	for( int i = 0; i < GL_MAX_LIGHTS; i++ )
		lights_used[i] = false;
		
	glEnable( GL_LIGHTING );
	glLightModeli( GL_LIGHT_MODEL_LOCAL_VIEWER, GL_TRUE );

	glLighti( GL_LIGHT0, GL_CONSTANT_ATTENUATION, 1 );

	/* Enable colour tracking */
	glEnable( GL_COLOR_MATERIAL );
	glColorMaterial( GL_FRONT, GL_AMBIENT_AND_DIFFUSE );
}
Пример #7
0
void CglicLight::glicInit()
{
  // check if enabled ...
  GLenum   light = GL_LIGHT0 + lid;

  glLightfv(light, GL_AMBIENT, glm::value_ptr(amb));
  glLightfv(light, GL_DIFFUSE, glm::value_ptr(dif));
  glLightfv(light, GL_SPECULAR, glm::value_ptr(spe));

  switch (ltyp) {
    case TL_POINT:
      pos[3] = 1.0;
      glLightfv(light, GL_POSITION, glm::value_ptr(pos));
      glLightf(light, GL_SPOT_CUTOFF, 180.0);
      break;
    case TL_DIRECTION:
      pos[3] = 0.0;
      glLightfv(light, GL_POSITION, glm::value_ptr(pos));
      glLightf(light, GL_SPOT_CUTOFF, 180.0);
      break;
    case TL_SPOT:
      pos[3] = 1.0;
      glLightfv(light, GL_POSITION, glm::value_ptr(pos));
      glLightf(light, GL_SPOT_CUTOFF, spotCutoff);
      glLightfv(light, GL_SPOT_DIRECTION, spotDirect);
      glLightf(light, GL_SPOT_EXPONENT, spotExp);
      break;
    default:

      break;
  }

  glLighti(light, GL_CONSTANT_ATTENUATION, cstatt);
  glLighti(light, GL_LINEAR_ATTENUATION, linatt);
  glLighti(light, GL_QUADRATIC_ATTENUATION, quadatt);
}
Пример #8
0
void Light::SetupLight(int lightIndex){
    glEnable(GL_LIGHT0+lightIndex);
    // Setup and enable light 0
    glLightfv(GL_LIGHT0+lightIndex,GL_AMBIENT, glm::value_ptr(GetAmbient()));
    glLightfv(GL_LIGHT0+lightIndex,GL_DIFFUSE, glm::value_ptr(GetDiffuse()));
    glLightfv(GL_LIGHT0+lightIndex,GL_SPECULAR, glm::value_ptr(GetSpecular()));
	glLighti(GL_LIGHT0+lightIndex, GL_SPOT_CUTOFF, spotCutoff); 
	glLightfv(GL_LIGHT0+lightIndex,GL_SPOT_DIRECTION, glm::value_ptr(spotDirection));
    float w = 0;
    if (GetLightType()==PointLight){
        w = 1;
    } else if (GetLightType()==DirectionalLight){
        w = 0;
    }
    SceneObject *sceneObject = GetOwner();
    assert(sceneObject != NULL);
    glm::vec4 lightPos(sceneObject->GetTransform()->GetPosition(), w);

    glLightfv(GL_LIGHT0+lightIndex,GL_POSITION, glm::value_ptr(lightPos));
}
Пример #9
0
void
screen_display(void)
{
    GLfloat pos[4], lKa[4], lKd[4], lKs[4];
    GLfloat dir[3], mKa[4], mKd[4], mKs[4], mKe[4];
    GLfloat lmKa[4];

    cell_vector(pos, light_pos, 4);
    cell_vector(lKa, light_Ka, 4);
    cell_vector(lKd, light_Kd, 4);
    cell_vector(lKs, light_Ks, 4);
    cell_vector(dir, spot_direction, 3);
    cell_vector(mKa, material_Ka, 4);
    cell_vector(mKd, material_Kd, 4);
    cell_vector(mKs, material_Ks, 4);
    cell_vector(mKe, material_Ke, 4);
    cell_vector(lmKa, lmodel_Ka, 4);

    glLightModelf(GL_LIGHT_MODEL_LOCAL_VIEWER, local_viewer.value);
    glLightModelf(GL_LIGHT_MODEL_TWO_SIDE, two_side.value);
    glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmKa);

    glLightfv(GL_LIGHT0, GL_POSITION, pos);
    glLightfv(GL_LIGHT0, GL_AMBIENT, lKa);
    glLightfv(GL_LIGHT0, GL_DIFFUSE, lKd);
    glLightfv(GL_LIGHT0, GL_SPECULAR, lKs);
    glLightfv(GL_LIGHT0, GL_SPOT_DIRECTION, dir);
    glLighti(GL_LIGHT0, GL_SPOT_EXPONENT, (int)spot_exponent.value);
    if (spot_cutoff.value > 90)
        glLighti(GL_LIGHT0, GL_SPOT_CUTOFF, 180);
    else
        glLighti(GL_LIGHT0, GL_SPOT_CUTOFF, (int)spot_cutoff.value);
    glLightf(GL_LIGHT0, GL_CONSTANT_ATTENUATION, Kc.value);
    glLightf(GL_LIGHT0, GL_LINEAR_ATTENUATION, Kl.value);
    glLightf(GL_LIGHT0, GL_QUADRATIC_ATTENUATION, Kq.value);

    glMaterialfv(GL_FRONT, GL_AMBIENT, mKa);
    glMaterialfv(GL_FRONT, GL_DIFFUSE, mKd);
    glMaterialfv(GL_FRONT, GL_SPECULAR, mKs);
    glMaterialfv(GL_FRONT, GL_EMISSION, mKe);
    glMaterialf(GL_FRONT, GL_SHININESS, material_Se.value);

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glPushMatrix();
    glRotatef(spin_y, 1.0, 0.0, 0.0);
    glRotatef(spin_x, 0.0, 1.0, 0.0);
    glGetDoublev(GL_MODELVIEW_MATRIX, modelview);
    if (pmodel)
        drawmodel();
    else
        glutSolidTorus(0.25, 0.75, 28, 28);
    glPopMatrix();

#if 0
#define TESS 20
    glNormal3f(0.0, 1.0, 0.0);
    for (i = 0; i < TESS; i++) {
        glBegin(GL_TRIANGLE_STRIP);
        for (j = 0; j <= TESS; j++) {
            glVertex3f(-1+(float)i/TESS*2, -1.0, -1+(float)j/TESS*2);
            glVertex3f(-1+(float)(i+1)/TESS*2, -1.0, -1+(float)j/TESS*2);
        }
        glEnd();
    }
#endif

    glutSwapBuffers();
}
Пример #10
0
void
world_display(void)
{
    double length;
    float l[3];
    GLfloat pos[4], lKa[4], lKd[4], lKs[4];
    GLfloat dir[3], mKa[4], mKd[4], mKs[4], mKe[4];
    GLfloat lmKa[4];

    cell_vector(pos, light_pos, 4);
    cell_vector(lKa, light_Ka, 4);
    cell_vector(lKd, light_Kd, 4);
    cell_vector(lKs, light_Ks, 4);
    cell_vector(dir, spot_direction, 3);
    cell_vector(mKa, material_Ka, 4);
    cell_vector(mKd, material_Kd, 4);
    cell_vector(mKs, material_Ks, 4);
    cell_vector(mKe, material_Ke, 4);
    cell_vector(lmKa, lmodel_Ka, 4);

    glLightModelf(GL_LIGHT_MODEL_LOCAL_VIEWER, local_viewer.value);
    glLightModelf(GL_LIGHT_MODEL_TWO_SIDE, two_side.value);
    glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmKa);

    glMaterialfv(GL_FRONT, GL_AMBIENT, mKa);
    glMaterialfv(GL_FRONT, GL_DIFFUSE, mKd);
    glMaterialfv(GL_FRONT, GL_SPECULAR, mKs);
    glMaterialfv(GL_FRONT, GL_EMISSION, mKe);
    glMaterialf(GL_FRONT, GL_SHININESS, material_Se.value);

    glLightfv(GL_LIGHT0, GL_AMBIENT, lKa);
    glLightfv(GL_LIGHT0, GL_DIFFUSE, lKd);
    glLightfv(GL_LIGHT0, GL_SPECULAR, lKs);
    glLighti(GL_LIGHT0, GL_SPOT_EXPONENT, (int)spot_exponent.value);
    if (spot_cutoff.value > 90)
        glLighti(GL_LIGHT0, GL_SPOT_CUTOFF, 180);
    else
        glLighti(GL_LIGHT0, GL_SPOT_CUTOFF, (int)spot_cutoff.value);
    glLightf(GL_LIGHT0, GL_CONSTANT_ATTENUATION, Kc.value);
    glLightf(GL_LIGHT0, GL_LINEAR_ATTENUATION, Kl.value);
    glLightf(GL_LIGHT0, GL_QUADRATIC_ATTENUATION, Kq.value);

    l[0] = at[0] - eye[0];
    l[1] = at[1] - eye[1];
    l[2] = at[2] - eye[2];

    invert(modelview, inverse);

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glPushMatrix();
    glMultMatrixd(inverse);
    glTranslatef(l[0], l[1], l[2]);
    glColor3fv(lKd);
    glBegin(GL_LINE_STRIP);
    if (spot_cutoff.value > 90)
        glVertex3f(0, 0, 0);
    else
        glVertex3f(pos[0]+spot_direction[0].value,
                   pos[1]+spot_direction[1].value,
                   pos[2]+spot_direction[2].value);

    if (pos[3] == 0)        /* 10.0 = 'infinite' light */
        glVertex3f(pos[0]*10.0,pos[1]*10.0,pos[2]*10.0);
    else
        glVertex3f(pos[0], pos[1], pos[2]);
    glEnd();
    glLightfv(GL_LIGHT0, GL_SPOT_DIRECTION, dir);
    glLightfv(GL_LIGHT0, GL_POSITION, pos);
    glPopMatrix();

    length = normalize(l);

    if (world_draw) {
        glEnable(GL_LIGHTING);
        if (pmodel)
            drawmodel();
        else
            glutSolidTorus(0.25, 0.75, 28, 28);
        glDisable(GL_LIGHTING);
    }

#if 0
#define TESS 20
    glNormal3f(0.0, 1.0, 0.0);
    for (i = 0; i < TESS; i++) {
        glBegin(GL_TRIANGLE_STRIP);
        for (j = 0; j <= TESS; j++) {
            glVertex3f(-1+(float)i/TESS*2, -1.0, -1+(float)j/TESS*2);
            glVertex3f(-1+(float)(i+1)/TESS*2, -1.0, -1+(float)j/TESS*2);
        }
        glEnd();
    }
#endif

    glPushMatrix();
    glMultMatrixd(inverse);

    /* draw the axis and eye vector */
    glPushMatrix();
    glColor3ub(0, 0, 255);
    glBegin(GL_LINE_STRIP);
    glVertex3f(0.0, 0.0, 0.0);
    glVertex3f(0.0, 0.0, -1.0*length);
    glVertex3f(0.1, 0.0, -0.9*length);
    glVertex3f(-0.1, 0.0, -0.9*length);
    glVertex3f(0.0, 0.0, -1.0*length);
    glVertex3f(0.0, 0.1, -0.9*length);
    glVertex3f(0.0, -0.1, -0.9*length);
    glVertex3f(0.0, 0.0, -1.0*length);
    glEnd();
    glColor3ub(255, 255, 0);
    glRasterPos3f(0.0, 0.0, -1.1*length);
    glutBitmapCharacter(GLUT_BITMAP_HELVETICA_12, 'e');
    glColor3ub(255, 0, 0);
    glScalef(0.4, 0.4, 0.4);
    drawaxes();
    glPopMatrix();

    invert(projection, inverse);
    glMultMatrixd(inverse);

    /* draw the viewing frustum */
    glColor3f(0.2, 0.2, 0.2);
    glBegin(GL_QUADS);
    glVertex3i(1, 1, 1);
    glVertex3i(-1, 1, 1);
    glVertex3i(-1, -1, 1);
    glVertex3i(1, -1, 1);
    glEnd();

    glColor3ub(128, 196, 128);
    glBegin(GL_LINES);
    glVertex3i(1, 1, -1);
    glVertex3i(1, 1, 1);
    glVertex3i(-1, 1, -1);
    glVertex3i(-1, 1, 1);
    glVertex3i(-1, -1, -1);
    glVertex3i(-1, -1, 1);
    glVertex3i(1, -1, -1);
    glVertex3i(1, -1, 1);
    glEnd();

    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    glColor4f(0.2, 0.2, 0.4, 0.5);
    glBegin(GL_QUADS);
    glVertex3i(1, 1, -1);
    glVertex3i(-1, 1, -1);
    glVertex3i(-1, -1, -1);
    glVertex3i(1, -1, -1);
    glEnd();
    glDisable(GL_BLEND);

    glPopMatrix();
    glutSwapBuffers();
}
Пример #11
0
void GLWidget::initializeGL()
{
	qglClearColor(Qt::black);
	glEnable(GL_DEPTH_TEST);
	glEnable (GL_BLEND);
	glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	glShadeModel(GL_SMOOTH);
	glEnable(GL_NORMALIZE);
	glEnable(GL_LIGHTING);
	glColorMaterial(GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFFUSE);
	glEnable(GL_COLOR_MATERIAL);
	
	glEnable(GL_CULL_FACE);
	
	if (GLEW_OK != glewInit())
	{
		qDebug() << "glewInit() failed!";
		exit(1);
	}
	
	if(m_displaying_particles)
	{
		glEnable(GL_FOG);
		float fog_color[] = {1.0, 1.0, 1.0, 1.0};
		float fog_density[] = {0.3};
		glFogfv(GL_FOG_COLOR, fog_color);
		glFogfv(GL_FOG_DENSITY, fog_density);
	}
	
	float ambient[] = {0.1, 0.1, 0.1, 1.0};
	glLightModelfv(GL_LIGHT_MODEL_AMBIENT, ambient);

	glEnable(GL_LIGHT0);
	glLighti(GL_LIGHT0, GL_NONE, 1);

	
	skybox = new Skybox();
	for (int i = 1; i<10; i++){
		glNewList(i, GL_COMPILE);
		tree();
		glEndList();
	}
	glNewList(11, GL_COMPILE);
	glColor3f(1.0,1.0,1.0);
	sphere();
	glEndList();
	m_map = new Map();
	
	change_current_chunk();
	qDebug() << "HARP DARP" << m_nchunk;
	Heightmap * hm = m_nchunk->heightmap;
	m_particles = new ParticleEngine();
	
	//cam = new TerrainCamera(2.5,2.5,hm, m_map);
	cam = new Camera3d(0,1.0,0, m_map);
	
	m_bloomShader = new BloomShader(this);	
	m_toonShader = new ToonShader();
	m_plainShader = new PlainShader();
	m_fbo = new QGLFramebufferObject(width(), height(), QGLFramebufferObject::NoAttachment);
	
	glGenRenderbuffers(1, &m_depthBuf);
}
Пример #12
0
/////////////////////////////////////////////////////////
// Render
//
void GEMglLighti :: render(GemState *state)
{
  glLighti (light, pname, param);
}
Пример #13
0
void TriangleWindow::initializeLighting() {
    qDebug() << "start lumens";
    glEnable(GL_LIGHTING);
     glEnable(GL_LIGHT0);
     glEnable(GL_NORMALIZE);

     // Light model parameters:
     // -------------------------------------------

     GLfloat lmKa[] = {0.0, 0.0, 0.0, 0.0 };
     glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmKa);

     glLightModelf(GL_LIGHT_MODEL_LOCAL_VIEWER, 1.0);
     glLightModelf(GL_LIGHT_MODEL_TWO_SIDE, 0.0);

     // -------------------------------------------
     // Spotlight Attenuation

     GLfloat spot_direction[] = {1.0, -1.0, -1.0 };
     GLint spot_exponent = 30;
     GLint spot_cutoff = 180;

     glLightfv(GL_LIGHT0, GL_SPOT_DIRECTION, spot_direction);
     glLighti(GL_LIGHT0, GL_SPOT_EXPONENT, spot_exponent);
     glLighti(GL_LIGHT0, GL_SPOT_CUTOFF, spot_cutoff);

     GLfloat Kc = 1.0;
     GLfloat Kl = 0.0;
     GLfloat Kq = 0.0;

     glLightf(GL_LIGHT0, GL_CONSTANT_ATTENUATION,Kc);
     glLightf(GL_LIGHT0, GL_LINEAR_ATTENUATION, Kl);
     glLightf(GL_LIGHT0, GL_QUADRATIC_ATTENUATION, Kq);


     // -------------------------------------------
     // Lighting parameters:

     GLfloat light_pos[] = {0.0f, 5.0f, 5.0f, 1.0f};
     GLfloat light_Ka[]  = {1.0f, 0.5f, 0.5f, 1.0f};
     GLfloat light_Kd[]  = {1.0f, 0.1f, 0.1f, 1.0f};
     GLfloat light_Ks[]  = {1.0f, 1.0f, 1.0f, 1.0f};

     glLightfv(GL_LIGHT0, GL_POSITION, light_pos);
     glLightfv(GL_LIGHT0, GL_AMBIENT, light_Ka);
     glLightfv(GL_LIGHT0, GL_DIFFUSE, light_Kd);
     glLightfv(GL_LIGHT0, GL_SPECULAR, light_Ks);

     // -------------------------------------------
     // Material parameters:

     GLfloat material_Ka[] = {0.5f, 0.0f, 0.0f, 1.0f};
     GLfloat material_Kd[] = {0.4f, 0.4f, 0.5f, 1.0f};
     GLfloat material_Ks[] = {0.8f, 0.8f, 0.0f, 1.0f};
     GLfloat material_Ke[] = {0.1f, 0.0f, 0.0f, 0.0f};
     GLfloat material_Se = 20.0f;

     glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, material_Ka);
     glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, material_Kd);
     glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, material_Ks);
     glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, material_Ke);
     glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, material_Se);
}
Пример #14
0
void Scene::keyboardDownHandler(unsigned char key, int x, int y) {
	Material* m;
	double a;
	switch ((int)key) {
		case 32: // Space - next camera
			nextCam();
			break;
		case 27: // Escape - Quit
			exit(EXIT_SUCCESS);
		case 43: // + - Glowing fish lighter
			if (attenuation >= -0.1) {
				attenuation -= 0.1;
			    glLightf(GL_LIGHT0, GL_CONSTANT_ATTENUATION, attenuation);
			    glLightf(GL_LIGHT0, GL_LINEAR_ATTENUATION, 0.0f);
				glLighti(GL_LIGHT0, GL_QUADRATIC_ATTENUATION, 0);
			}
			m = Fish::getFirst()->getMaterial();
			a = 1 - (attenuation / 3.0);
			m->getEmissiveColor()->set(a, a, a);
			break;
		case 45: // - - Glowing fish darker
			if (attenuation <= 2.9) {
				attenuation += 0.1;
			    glLightf(GL_LIGHT0, GL_CONSTANT_ATTENUATION, attenuation);
			    glLightf(GL_LIGHT0, GL_LINEAR_ATTENUATION, 0.0f);
				glLighti(GL_LIGHT0, GL_QUADRATIC_ATTENUATION, 0);
			}
			m = Fish::getFirst()->getMaterial();
			a = 1 - (attenuation / 3.0);
			m->getEmissiveColor()->set(a, a, a);
			break;
		case 102: // f - Start max fish count test
			if (!calculateFishCount) {
				calculateFishCount = true;
				maxFishCount = fishList->size();
				while (sharkList->size() > 0) {
					sharkList->removeNode();
				}
				glutPostRedisplay();
			}
			break;
		case 110: // n - Toggle names
			drawNames = !drawNames;
			break;
		case 104: // h - Toggle help
			drawHelp = !drawHelp;
			for (list<Text*>::iterator it = helpDisplay.begin(); it != helpDisplay.end(); it++) {
				(*it)->setEnabled(drawHelp);
			}
			break;
		case 111: // o - Move camera z up
			camPos[activeCam]->y += 5.0;
			break;
		case 108: // l - Move camera z down
			camPos[activeCam]->y -= 5.0;
			break;
		case 116: // t - Toggle top light
			topLight = !topLight;
			if (topLight) {
				glEnable(GL_LIGHT1);
			} else {
				glDisable(GL_LIGHT1);
			}
			break;
		case 49: {  // 1 - Add fish
			ostringstream name;
			name << "Fish";
			int x = (rand() % ((int)tankWidth - 50))-((int)tankWidth/2);
			int y = (rand() % ((int)tankHeight - 50))-((int)tankHeight/2);
			int z = (rand() % ((int)tankDepth - 10))-((int)tankDepth/2);
			Material* mat = material();
			*mat = *Material::getFishMaterial();
			fishList->addNode(new Fish(mat, new Text(name.str(), 1.2),
				new Vector(x, y, z), new Vector(1, 0, 0)));
			for (int i = 0; i < sharkList->size(); i++) {
				((Shark*)sharkList->getNode(i))->nextTarget();
			}
			break;
		}
		case 50:  // 2 - Remove fish
			if (fishList->size() > 1) {
				fishList->removeNode();
				for (int i = 0; i < sharkList->size(); i++) {
					((Shark*)sharkList->getNode(i))->nextTarget();
				}
			}
			break;
		case 51: { // 3 - Add shark
			Material *sharkmat = material();
			sharkmat->setDiffuseColor(color(0.3, 0.3, 0.3));
			sharkList->addNode(new Shark(sharkmat, new Text("Shark", 1.2),
				new Vector(1, 0, 0), new Vector(-1, 0, 0)));
			break;
		}
		case 52:  // 4 - Remove shark
			sharkList->removeNode();
			break;
		case 112: // p - Pause
			paused = !paused;
			break;
		case 120: // x - Write TGAs
			tgaWriter = !tgaWriter;
			break;
		default:
			cout << "Key: " << (int)key << "\n";
			break;
	}
}
Пример #15
0
inline void glLight( const GLenum & light, const GLenum & pname, const GLint & param )		{ glLighti( light, pname, param ); }
// GLUT callback. Called to draw the scene.
void My_Display()
{
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	//GLfloat angleX = ((GLfloat)windowRotateX / ((GLfloat)window_width / 2)) * 180;
	//GLfloat angleY = ((GLfloat)windowRotateY / ((GLfloat)window_height / 2)) * 180;

	
	//Arm left_up_arm(1, -1, 1);
	//Arm right_up_arm(-1,-1,1);

	//initial matrix
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
	glLightfv(GL_LIGHT0, GL_POSITION, lightPos);

	gluLookAt(0.0, 0.0, nRange, 0.0, 0.0, 0.0, 0.0, 0.1, 0.0);

	{
		glutSolidCube(0.08f*nRange/10.0f);
	}

	glMultMatrixf(World_Matrix);

	SpotlightPos[0] = 0.0f;
	SpotlightPos[1] = -13.5f;
	SpotlightPos[2] = 8.0f;
	SpotlightPos[3] = 1.0f;

	
	
	glLightfv(GL_LIGHT1, GL_AMBIENT, ambientLight);
	glLightfv(GL_LIGHT1, GL_DIFFUSE, diffuseLight);
	glLightfv(GL_LIGHT1, GL_SPECULAR, specular);
	glLightfv(GL_LIGHT1, GL_POSITION, SpotlightPos);
	glLightfv(GL_LIGHT1, GL_SPOT_DIRECTION, Vector3<GLfloat>(0.0f, 13.5f, -0.8f).toArray());
	glLighti(GL_LIGHT1, GL_SPOT_CUTOFF, 30);
	glLightf(GL_LIGHT1, GL_SPOT_EXPONENT, 1000.0f);

	SpotlightPos[0] = 0.0f;
	SpotlightPos[1] = -9.5f;
	SpotlightPos[2] = 0.0f;
	SpotlightPos[3] = 1.0f;

	glLightfv(GL_LIGHT2, GL_AMBIENT, ambientLight);
	glLightfv(GL_LIGHT2, GL_DIFFUSE, diffuseLight);
	glLightfv(GL_LIGHT2, GL_SPECULAR, specular);
	glLightfv(GL_LIGHT2, GL_POSITION, SpotlightPos);
	glLightfv(GL_LIGHT2, GL_SPOT_DIRECTION, Vector3<GLfloat>(0.0f, -1.0f, 0.0f).toArray());
	glLighti(GL_LIGHT2, GL_SPOT_CUTOFF, 60);
	glLightf(GL_LIGHT2, GL_SPOT_EXPONENT, 1000.0f);
	


	glPushMatrix();
	{
		
		//glRotatef(angleX, 0.0, 1.0, 0.0);
		//glRotatef(angleY, 1.0, 0.0, 0.0);
		//glRotatef(angle,0.0f,1.0f,0.0f);

		glPushMatrix();
		{
			glPushMatrix();
			{
				glTranslatef(0.0f,-13.5f,0.0f);
				magiccircle.draw();
			}
			glPopMatrix();
			
			glTranslatef(0.0f, body.torso_pos, 0.0f);
			
			glPushMatrix();
			{
				glRotateXYZ(body.torso_tilt);
				body.draw();    //body


				glPushMatrix();   //left wing
				{
					glTranslatef(1.3f, 3.0f, -1.1f);
					glRotatef(25.0f, 0.0f, 1.0f, 0.0f);
					glRotatef(-5.0f, 0.0f, 0.0f, 1.0f);
					left_wing.draw();
				}
				glPopMatrix();

				glPushMatrix();   //right wing
				{
					glTranslatef(-1.3f, 3.0f, -1.1f);
					glRotatef(-25.0f, 0.0f, 1.0f, 0.0f);
					glRotatef(5.0f, 0.0f, 0.0f, 1.0f);
					right_wing.draw();
				}
				glPopMatrix();

				glPushMatrix();   //head
				{
					glTranslatef(0.0f, 4.0f, 0.0f);
					head.draw();
				}
				glPopMatrix();

				glPushMatrix();    //left arm
				{
					glTranslatef(3.0f, 2.6f, 0.0f);
					left_arm.draw();
					
				}
				glPopMatrix();
				
				glPushMatrix();    //right arm
				{
					glTranslatef(-3.0f, 2.6f, 0.0f);
					right_arm.draw();
					
				}
				glPopMatrix();
				
				glPushMatrix();    //left leg
				{
					glTranslatef(1.7f, -4.0f, 0.0f);
					glRotateXYZ(-body.torso_tilt[0], 0.0f, 0.0f);
					left_leg.draw();

				}
				glPopMatrix();

				glPushMatrix();    //right leg
				{
					glTranslatef(-1.7f, -4.0f, 0.0f);
					glRotateXYZ(-body.torso_tilt[0], 0.0f, 0.0f);
					right_leg.draw();
				}
				glPopMatrix();
			}
			glPopMatrix();
			
			
		}
		glPopMatrix();

		
		/*
		glPushMatrix();
		{
			glTranslatef(2.2f, 0.7f, 0.0f);
			left_up_arm.draw();
		}
		glPopMatrix();

		glPushMatrix();
		{
			glTranslatef(-2.2f, 0.7f, 0.0f);
			right_up_arm.draw();
		}
		glPopMatrix();*/

	}
	glPopMatrix();

	glutSwapBuffers();
}