Commit 32c430ec authored by Sylvain Thery's avatar Sylvain Thery

minor bugs & optim

parent 895926cd
...@@ -27,13 +27,15 @@ ...@@ -27,13 +27,15 @@
#include "Algo/Modelisation/polyhedron.h" #include "Algo/Modelisation/polyhedron.h"
#include "Utils/vbo.h" #include "Utils/vbo.h"
ObjView::ObjView(): ObjView::ObjView():
m_obj(myMap), m_obj(myMap),
m_positionVBO(NULL), m_positionVBO(NULL),
m_normalVBO(NULL), m_normalVBO(NULL),
m_texcoordVBO(NULL), m_texcoordVBO(NULL),
m_shader(NULL), m_shader(NULL),
m_shader2(NULL) m_shader2(NULL),
m_RenderStyle(2)
{} {}
ObjView::~ObjView() ObjView::~ObjView()
...@@ -53,6 +55,27 @@ ObjView::~ObjView() ...@@ -53,6 +55,27 @@ ObjView::~ObjView()
delete m_texcoordVBO; delete m_texcoordVBO;
} }
void ObjView::cb_keyPress(int k)
{
switch(k)
{
case 'm':
m_RenderStyle=0;
break;
case 'c':
m_RenderStyle=1;
break;
case 't':
m_RenderStyle=2;
break;
default:
break;
}
updateGL();
}
void ObjView::cb_initGL() void ObjView::cb_initGL()
{ {
// choose to use GL version 2 // choose to use GL version 2
...@@ -63,12 +86,6 @@ void ObjView::cb_initGL() ...@@ -63,12 +86,6 @@ void ObjView::cb_initGL()
m_texcoordVBO = new Utils::VBO; m_texcoordVBO = new Utils::VBO;
m_normalVBO = new Utils::VBO; m_normalVBO = new Utils::VBO;
// m_shader = new Utils::ShaderSimpleTexture();
// m_shader->setAttributePosition(m_positionVBO);
// m_shader->setAttributeTexCoord(m_texcoordVBO);
// m_shader->setTextureUnit(GL_TEXTURE0);
// registerShader(m_shader);
m_shader2 = new Utils::ShaderPhongTexture(); m_shader2 = new Utils::ShaderPhongTexture();
m_shader2->setAttributePosition(m_positionVBO); m_shader2->setAttributePosition(m_positionVBO);
m_shader2->setAttributeTexCoord(m_texcoordVBO); m_shader2->setAttributeTexCoord(m_texcoordVBO);
...@@ -100,30 +117,61 @@ void ObjView::cb_redraw() ...@@ -100,30 +117,61 @@ void ObjView::cb_redraw()
for (unsigned int i=0; i<nb; ++i) for (unsigned int i=0; i<nb; ++i)
{ {
if (mats[i]->textureDiffuse != NULL) switch(m_RenderStyle)
{
m_shader2->setTexture(mats[i]->textureDiffuse);
m_shader2->setShininess(mats[i]->shininess);
m_shader2->setAmbient(0.8f);
m_shader2->activeTexture();
m_shader2->enableVertexAttribs();
glDrawArrays(GL_TRIANGLES, m_obj.beginIndex(i), m_obj.nbIndices(i));
m_shader2->disableVertexAttribs();
}
else
{ {
Geom::Vec4f v; case 0: // MONO
// v[0] = mats[i]->ambiantColor[0]; v[1] = mats[i]->ambiantColor[1]; v[2] = mats[i]->ambiantColor[2]; v[3] = 0.0f; {
v[0] = 0.5f; v[1] = 0.5f; v[2] = 0.5f; v[3] = 0.0f; Geom::Vec4f v(0.2f,1.0f,0.4f,0.0f); // color here green
m_phongShader->setAmbiant(v) ; m_phongShader->setAmbiant(0.2f*v) ;
v[0] = mats[i]->diffuseColor[0]; v[1] = mats[i]->diffuseColor[1]; v[2] = mats[i]->diffuseColor[2]; v[3] = 0.0f; m_phongShader->setDiffuse(v) ;
m_phongShader->setDiffuse(v) ; // v[0] = 1.0f; v[1] = 1.0f; v[2] = 1.0f; v[3] = 0.0f; // use this for specular effected
v[0] = mats[i]->specularColor[0]; v[1] = mats[i]->specularColor[1]; v[2] = mats[i]->specularColor[2]; v[3] = 0.0f; m_phongShader->setSpecular(v) ;
m_phongShader->setSpecular(v) ; m_phongShader->setShininess(10000.0) ;
m_phongShader->setShininess(mats[i]->shininess) ; m_phongShader->enableVertexAttribs();
m_phongShader->enableVertexAttribs(); glDrawArrays(GL_TRIANGLES, m_obj.beginIndex(i), m_obj.nbIndices(i));
glDrawArrays(GL_TRIANGLES, m_obj.beginIndex(i), m_obj.nbIndices(i)); m_phongShader->disableVertexAttribs();
m_phongShader->disableVertexAttribs(); }
break;
case 1: // COLOR
{
Geom::Vec4f v(mats[i]->diffuseColor[0],mats[i]->diffuseColor[1],mats[i]->diffuseColor[2],0.0f);
m_phongShader->setAmbiant(0.2f*v) ;
m_phongShader->setDiffuse(v) ;
// v[0] = 1.0f; v[1] = 1.0f; v[2] = 1.0f; v[3] = 0.0f; // use this for specular effected
m_phongShader->setSpecular(v) ;
m_phongShader->setShininess(10000.0) ;
m_phongShader->enableVertexAttribs();
glDrawArrays(GL_TRIANGLES, m_obj.beginIndex(i), m_obj.nbIndices(i));
m_phongShader->disableVertexAttribs();
}
default:
{
if (mats[i]->textureDiffuse != NULL)
{
m_shader2->setTexture(mats[i]->textureDiffuse);
m_shader2->setShininess(mats[i]->shininess);
m_shader2->setAmbient(0.8f);
m_shader2->activeTexture();
m_shader2->enableVertexAttribs();
glDrawArrays(GL_TRIANGLES, m_obj.beginIndex(i), m_obj.nbIndices(i));
m_shader2->disableVertexAttribs();
}
else
{
Geom::Vec4f v;
v[0] = 0.5f; v[1] = 0.5f; v[2] = 0.5f; v[3] = 0.0f;
m_phongShader->setAmbiant(v) ;
v[0] = mats[i]->diffuseColor[0]; v[1] = mats[i]->diffuseColor[1]; v[2] = mats[i]->diffuseColor[2]; v[3] = 0.0f;
m_phongShader->setDiffuse(v) ;
v[0] = mats[i]->specularColor[0]; v[1] = mats[i]->specularColor[1]; v[2] = mats[i]->specularColor[2]; v[3] = 0.0f;
m_phongShader->setSpecular(v) ;
m_phongShader->setShininess(mats[i]->shininess) ;
m_phongShader->enableVertexAttribs();
glDrawArrays(GL_TRIANGLES, m_obj.beginIndex(i), m_obj.nbIndices(i));
m_phongShader->disableVertexAttribs();
}
}
} }
} }
} }
......
...@@ -77,6 +77,8 @@ public: ...@@ -77,6 +77,8 @@ public:
Utils::ShaderPhongTexture* m_shader2; Utils::ShaderPhongTexture* m_shader2;
Utils::ShaderPhong* m_phongShader; Utils::ShaderPhong* m_phongShader;
int m_RenderStyle;
ObjView(); ObjView();
~ObjView(); ~ObjView();
...@@ -88,6 +90,9 @@ public: ...@@ -88,6 +90,9 @@ public:
void cb_initGL(); void cb_initGL();
void cb_keyPress(int k);
}; };
#endif #endif
...@@ -174,11 +174,13 @@ void AttributeContainer::clear(bool removeAttrib) ...@@ -174,11 +174,13 @@ void AttributeContainer::clear(bool removeAttrib)
for (std::vector<HoleBlockRef*>::iterator it = m_holesBlocks.begin(); it != m_holesBlocks.end(); ++it) for (std::vector<HoleBlockRef*>::iterator it = m_holesBlocks.begin(); it != m_holesBlocks.end(); ++it)
delete (*it); delete (*it);
std::vector<HoleBlockRef*> bf; { // add bracket just for scope of temporary vectors
m_holesBlocks.swap(bf); std::vector<HoleBlockRef*> bf;
m_holesBlocks.swap(bf);
std::vector<unsigned int> bwf; std::vector<unsigned int> bwf;
m_tableBlocksWithFree.swap(bwf); m_tableBlocksWithFree.swap(bwf);
}
// detruit les données // detruit les données
for (std::vector<AttributeMultiVectorGen*>::iterator it = m_tableAttribs.begin(); it != m_tableAttribs.end(); ++it) for (std::vector<AttributeMultiVectorGen*>::iterator it = m_tableAttribs.begin(); it != m_tableAttribs.end(); ++it)
......
...@@ -185,7 +185,7 @@ void Drawer::callList(float opacity) ...@@ -185,7 +185,7 @@ void Drawer::callList(float opacity)
{ {
if (pp->mode == GL_POINTS) if (pp->mode == GL_POINTS)
glPointSize(pp->width); glPointSize(pp->width);
if ((pp->mode == GL_LINES) || (pp->mode == GL_LINE_LOOP)) if ((pp->mode == GL_LINES) || (pp->mode == GL_LINE_LOOP) || (pp->mode == GL_LINE_STRIP))
glLineWidth(pp->width); glLineWidth(pp->width);
glDrawArrays(pp->mode, pp->begin, pp->nb); glDrawArrays(pp->mode, pp->begin, pp->nb);
} }
...@@ -206,7 +206,7 @@ void Drawer::callSubList(int index, float opacity) ...@@ -206,7 +206,7 @@ void Drawer::callSubList(int index, float opacity)
if (pp->mode == GL_POINTS) if (pp->mode == GL_POINTS)
glPointSize(pp->width); glPointSize(pp->width);
if ((pp->mode == GL_LINES) || (pp->mode == GL_LINE_LOOP)) if ((pp->mode == GL_LINES) || (pp->mode == GL_LINE_LOOP) || (pp->mode == GL_LINE_STRIP))
glLineWidth(pp->width); glLineWidth(pp->width);
glDrawArrays(pp->mode, pp->begin, pp->nb); glDrawArrays(pp->mode, pp->begin, pp->nb);
...@@ -226,7 +226,7 @@ void Drawer::callSubLists(int first, int nb, float opacity) ...@@ -226,7 +226,7 @@ void Drawer::callSubLists(int first, int nb, float opacity)
if (pp->mode == GL_POINTS) if (pp->mode == GL_POINTS)
glPointSize(pp->width); glPointSize(pp->width);
if ((pp->mode == GL_LINES) || (pp->mode == GL_LINE_LOOP)) if ((pp->mode == GL_LINES) || (pp->mode == GL_LINE_LOOP) || (pp->mode == GL_LINE_STRIP))
glLineWidth(pp->width); glLineWidth(pp->width);
glDrawArrays(pp->mode, pp->begin, pp->nb); glDrawArrays(pp->mode, pp->begin, pp->nb);
} }
...@@ -247,7 +247,7 @@ void Drawer::callSubLists(std::vector<int> indices, float opacity) ...@@ -247,7 +247,7 @@ void Drawer::callSubLists(std::vector<int> indices, float opacity)
if (pp->mode == GL_POINTS) if (pp->mode == GL_POINTS)
glPointSize(pp->width); glPointSize(pp->width);
if ((pp->mode == GL_LINES) || (pp->mode == GL_LINE_LOOP)) if ((pp->mode == GL_LINES) || (pp->mode == GL_LINE_LOOP) || (pp->mode == GL_LINE_STRIP))
glLineWidth(pp->width); glLineWidth(pp->width);
glDrawArrays(pp->mode, pp->begin, pp->nb); glDrawArrays(pp->mode, pp->begin, pp->nb);
} }
......
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