Commit a9000180 authored by Jan Möbius's avatar Jan Möbius
Browse files

First try to get the new renderer working with a sphere.

Color still not working correctly

refs #1286

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@15836 383ad7c9-94d9-4d36-a494-682f7c89f535
parent c5ef4a34
......@@ -53,7 +53,11 @@
//== INCLUDES =================================================================
#include "GlutPrimitiveNode.hh"
#include "../GL/gl.hh"
#include <ACG/GL/gl.hh>
#include <ACG/GL/IRenderer.hh>
#include <ACG/Scenegraph/MaterialNode.hh>
//== NAMESPACES ===============================================================
......@@ -64,6 +68,35 @@ namespace SceneGraph {
//== IMPLEMENTATION ==========================================================
GlutPrimitiveNode::GlutPrimitiveNode( BaseNode* _parent,
std::string _name )
: BaseNode(_parent, _name),
setColor_(true)
{
const int slices = 20;
const int stacks = 20;
sphere_ = new ACG::GLSphere(slices,stacks);
};
//----------------------------------------------------------------------------
GlutPrimitiveNode::GlutPrimitiveNode(GlutPrimitiveType _type,
BaseNode* _parent,
std::string _name) :
BaseNode(_parent, _name),
setColor_(true)
{
const int slices = 20;
const int stacks = 20;
// add a single primitive of the given type
Primitive p(_type);
primitives_.push_back(p);
sphere_ = new ACG::GLSphere(slices, stacks);
}
void
GlutPrimitiveNode::
set_position(const Vec3d& _p, int _idx)
......@@ -353,6 +386,61 @@ pick(GLState& _state , PickTarget _target)
}
}
//----------------------------------------------------------------------------
void
GlutPrimitiveNode::
getRenderObjects(IRenderer* _renderer, GLState& _state , const DrawModes::DrawMode& _drawMode , const Material* _mat) {
// TODO: Color is incorrect!
// init base render object
RenderObject ro;
memset(&ro, 0, sizeof(RenderObject));
ro.initFromState(&_state);
ro.setMaterial(_mat);
for (int i = 0; i < (int)primitives_.size(); ++i)
{
// Set the right position
_state.push_modelview_matrix();
_state.translate(primitives_[i].position);
ro.modelview = _state.modelview();
_state.pop_modelview_matrix();
Material localMaterial;
localMaterial.color(primitives_[i].color);
localMaterial.ambientColor(primitives_[i].color);
localMaterial.diffuseColor(primitives_[i].color);
ro.setMaterial(&localMaterial);
switch (primitives_[i].type) {
case SPHERE:
// Sphere
ro.debugName = "glutprimitive.sphere";
//ro.emissive = Vec3f(1.0f, 0.0f, 0.0f);
sphere_->addToRenderer(_renderer, &ro, primitives_[i].size);
break;
default:
// TODO: The other glut primitives are not yet supported by the advanced renderers
break;
}
}
}
//=============================================================================
} // namespace SceneGraph
......
......@@ -60,6 +60,8 @@
#include "DrawModes.hh"
#include <string>
#include <ACG/GL/GLPrimitives.hh>
//== NAMESPACES ===============================================================
......@@ -165,22 +167,12 @@ public:
GlutPrimitiveNode( BaseNode* _parent=0,
std::string _name="<GlutPrimitive>" )
: BaseNode(_parent, _name),
setColor_(true)
{};
std::string _name="<GlutPrimitive>" );
GlutPrimitiveNode( GlutPrimitiveType _type,
BaseNode* _parent=0,
std::string _name="<GlutPrimitive>" )
: BaseNode(_parent, _name),
setColor_(true)
{
// add a single primitive of the given type
Primitive p(_type);
primitives_.push_back(p);
}
std::string _name="<GlutPrimitive>" );
/// destructor
......@@ -225,12 +217,24 @@ public:
*/
void setColorInternal(bool _set) { setColor_ = _set; };
/** \brief Add the objects to the given renderer
*
* @param _renderer The renderer which will be used. Add your geometry into this class
* @param _state The current GL State when this object is called
* @param _drawMode The active draw mode
* @param _mat Current material
*/
void getRenderObjects(IRenderer* _renderer, GLState& _state , const DrawModes::DrawMode& _drawMode , const Material* _mat);
private:
std::vector<Primitive> primitives_;
bool setColor_;
// Sphere rendering
ACG::GLSphere* sphere_;
};
......
Markdown is supported
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