Hi Frank,
I’ve been using this very simple light class I put together. It allows me to create, destroy and modify GL lighting as needed. This is my “first” attempt at abastracting a single facet of OpenGL.
“parent”, passed thru the overloaded constructor is optional. I could have just a easily passed the current light index in. But its nice to have a pointer to the Almighty creator laying around.
If your planning on wrapping the entire API, email me when you get done :P. Id like to see it. Ive seen a couple attempts at this, but the interfaces werent much of an improvement over GLs. Not that my attempt at abstraction is any better
Good luck, & have fun
// Light.h: interface for the CLight class.
#define M_BASE 0x4000
class CLight : public CObject
{
public:
CLight();
CLight(CProBotDoc* parent);
virtual ~CLight();
void GetPosition(GLdouble* position);
void GetAmbiance(GLfloat* ambiance);
void GetDiffuse(GLfloat* diffuse);
void GetSpecular(GLfloat* specular);
void SetPosition(GLdouble* position);
void SetSpecular(GLfloat* specular);
void SetDiffuse(GLfloat* diffuse);
void SetAmbiance(GLfloat* ambiance);
void ON(BOOL state = TRUE);
void SetDefault();
CProBotDoc* m_parent;
//Inline
public:
CString GetName(){return m_name;}
int GetIndex(){return m_indexID;}
void SetName(CString name){m_name = name;}
protected:
GLfloat m_ambiance[4];
GLfloat m_diffuse[4];
GLfloat m_specular[4];
GLfloat m_position[4];
int m_indexID;
CString m_name;
BOOL m_ON;
private:
void SetIndexID();
};
// Light.cpp: implementation of the CLight class.
#include “Light.h”
#include “ProBotDoc.h”
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=FILE;
#define new DEBUG_NEW
#endif
// Construction/Destruction
CLight::CLight()
{
}
CLight::~CLight()
{
}
CLight::CLight(CProBotDoc *parent)
{
//Set default Lighting
m_parent = parent;
SetIndexID();
SetDefault();
}
void CLight::GetSpecular(GLfloat *specular)
{
int i = 0;
while (i++ < 4)
specular[i] = m_specular[i];
}
void CLight::GetDiffuse(GLfloat *diffuse)
{
int i = 0;
while (i++ < 4)
diffuse[i] = m_diffuse[i];
}
void CLight::GetAmbiance(GLfloat *ambiance)
{
int i = 0;
while (i++ < 4)
ambiance[i] = m_ambiance[i];
}
void CLight::GetPosition(GLdouble *position)
{
int i = 0;
while (i++ < 4)
position[i] = m_position[i];
}
void CLight::SetDefault()
{
m_ON = TRUE;
m_ambiance[0] = .01;
m_ambiance[1] = .01;
m_ambiance[2] = .01;
m_ambiance[3] = .01;
m_diffuse[0] = .5;
m_diffuse[1] = .5;
m_diffuse[2] = .5;
m_diffuse[3] = 0;
m_specular[0] = .1;
m_specular[1] = .1;
m_specular[2] = .1;
m_specular[3] = 0;
m_position[0] = 0;
m_position[1] = 0;
m_position[2] = 100.;
m_position[3] = 1;
glLightfv(M_BASE + m_indexID, GL_AMBIENT, m_ambiance);
glLightfv(M_BASE + m_indexID, GL_DIFFUSE, m_diffuse);
glLightfv(M_BASE + m_indexID, GL_SPECULAR, m_specular);
glLightfv(M_BASE + m_indexID, GL_POSITION, m_position);
glEnable(M_BASE + m_indexID);
}
void CLight::SetIndexID()
{
CString tmp;
m_indexID = m_parent->GetNumLights() + 1;
tmp.Format(“Light%d”, m_indexID);
m_name = tmp;
}
void CLight::SetAmbiance(GLfloat *ambiance)
{
int i = 0;
while (i++ < 4)
{
m_ambiance[i] = ambiance[i];
}
glLightfv(M_BASE + m_indexID, GL_AMBIENT, m_ambiance);
}
void CLight::SetDiffuse(GLfloat *diffuse)
{
int i = 0;
while (i++ < 4)
{
m_diffuse[i] = diffuse[i];
}
glLightfv(M_BASE + m_indexID, GL_DIFFUSE, m_diffuse);
}
void CLight::SetSpecular(GLfloat *specular)
{
int i = 0;
while (i++ < 4)
{
m_specular[i] = specular[i];
}
glLightfv(M_BASE + m_indexID, GL_SPECULAR, m_specular);
}
void CLight::SetPosition(GLdouble *position)
{
int i = 0;
while (i++ < 4)
{
position[i] = m_position[i];
}
glLightfv(M_BASE + m_indexID, GL_POSITION, m_position);
}
void CLight::ON(BOOL state)
{
if (state)
glEnable(M_BASE + m_indexID);
else
glDisable(M_BASE + m_indexID);
}