Skip to content
Snippets Groups Projects
Commit aaa5ac8d authored by Christophe Geuzaine's avatar Christophe Geuzaine
Browse files

lighting

parent 6c6eebe0
No related branches found
No related tags found
No related merge requests found
...@@ -628,7 +628,8 @@ void drawContext::drawView() ...@@ -628,7 +628,8 @@ void drawContext::drawView()
OrthofFromGModel(); OrthofFromGModel();
glMatrixMode(GL_MODELVIEW); glMatrixMode(GL_MODELVIEW);
// fill the background
// draw the background
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
if(CTX::instance()->bgGradient){ if(CTX::instance()->bgGradient){
glPushMatrix(); glPushMatrix();
...@@ -656,10 +657,73 @@ void drawContext::drawView() ...@@ -656,10 +657,73 @@ void drawContext::drawView()
} }
checkGlError("Draw background"); checkGlError("Draw background");
// init lights
glPushMatrix();
glLoadIdentity(); glLoadIdentity();
glScalef(_scale[0], _scale[1], _scale[2]); glScalef(_scale[0], _scale[1], _scale[2]);
glTranslatef(_translate[0], _translate[1], _translate[2]); glTranslatef(_translate[0], _translate[1], _translate[2]);
for(int i = 0; i < 6; i++) {
if(CTX::instance()->light[i]) {
GLfloat position[4] = {
(GLfloat)CTX::instance()->lightPosition[i][0],
(GLfloat)CTX::instance()->lightPosition[i][1],
(GLfloat)CTX::instance()->lightPosition[i][2],
(GLfloat)CTX::instance()->lightPosition[i][3]
};
glLightfv((GLenum)(GL_LIGHT0 + i), GL_POSITION, position);
GLfloat r = (GLfloat)(CTX::instance()->unpackRed
(CTX::instance()->color.ambientLight[i]) / 255.);
GLfloat g = (GLfloat)(CTX::instance()->unpackGreen
(CTX::instance()->color.ambientLight[i]) / 255.);
GLfloat b = (GLfloat)(CTX::instance()->unpackBlue
(CTX::instance()->color.ambientLight[i]) / 255.);
GLfloat ambient[4] = {r, g, b, 1.0F};
glLightfv((GLenum)(GL_LIGHT0 + i), GL_AMBIENT, ambient);
r = (GLfloat)(CTX::instance()->unpackRed
(CTX::instance()->color.diffuseLight[i]) / 255.);
g = (GLfloat)(CTX::instance()->unpackGreen
(CTX::instance()->color.diffuseLight[i]) / 255.);
b = (GLfloat)(CTX::instance()->unpackBlue
(CTX::instance()->color.diffuseLight[i]) / 255.);
GLfloat diffuse[4] = {r, g, b, 1.0F};
glLightfv((GLenum)(GL_LIGHT0 + i), GL_DIFFUSE, diffuse);
r = (GLfloat)(CTX::instance()->unpackRed
(CTX::instance()->color.specularLight[i]) / 255.);
g = (GLfloat)(CTX::instance()->unpackGreen
(CTX::instance()->color.specularLight[i]) / 255.);
b = (GLfloat)(CTX::instance()->unpackBlue
(CTX::instance()->color.specularLight[i]) / 255.);
GLfloat specular[4] = {r, g, b, 1.0F};
glLightfv((GLenum)(GL_LIGHT0 + i), GL_SPECULAR, specular);
glEnable((GLenum)(GL_LIGHT0 + i));
}
else{
glDisable((GLenum)(GL_LIGHT0 + i));
}
}
glPopMatrix();
// ambient and diffuse material colors track glColor automatically
//glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
glEnable(GL_COLOR_MATERIAL);
// "white"-only specular material reflection color
GLfloat spec[4] = {(GLfloat)CTX::instance()->shine,
(GLfloat)CTX::instance()->shine,
(GLfloat)CTX::instance()->shine, 1.0F};
glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, spec);
// specular exponent in [0,128] (larger means more "focused"
// reflection)
glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS,
(GLfloat)CTX::instance()->shineExponent);
glShadeModel(GL_SMOOTH);
glEnable(GL_RESCALE_NORMAL);
glLightModelf(GL_LIGHT_MODEL_TWO_SIDE, 1.);
glDisable(GL_LIGHTING);
checkGlError("Initialize lights");
// init position
glLoadIdentity();
glScalef(_scale[0], _scale[1], _scale[2]);
glTranslatef(_translate[0], _translate[1], _translate[2]);
if(CTX::instance()->rotationCenterCg) if(CTX::instance()->rotationCenterCg)
glTranslatef(CTX::instance()->cg[0], glTranslatef(CTX::instance()->cg[0],
CTX::instance()->cg[1], CTX::instance()->cg[1],
...@@ -668,10 +732,8 @@ void drawContext::drawView() ...@@ -668,10 +732,8 @@ void drawContext::drawView()
glTranslatef(CTX::instance()->rotationCenter[0], glTranslatef(CTX::instance()->rotationCenter[0],
CTX::instance()->rotationCenter[1], CTX::instance()->rotationCenter[1],
CTX::instance()->rotationCenter[2]); CTX::instance()->rotationCenter[2]);
buildRotationMatrix(); buildRotationMatrix();
glMultMatrixf(_rotatef); glMultMatrixf(_rotatef);
if(CTX::instance()->rotationCenterCg) if(CTX::instance()->rotationCenterCg)
glTranslatef(-CTX::instance()->cg[0], glTranslatef(-CTX::instance()->cg[0],
-CTX::instance()->cg[1], -CTX::instance()->cg[1],
...@@ -680,24 +742,19 @@ void drawContext::drawView() ...@@ -680,24 +742,19 @@ void drawContext::drawView()
glTranslatef(-CTX::instance()->rotationCenter[0], glTranslatef(-CTX::instance()->rotationCenter[0],
-CTX::instance()->rotationCenter[1], -CTX::instance()->rotationCenter[1],
-CTX::instance()->rotationCenter[2]); -CTX::instance()->rotationCenter[2]);
checkGlError("Initialize position"); checkGlError("Initialize position");
// draw everything
glEnable(GL_DEPTH_TEST); glEnable(GL_DEPTH_TEST);
drawMesh(); checkGlError("Draw mesh");
drawMesh(); drawGeom(); checkGlError("Draw geometry");
checkGlError("Draw mesh"); glEnable(GL_LIGHTING);
drawGeom(); drawPost(); checkGlError("Draw post-pro");
checkGlError("Draw geometry"); glDisable(GL_LIGHTING);
drawPost();
checkGlError("Draw post-pro");
glDisable(GL_DEPTH_TEST); glDisable(GL_DEPTH_TEST);
drawScale(); drawScale(); checkGlError("Draw scales");
checkGlError("Draw scales"); drawAxes(); checkGlError("Draw axes");
drawAxes(); drawText2d(); checkGlError("Draw text2d");
checkGlError("Draw axes");
drawText2d();
checkGlError("Draw text2d");
} }
std::vector<std::string> commandToVector(const std::string cmd) std::vector<std::string> commandToVector(const std::string cmd)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment