ho definito questi array:
codice:
GLfloat lightPos[] = { 38.0f, 2.0f, 2.0f, 1.0f };
GLfloat specular[] = { 1.0f, 1.0f, 1.0f, 1.0f};
GLfloat specref[] = { 1.0f, 1.0f, 1.0f, 1.0f };
GLfloat ambientLight[] = { 0.5f, 0.5f, 0.5f, 1.0f};
GLfloat spotDir[] = { 38.0f, 2.0f, -1.0f };
poi ho una funzione di inizializzazione della scena che contiente queste istruzioni relative alla luce:
codice:
// Enable lighting
glEnable(GL_LIGHTING);
// Setup and enable light 0
// Supply a slight ambient light so the objects can be seen
glLightModelfv(GL_LIGHT_MODEL_AMBIENT, ambientLight);
// The light is composed of just a diffuse and specular components
glLightfv(GL_LIGHT0,GL_DIFFUSE,ambientLight);
glLightfv(GL_LIGHT0,GL_SPECULAR,specular);
glLightfv(GL_LIGHT0,GL_POSITION,lightPos);
// Specific spot effects
// Cut off angle is 60 degrees
glLightf(GL_LIGHT0,GL_SPOT_CUTOFF,50.0f);
// Enable this light in particular
glEnable(GL_LIGHT0);
// Enable color tracking
glEnable(GL_COLOR_MATERIAL);
// Set Material properties to follow glColor values
glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE);
// All materials hereafter have full specular reflectivity
// with a high shine
glMaterialfv(GL_FRONT, GL_SPECULAR,specref);
glMateriali(GL_FRONT, GL_SHININESS,1);
ho infine la funzione che si occupa di disegnare la scena che contiene queste istruzioni:
codice:
...
glLightfv(GL_LIGHT0,GL_POSITION,lightPos);
glLightfv(GL_LIGHT0,GL_SPOT_DIRECTION,spotDir);
...
disegnaLampione(38,2,2);
dove disegnaLampione serve a disegnare una sfera gialla sospesa in aria che dovrebbe emettere luce:
codice:
void disegnaLampione(GLfloat x, GLfloat y, GLfloat z)
{
glPushMatrix();
glTranslatef(x,y,z);
glColor3f(1, 1, 0);
glutSolidSphere(0.2f, 15, 15);
glPopMatrix();
}
credo di non aver capito bene qualcosa... ma cosa??