00001
00008 #include "light.h"
00009
00014 TLight::TLight()
00015 {
00016 light = 0;
00017 pos.LoadIdentity();
00018 shadow = false;
00019 fbo = 0;
00020 }
00021
00026 TLight::~TLight()
00027 {
00029 if(fbo != 0)
00030 glDeleteFramebuffers(1, &fbo);
00031 }
00032
00039 void TLight::ChangeColor(GLint component, TVector color)
00040 {
00041 switch(component)
00042 {
00043 case AMBIENT:
00044 glLightfv(light + GL_LIGHT0, GL_AMBIENT, color);
00045 ambient = color;
00046 break;
00047 case DIFFUSE:
00048 glLightfv(light + GL_LIGHT0, GL_DIFFUSE, color);
00049 diffuse = color;
00050 break;
00051 case SPECULAR:
00052 glLightfv(light + GL_LIGHT0, GL_SPECULAR, color);
00053 specular = color;
00054 break;
00055 };
00056 }
00057
00058
00068 void TLight::Set(GLint lights, TVector amb, TVector diff, TVector spec, TVector lpos, float _radius)
00069 {
00070 light = lights;
00071
00072
00073 ambient = amb;
00074 diffuse = diff;
00075 specular = spec;
00076 pos = lpos;
00077 radius = _radius;
00078
00079 glLightfv(light + GL_LIGHT0, GL_AMBIENT, amb);
00080 glLightfv(light + GL_LIGHT0, GL_DIFFUSE, diff);
00081 glLightfv(light + GL_LIGHT0, GL_SPECULAR, spec);
00082 glLightfv(light + GL_LIGHT0, GL_POSITION,lpos);
00083
00084
00085 q = gluNewQuadric();
00086 gluQuadricNormals(q, GLU_SMOOTH);
00087
00088 shadow = false;
00089 }
00090
00091
00092
00098 void TLight::DrawLight(TMatrix &transformMatrix)
00099 {
00100 glPushMatrix();
00101 glLoadMatrixf(transformMatrix);
00102 glTranslatef(pos.x,pos.y,pos.z);
00103 glUseProgram(0);
00104 glBindTexture(GL_TEXTURE_2D,0);
00105 glColor3f(diffuse.x,diffuse.y,diffuse.z);
00106 gluSphere(q,0.5f,8,8);
00107 glPopMatrix();
00108 }
00109
00117 void TLight::SetShadow(GLint _shadow_size, GLfloat _shadow_intensity, bool _shadow)
00118 {
00119
00120 shadow = _shadow;
00121 shadow_size = _shadow_size;
00122 shadow_intensity = _shadow_intensity;
00123
00125 biasMatrix = TMatrix(0.5f, 0.0f, 0.0f, 0.0f,
00126 0.0f, 0.5f, 0.0f, 0.0f,
00127 0.0f, 0.0f, 0.5f, 0.0f,
00128 0.5f, 0.5f, 0.5f, 1.0f);
00129 }
00130
00136 string TLight::GetShadowCache()
00137 {
00138 stringstream shad_cache_name;
00139 shad_cache_name<<"shadow"<<light;
00140 return shad_cache_name.str();
00141 }