Commit 28f10a00 authored by Martin Schultz's avatar Martin Schultz
Browse files

Use ACG Render calls to render primitives instead of using glutCalls.

TODO: Teapot and Torus, rest should be working
parent 3e089065
......@@ -176,28 +176,26 @@ void
GlutPrimitiveNode::
draw(GLState& _state, const DrawModes::DrawMode& _drawMode)
{
float backupColorDiffuse[4];
float backupColorAmbient[4];
Vec4f backupColorDiffuse;
Vec4f backupColorAmbient;
if ( setColor_ ) {
glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE);
glGetFloatv(GL_CURRENT_COLOR,backupColorDiffuse);
glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT);
glGetFloatv(GL_CURRENT_COLOR,backupColorAmbient);
backupColorDiffuse = _state.diffuse_color();
backupColorAmbient = _state.ambient_color();
}
for (size_t i = 0; i < primitives_.size(); ++i)
{
glPushMatrix();
glTranslatef(primitives_[i].position[0], primitives_[i].position[1], primitives_[i].position[2]);
_state.push_modelview_matrix();
_state.translate(primitives_[i].position[0], primitives_[i].position[1], primitives_[i].position[2]);
if (_drawMode & DrawModes::POINTS)
{
if(setColor_)
_state.set_color(primitives_[i].color);
ACG::GLState::disable(GL_LIGHTING);
ACG::GLState::shadeModel(GL_FLAT);
glPolygonMode(GL_FRONT_AND_BACK, GL_POINT);
draw_obj(i);
draw_obj(_state, i);
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
}
......@@ -207,7 +205,8 @@ draw(GLState& _state, const DrawModes::DrawMode& _drawMode)
ACG::GLState::disable(GL_LIGHTING);
ACG::GLState::shadeModel(GL_FLAT);
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
draw_obj(i);
_state.set_color(primitives_[i].color);
draw_obj(_state, i);
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
}
......@@ -218,11 +217,12 @@ draw(GLState& _state, const DrawModes::DrawMode& _drawMode)
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
if ( setColor_ ) {
glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
glColor(primitives_[i].color);
_state.set_diffuse_color(primitives_[i].color);
_state.set_ambient_color(primitives_[i].color);
_state.set_color(primitives_[i].color);
}
draw_obj(i);
draw_obj(_state, i);
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
}
......@@ -234,15 +234,18 @@ draw(GLState& _state, const DrawModes::DrawMode& _drawMode)
ACG::GLState::disable(GL_LIGHTING);
ACG::GLState::shadeModel(GL_FLAT);
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
glColor(_state.clear_color());
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
_state.set_color(_state.clear_color());
ACG::GLState::depthRange(0.01, 1.0);
draw_obj(i);
draw_obj(_state, i);
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
glColor(base_color_backup);
if(setColor_)
_state.set_color(primitives_[i].color);
else
_state.set_color(base_color_backup);
ACG::GLState::depthRange(0.0, 1.0);
draw_obj(i);
draw_obj(_state, i);
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
}
......@@ -255,11 +258,12 @@ draw(GLState& _state, const DrawModes::DrawMode& _drawMode)
ACG::GLState::shadeModel(GL_FLAT);
if ( setColor_ ) {
glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
glColor(primitives_[i].color);
_state.set_diffuse_color(primitives_[i].color);
_state.set_ambient_color(primitives_[i].color);
_state.set_color(primitives_[i].color);
}
draw_obj(i);
draw_obj(_state, i);
}
......@@ -270,19 +274,22 @@ draw(GLState& _state, const DrawModes::DrawMode& _drawMode)
ACG::GLState::shadeModel(GL_SMOOTH);
if ( setColor_ ) {
glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
glColor(primitives_[i].color);
_state.set_diffuse_color(primitives_[i].color);
_state.set_ambient_color(primitives_[i].color);
_state.set_color(primitives_[i].color);
//not sure if ambient and diffuse color have to be set here.
//the original call was:
//glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
//glColor(primitives_[i].color);
}
draw_obj(i);
draw_obj(_state, i);
}
glPopMatrix();
_state.pop_modelview_matrix();
if ( setColor_ ) {
glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE);
glColor4fv(backupColorDiffuse);
glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT);
glColor4fv(backupColorAmbient);
_state.set_diffuse_color(backupColorDiffuse);
_state.set_ambient_color(backupColorAmbient);
}
} // end of primitives iter
}
......@@ -301,7 +308,7 @@ add_primitive(GlutPrimitiveType _type, Vec3d _pos, Vec3d _axis, ACG::Vec4f _colo
//----------------------------------------------------------------------------
void
GlutPrimitiveNode::draw_obj(size_t _idx) const
GlutPrimitiveNode::draw_obj(GLState& _state, size_t _idx) const
{
if ( _idx >= primitives_.size()) // range check
return;
......@@ -311,8 +318,7 @@ GlutPrimitiveNode::draw_obj(size_t _idx) const
if (size > 1e-10)
{
glPushMatrix();
_state.push_modelview_matrix();
Vec3d direction = axis;
Vec3d z_axis(0,0,1);
Vec3d rot_normal;
......@@ -324,51 +330,56 @@ GlutPrimitiveNode::draw_obj(size_t _idx) const
if (fabs(rot_angle) > 0.0001 && fabs(180 - rot_angle) > 0.0001)
glRotatef(rot_angle,rot_normal[0], rot_normal[1], rot_normal[2]);
{
_state.rotate(rot_angle,rot_normal[0], rot_normal[1], rot_normal[2]);
}
else
glRotatef(rot_angle,1,0,0);
{
_state.rotate(rot_angle,1,0,0);
}
switch (primitives_[_idx].type)
{
case CONE:
glutSolidCone(primitives_[_idx].size, primitives_[_idx].innersize, primitives_[_idx].slices, primitives_[_idx].stacks);
ACG::GLCone(primitives_[_idx].slices, primitives_[_idx].stacks, primitives_[_idx].size, 0.0f, true, true).draw(_state, primitives_[_idx].innersize);
break;
case CUBE:
glutSolidCube(primitives_[_idx].size);
case CUBE:
_state.scale(primitives_[_idx].size);
ACG::GLBox().draw_primitive();
break;
case DODECAHEDRON:
glutSolidDodecahedron();
ACG::GLDodecahedron().draw_primitive();
break;
case ICOSAHEDRON:
glutSolidIcosahedron();
ACG::GLIcosahedron().draw_primitive();
break;
case OCTAHEDRON:
glutSolidOctahedron();
ACG::GLOctahedron().draw_primitive();
break;
case SPHERE:
glutSolidSphere(primitives_[_idx].size, primitives_[_idx].slices, primitives_[_idx].stacks);
ACG::GLSphere(primitives_[_idx].slices, primitives_[_idx].stacks).draw(_state,primitives_[_idx].size);
break;
case TEAPOT:
glutSolidTeapot(primitives_[_idx].size);
break;
case TETRAHEDRON:
glutSolidTetrahedron();
case TETRAHEDRON:
ACG::GLTetrahedron().draw_primitive();
break;
case TORUS:
glutSolidTorus(primitives_[_idx].innersize, primitives_[_idx].size, primitives_[_idx].slices, primitives_[_idx].stacks);
ACG::GLDisk(primitives_[_idx].slices,primitives_[_idx].stacks, primitives_[_idx].innersize, primitives_[_idx].size).draw(_state, Vec3f(0.0f),(Vec3f)primitives_[_idx].axis);
//glutSolidTorus(primitives_[_idx].innersize, primitives_[_idx].size, primitives_[_idx].slices, primitives_[_idx].stacks);
break;
}
glPopMatrix();
_state.pop_modelview_matrix();
}
}
......@@ -395,7 +406,7 @@ pick(GLState& _state , PickTarget _target)
_state.pick_set_name(i);
glPushMatrix();
glTranslatef(primitives_[i].position[0], primitives_[i].position[1], primitives_[i].position[2]);
draw_obj(i);
draw_obj(_state, i);
glPopMatrix();
}
break;
......
......@@ -219,7 +219,7 @@ public:
/// drawing the primitive
void draw(GLState& _state, const DrawModes::DrawMode& _drawMode);
void draw_obj(size_t _idx) const;
void draw_obj(GLState& _state, size_t _idx) const;
/// picking
void pick(GLState& _state, PickTarget _target);
......
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