Commit a5b49c4c authored by Mike Kremer's avatar Mike Kremer
Browse files

A light source now requests a GL light id each time it is rendered and frees...

A light source now requests a GL light id each time it is rendered and frees it after the rendering.

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@9044 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 2826905d
......@@ -200,21 +200,17 @@ float LightSource::quadraticAttenuation() {
LightNode::LightNode( BaseNode* _parent,
const std::string& _name)
: BaseNode(_parent, _name),
lightId_(0),
visualize_(false) {
visualize_(false),
lightId_(GL_INVALID_ENUM) {
if(lightSourceHandle == 0) {
lightSourceHandle = new LightSourceHandle();
}
lightId_ = lightSourceHandle->getLight(this);
}
//----------------------------------------------------------------------------
LightNode::~LightNode() {
lightSourceHandle->removeLight(this);
}
//----------------------------------------------------------------------------
......@@ -237,17 +233,36 @@ void LightNode::draw(GLState& _state, DrawModes::DrawMode /*_drawMode*/) {
ACG::Vec3d p = light_.position();
ACG::Vec4f c = light_.ambientColor();
// Backup variables
ACG::Vec4f base_color_backup;
GLboolean lighting_backup;
GLUquadricObj* quadric = gluNewQuadric();
// Origin
_state.push_modelview_matrix ();
//_state.reset_modelview();
_state.translate(p[0], p[1], p[2]);
GLUquadricObj* quadric = gluNewQuadric();
// Set lighting
glGetBooleanv(GL_LIGHTING, &lighting_backup);
glDisable(GL_LIGHTING);
// Set color
base_color_backup = _state.base_color();
_state.set_base_color(c);
glColor3f(c[0], c[1], c[2]);
gluSphere( quadric, light_.radius(), 10, 10 );
// TODO: Visualize vieweing direction
// TODO: Visualize viewing direction
// Undo state changes
// Color
_state.set_base_color(base_color_backup);
// Lighting
if(lighting_backup) glEnable(GL_LIGHTING);
gluDeleteQuadric(quadric);
......@@ -258,30 +273,35 @@ void LightNode::draw(GLState& _state, DrawModes::DrawMode /*_drawMode*/) {
void LightNode::enter(GLState& _state, DrawModes::DrawMode /* _drawmode */ )
{
// Return if we don't have a valid light source
if(lightId_ == GL_INVALID_ENUM || !light_.enabled()) return;
/// transfer GL-preferences to lightSave_
getParameters(lightId_, lightSave_);
if(visualize_) return;
// Get light id
lightId_ = lightSourceHandle->getLight(this);
// Return if we don't have a valid light source
if(lightId_ == GL_INVALID_ENUM) return;
/// transfer GL-preferences to lightSave_
getParameters(lightId_, lightSave_);
// save old light
lightSave_.enabled_ = glIsEnabled(lightId_);
if(light_.enabled_ ) {
// correct Position for fixed Lights
if(light_.fixedPosition_) {
light_.realPosition_ = _state.inverse_modelview() * light_.position_;
// std::cerr << "New Light pos :" << _state.inverse_modelview().transform_vector(light_.position) << std::endl;
// save old light
lightSave_.enabled_ = glIsEnabled(lightId_);
if(light_.enabled_ ) {
// correct Position for fixed Lights
if(light_.fixedPosition_) {
light_.realPosition_ = _state.inverse_modelview() * light_.position_;
//std::cerr << "New Light pos :" << _state.inverse_modelview().transform_vector(light_.position) << std::endl;
} else {
light_.realPosition_ = light_.position_;
//std::cerr << "New Light pos :" << light_.position << std::endl;
}
glEnable(lightId_);
setParameters(lightId_, light_);
} else {
light_.realPosition_ = light_.position_;
// std::cerr << "New Light pos :" << light_.position << std::endl;
glDisable(lightId_);
}
glEnable(lightId_);
setParameters(lightId_, light_);
} else
glDisable(lightId_);
}
......@@ -290,16 +310,22 @@ void LightNode::enter(GLState& _state, DrawModes::DrawMode /* _drawmode */ )
void LightNode::leave(GLState& /* _state */ , DrawModes::DrawMode /* _drawmode*/ )
{
// Return if we don't have a valid light source
if(lightId_ == GL_INVALID_ENUM || !light_.enabled()) return;
if(visualize_) return;
// Return if we don't have a valid light source
if(lightId_ == GL_INVALID_ENUM) return;
// restore old enabled light
if(lightSave_.enabled_)
{
glEnable(lightId_);
setParameters(lightId_, lightSave_);
}
else glDisable(lightId_);
// restore old enabled light
if(lightSave_.enabled_) {
glEnable(lightId_);
setParameters(lightId_, lightSave_);
}
else {
glDisable(lightId_);
}
// Free light id
lightSourceHandle->removeLight(this);
}
//----------------------------------------------------------------------------
......
......@@ -273,8 +273,6 @@ private:
private:
GLenum lightId_;
/// store LightSources of this node
LightSource light_;
......@@ -283,6 +281,9 @@ private:
/// Indicates whether light node should be visualized or not
bool visualize_;
/// Internal light id
GLenum lightId_;
};
/**
......
......@@ -110,9 +110,8 @@ void LightObject::init(LightNode* _light, LightNode* _lightVis) {
PluginFunctions::addGlobalStatusNode(lightNode_);
lightNodeVis_ = new LightNode( materialNode() , "LightNode Visualization");
lightNodeVis_->show();
lightNodeVis_->visualize(true);
lightNodeVis_->show();
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment