Commit c3a29831 authored by Thibault Soucarre's avatar Thibault Soucarre

Using a char instead of a float for shade

parent c440dbda
......@@ -674,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, 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);
_current->add(x+offset_x , y+offset_y, 2);// , _r, _g, _b);
_current->add(x+offset_x+w, y+offset_y, 1);// , _r/2, _g/2, _b/2);
_current->add(x+offset_x+w, y+offset_y+h, 1);//, _r/2, _g/2, _b/2);
_current->add(x+offset_x , y+offset_y+h, 2);//, _r, _g, _b);
}
else if(_draw_ruler){
}
......
......@@ -29,15 +29,15 @@ 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 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 }"){
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 int 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=intBitsToFloat(c); \n }"){
std::ostringstream os;
//std::cout << "rgb" << r << " " << g << " " << b << std::endl;
os << "#version 330 core \n in float shade; \n out vec4 outColor; \n void main(){ \n outColor = vec4(";
os << r;
os << r/2;
os << "*shade, ";
os << g;
os << g/2;
os << "*shade, ";
os << b;
os << b/2;
/*os << ", 0.5); \n";
os << "else \n outColor = vec4(";
os << r/2;
......
......@@ -105,7 +105,7 @@ 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, float b){
int Vbo::add(Element_pos x, Element_pos y, char b){
_vertex.push_back(x);
_vertex.push_back(y);
_shaded.push_back(b);
......@@ -118,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);
float shaded_size = _shaded.size() * sizeof(float);
int shaded_size = _shaded.size() * sizeof(char);
Element_pos * vertex = &_vertex[0];
Element_col * colors = &_colors[0];
float * shaded = &_shaded[0];
char * shaded = &_shaded[0];
//Delete old vbo if necessary
if(glIsBuffer(_vboID) == GL_TRUE)
glDeleteBuffers(1, &_vboID);
......@@ -143,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<float>().swap(_shaded);
std::vector<char>().swap(_shaded);
//Delete old vao if necessary
if(glIsVertexArray(_vaoID))
glDeleteVertexArrays(1, &_vaoID);
......@@ -164,7 +164,7 @@ void Vbo::config(){
glEnableVertexAttribArray(1);
}
if(shaded_size>0){
glVertexAttribPointer(1, 1, GL_FLOAT, GL_FALSE, 0, BUFFER_OFFSET(vertex_size+colors_size));
glVertexAttribPointer(1, 1, GL_BYTE, GL_FALSE, 0, BUFFER_OFFSET(vertex_size+colors_size));
glEnableVertexAttribArray(1);
}
//Deselect VBO
......
......@@ -63,7 +63,7 @@ private:
GLuint _vaoID;
vector<Element_pos> _vertex;
vector<Element_col> _colors;
vector<float> _shaded;
vector<char> _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, float b);
int add(Element_pos x, Element_pos y, char 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