PDA

View Full Version : indirect light setting



Oleg
03-02-2000, 09:32 PM
I tried using a class that controls the light properties (of different source - up to 7 ) : and it makes no effect :
the h file:

#ifndef LIGHTPROP_H
#define LIGHTPROP_H

#include "Defs.h"

class CLightProp
{
protected:
int SpotNum;
GLint DiffuseColor[3];
GLint SpecularColor[3];
GLfloat Position[3];
GLfloat Direction[3];
bool IsOn;
static Counter;
public:
CLightProp(){IsOn = false;SpotNum = Counter++;}// All the other values are initialized fine
~CLightProp(){};

void TurnOn()
{IsOn = true ; glEnable(SpotNum);}
void TurnOff()
{IsOn = false ; glDisable(SpotNum);}

void SetDiffuseColor(GLint R,GLint G,GLint B)
{DiffuseColor[0] = R ;
DiffuseColor[1] = G ;
DiffuseColor[2] = B ;}
void SetSpecularColor(GLint R,GLint G,GLint B)
{SpecularColor[0] = R ;
SpecularColor[1] = G ;
SpecularColor[2] = B ;}

void SetPosition(GLfloat Xcoord,GLfloat Ycoord,GLfloat Zcoord)
{Position[X] = Xcoord ;
Position[Y] = Ycoord ;
Position[Z] = Zcoord ;}

void SetDirection(GLfloat Xcoord,GLfloat Ycoord,GLfloat Zcoord)
{Direction[X] = Xcoord ;
Direction[Y] = Ycoord ;
Direction[Z] = Zcoord ; }

void SetLight(); // Changes the light_(SpotNum) with the members last defind

int GetNum()const{return SpotNum;}
bool IsActive()const{return IsOn;}
const GLint* GetDiffuseColor()const{return DiffuseColor;}
const GLint* GetSpecularColor()const{return SpecularColor;}
const GLfloat* GetPosition()const{return Position;}
const GLfloat* GetDirection()const{return Direction;}

};

#endif LIGHTPROP_H

the cpp file :

#include "LightProp.h"

int CLightProp::Counter = GL_LIGHT1;

void CLightProp::SetLight()
{
// Setting the colors
glLightiv(SpotNum,GL_DIFFUSE,DiffuseColor);
glLightiv(SpotNum,GL_SPECULAR,SpecularColor);

// Setting position
glLightfv(SpotNum,GL_POSITION,Position);

// Setting specular light properties
glLightf(SpotNum,GL_SPOT_CUTOFF,45.0f);
glLightfv(SpotNum,GL_SPOT_DIRECTION ,Direction);
glLightf(SpotNum,GL_SPOT_EXPONENT,100.0f);

if(IsOn)
{
glEnable(SpotNum);
glEnable(GL_COLOR_MATERIAL);
glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE);
glMaterialiv(GL_FRONT_AND_BACK,GL_DIFFUSE,DiffuseC olor);

// The specularity of the balls
glMaterialiv(GL_FRONT, GL_SPECULAR,SpecularColor);
glMateriali(GL_FRONT, GL_SHININESS,128);
}
else
glDisable(SpotNum);
}


Does anyone has an idea what to do ?