Commit c440dbda authored by Thibault Soucarre's avatar Thibault Soucarre

States shaded again, using a float by state

parent b965c6fd
......@@ -198,7 +198,7 @@ void Render_alternate::paintGL(){
glDrawArrays(GL_QUADS, 0, _containers.getNbVertex());
_containers.unlock();
_modelview = tmp;
//glUseProgram(0);
glUseProgram(0);
/*drawing states*/
_modelview = glm::translate(_modelview, glm::vec3(_default_entity_x_translate - _x_state_translate, _ruler_y + _ruler_height - _y_state_translate, _z_state));
_modelview = glm::scale(_modelview, glm::vec3(_x_state_scale, _y_state_scale, 1));
......@@ -206,6 +206,7 @@ void Render_alternate::paintGL(){
std::map<const EntityValue*, Vbo*>::iterator it_state;
it_state = _states.begin();
while(it_state!=_states.end()){
//std::cout << "drawing states" << std::endl;
Shader *s = _states_shaders[it_state->first];
glUseProgram(s->getProgramID());
//glUniform1i(glGetUniformLocation(s->getProgramID(), "i"), 0);
......@@ -673,10 +674,10 @@ void Render_alternate::draw_quad(Element_pos x, Element_pos y, Element_pos z, El
}
else if(_draw_states){
offset_x = -_default_entity_x_translate;
_current->add(x+offset_x , y+offset_y);// , _r, _g, _b);
_current->add(x+offset_x+w, y+offset_y);// , _r/2, _g/2, _b/2);
_current->add(x+offset_x+w, y+offset_y+h);//, _r/2, _g/2, _b/2);
_current->add(x+offset_x , y+offset_y+h);//, _r, _g, _b);
_current->add(x+offset_x , y+offset_y, 1.);// , _r, _g, _b);
_current->add(x+offset_x+w, y+offset_y, 0.5);// , _r/2, _g/2, _b/2);
_current->add(x+offset_x+w, y+offset_y+h, 0.5);//, _r/2, _g/2, _b/2);
_current->add(x+offset_x , y+offset_y+h, 1.);//, _r, _g, _b);
}
else if(_draw_ruler){
}
......@@ -760,7 +761,7 @@ void Render_alternate::draw_state(const Element_pos x, const Element_pos y, cons
_states.insert(p2);
}
_current = _states[value];
draw_quad(x, y, z, w*0.98, h);
draw_quad(x, y, z, w, h);
}
void Render_alternate::end_draw_states(){
......
......@@ -29,27 +29,27 @@ Shader::Shader() : m_vertexID(0), m_fragmentID(0), m_programID(0),
{
}
Shader::Shader(Element_col r, Element_col g, Element_col b):m_vertexID(0), m_fragmentID(0), m_programID(0), m_vertex_code("#version 330 core \n in vec2 in_Vertex; \n uniform mat4 MVP; \n void main(){ \n gl_Position = MVP * vec4(in_Vertex, 0.0, 1.0); \n }"){
Shader::Shader(Element_col r, Element_col g, Element_col b):m_vertexID(0), m_fragmentID(0), m_programID(0), m_vertex_code("#version 330 core \n in vec2 in_Vertex; \n in float c; \n uniform mat4 MVP; \n out float shade; \n void main(){ \n gl_Position = MVP * vec4(in_Vertex, 0.0, 1.0); \n shade=c; \n }"){
std::ostringstream os;
//std::cout << "rgb" << r << " " << g << " " << b << std::endl;
os << "#version 330 core \n out vec4 outColor; \n void main(){ \n if(true) { \n outColor = vec4(";
os << "#version 330 core \n in float shade; \n out vec4 outColor; \n void main(){ \n outColor = vec4(";
os << r;
os << ", ";
os << "*shade, ";
os << g;
os << ", ";
os << "*shade, ";
os << b;
os << ", 0.5); \n }";
os << "else { \n out_Color = vec4(";
os << 1;
/*os << ", 0.5); \n";
os << "else \n outColor = vec4(";
os << r/2;
os << ", ";
os << 1;
os << g/2;
os << ", ";
os << 1;
os << ", 0.5); \n } \n \n }";
os << b/2;*/
os << "*shade, 0.5); \n }";
m_fragment_code=os.str();
/*std::cout << "code shaders" << std::endl;
std::cout << "code shaders" << std::endl;
std::cout << m_vertex_code << std::endl;
std::cout << m_fragment_code << std::endl;*/
std::cout << m_fragment_code << std::endl;
}
......
......@@ -105,10 +105,12 @@ int Vbo::add(Element_pos x, Element_pos y, Element_col r, Element_col g, Element
_nbVertex++;
}
int Vbo::add(Element_pos x, Element_pos y/*, bool b*/){
int Vbo::add(Element_pos x, Element_pos y, float b){
_vertex.push_back(x);
_vertex.push_back(y);
//_shaded.push_back(b);
_shaded.push_back(b);
//_vertex.push_back(3);
//_vertex.push_back(3);
_nbVertex++;
}
......@@ -116,10 +118,10 @@ void Vbo::config(){
std::cout << "Configuration du VBO. Nombre de points : "<< _vertex.size()/2 << std::endl;
int vertex_size = _vertex.size() * sizeof(Element_pos);
int colors_size = _colors.size() * sizeof(Element_col);
//int shaded_size = _shaded.size() * sizeof(bool);
float shaded_size = _shaded.size() * sizeof(float);
Element_pos * vertex = &_vertex[0];
Element_col * colors = &_colors[0];
//bool * shaded = &_shaded[0];
float * shaded = &_shaded[0];
//Delete old vbo if necessary
if(glIsBuffer(_vboID) == GL_TRUE)
glDeleteBuffers(1, &_vboID);
......@@ -128,11 +130,11 @@ void Vbo::config(){
//Select our VBO
glBindBuffer(GL_ARRAY_BUFFER, _vboID);
//Allocate memory inside graphic card
glBufferData(GL_ARRAY_BUFFER, vertex_size+colors_size/*+shaded_size*/, 0, GL_STATIC_DRAW);
glBufferData(GL_ARRAY_BUFFER, vertex_size+colors_size+shaded_size, 0, GL_STATIC_DRAW);
//Send datas
glBufferSubData(GL_ARRAY_BUFFER, 0 , vertex_size, vertex);
glBufferSubData(GL_ARRAY_BUFFER, vertex_size, colors_size, colors);
//glBufferSubData(GL_ARRAY_BUFFER, vertex_size+colors_size, shaded_size, shaded);
glBufferSubData(GL_ARRAY_BUFFER, vertex_size+colors_size, shaded_size, shaded);
//Deselect our VBO
glBindBuffer(GL_ARRAY_BUFFER, 0);
//Clear RAM
......@@ -141,7 +143,7 @@ void Vbo::config(){
//Clear RAM and realoccate _vertex and _colors
std::vector<Element_pos>().swap(_vertex);
std::vector<Element_col>().swap(_colors);
//std::vector<boolean>().swap(_shaded);
std::vector<float>().swap(_shaded);
//Delete old vao if necessary
if(glIsVertexArray(_vaoID))
glDeleteVertexArrays(1, &_vaoID);
......@@ -161,9 +163,10 @@ void Vbo::config(){
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, BUFFER_OFFSET(vertex_size));
glEnableVertexAttribArray(1);
}
/*if(shaded_size>0){
glVertexAttribPointer(2, 1, GL_BOOLEAN, GL_FALSE, 0, BUFFER_OFFSET(vertex_size+colors_size));
glEnableVertexAttribArray(2);*/
if(shaded_size>0){
glVertexAttribPointer(1, 1, GL_FLOAT, GL_FALSE, 0, BUFFER_OFFSET(vertex_size+colors_size));
glEnableVertexAttribArray(1);
}
//Deselect VBO
glBindBuffer(GL_ARRAY_BUFFER,0);
}
......
......@@ -63,7 +63,7 @@ private:
GLuint _vaoID;
vector<Element_pos> _vertex;
vector<Element_col> _colors;
//vector<bool> _shaded;
vector<float> _shaded;
GLenum _mode;
int _nbVertex;
......@@ -107,7 +107,7 @@ public:
int add(Element_pos x, Element_pos y, Element_col r, Element_col g, Element_col b);
int add(Element_pos x, Element_pos y/*, bool b*/);
int add(Element_pos x, Element_pos y, float b);
void lock();
void unlock();
......
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