Commit be3e461c authored by Thibault Soucarre's avatar Thibault Soucarre

correct home screen

parent 7c117fa9
......@@ -135,7 +135,10 @@ void Render_alternate::initializeGL() {
_glsl = (version[0]-'0')*100 + (version[2]-'0')*10 + version[3]-'0';
std::cout << _glsl << std::endl;
_shader = new Shader(_glsl);
_wait_shader = new Shader(_glsl, 0);
_shader->charger();
_wait_shader->charger();
draw_wait();
//std::cout << version[2] << std::endl;
//std::cout << version[3] << std::endl;
setAutoFillBackground(false);
......@@ -165,9 +168,22 @@ void Render_alternate::resizeGL(int width, int height) {
void Render_alternate::paintGL(){
glClearDepth(1.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
/*Do not call paintGL before rendering the trace*/
if(DRAWING_STATE_WAITING == _state)
if(DRAWING_STATE_WAITING == _state){
glUseProgram(_wait_shader->getProgramID());
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
_wait.lock();
glBindTexture(GL_TEXTURE_2D, _textureID);
std::cout << "draw wait\n";
glDrawArrays(GL_QUADS, 0, _wait.getNbVertex());
glBindTexture(GL_TEXTURE_2D, 0);
_wait.unlock();
glUseProgram(0);
return;
}
resizeGL(Render_alternate::QGLWidget::width(), Render_alternate::QGLWidget::height());
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
......@@ -613,6 +629,18 @@ bool Render_alternate::unbuild(){
GLuint Render_alternate::draw_wait() {
glGenTextures(1, &_textureID);
QFile texture_file(QString(":/img/img/logo") + QDate::currentDate().toString("MMdd") + QString(".png"));
glBindTexture(GL_TEXTURE_2D, _textureID);
if (true == texture_file.exists())/* The texture exists */
_textureID = bindTexture(QPixmap(texture_file.fileName()), GL_TEXTURE_2D);
else/* use the default picture */
_textureID = bindTexture(QPixmap(":/img/img/logo.png"), GL_TEXTURE_2D);
_wait.add(-0.25, -0.25, 0, 0);
_wait.add( 0.25, -0.25, 1, 0);
_wait.add( 0.25, 0.25, 1, 1);
_wait.add(-0.25, 0.25, 0, 1);
_wait.config(_glsl);
// GLuint object;
// GLuint texture;
......
......@@ -101,6 +101,7 @@ class Render_alternate : /*public QGLWidget,*/ public Hook_event, public Render
private:
int _glsl; //version of OpenGL Shading Language
Shader* _shader;
Shader* _wait_shader;
Element_pos _container_height;
Element_col _r;
Element_col _g;
......@@ -120,9 +121,11 @@ private:
Vbo _arrows3;
Vbo _counters;
Vbo _ruler;
Vbo _wait;
Vbo *_current;
std::map<const EntityValue*, Vbo*> _states;
std::map<const EntityValue*, Shader*> _states_shaders;
GLuint _textureID;
/*!
* \brief Offset of the vertical helper line
*/
......
......@@ -28,7 +28,22 @@ Shader::Shader() : m_vertexID(0), m_fragmentID(0), m_programID(0),
m_vertex_code("#version 330 core \n in vec2 in_Vertex; \n in vec3 in_Color; \n uniform mat4 MVP; \n out vec3 color; \n void main(){ \n gl_Position = MVP * vec4(in_Vertex, 0.0, 1.0); \n color = in_Color; \n }"), m_fragment_code("#version 330 core \n in vec3 color; \n out vec4 out_Color; \n void main(){ \n out_Color = vec4(color, 0.5); \n }")
{
}
Shader::Shader(int glsl){
/*Parameter n is not used, it just allow to create a have another constructor for shader using texture*/
Shader::Shader(int glsl, int n):m_vertexID(0), m_fragmentID(0), m_programID(0){
std::ostringstream os1, os2;
os1 << "#version ";
os1 << glsl;
os1 << " \n in vec2 in_Vertex; \n in vec2 in_UV; \n out vec2 UV; \n void main(){ \n gl_Position = vec4(in_Vertex, 0.0, 1.0); \n UV = in_UV; \n }";
os2 << "#version ";
os2 << glsl;
os2 << " \n in vec2 UV; \n out vec4 out_Color; \n uniform sampler2D textureSampler; \n void main(){ \n out_Color = texture(textureSampler, UV); \n }";
m_vertex_code = os1.str();
m_fragment_code = os2.str();
std::cout << m_vertex_code << std::endl;
std::cout << m_fragment_code << std::endl;
}
Shader::Shader(int glsl):m_vertexID(0), m_fragmentID(0), m_programID(0){
std::ostringstream os1, os2;
os1 << "#version ";
os1 << glsl;
......@@ -36,8 +51,6 @@ Shader::Shader(int glsl){
os2 << "#version ";
os2 << glsl;
os2 << " \n in vec3 color; \n out vec4 out_Color; \n void main(){ \n out_Color = vec4(color, 0.5); \n }";
std::cout << os1 << std::endl;
std::cout << os2 << std::endl;
m_vertex_code = os1.str();
m_fragment_code = os2.str();
std::cout << m_vertex_code << std::endl;
......@@ -134,7 +147,6 @@ bool Shader::charger()
if(!compilerShader(m_vertexID, GL_VERTEX_SHADER, m_vertex_code))
return false;
if(!compilerShader(m_fragmentID, GL_FRAGMENT_SHADER, m_fragment_code))
return false;
......@@ -154,7 +166,7 @@ bool Shader::charger()
glBindAttribLocation(m_programID, 0, "in_Vertex");
glBindAttribLocation(m_programID, 1, "in_Color");
glBindAttribLocation(m_programID, 2, "in_TexCoord0");
glBindAttribLocation(m_programID, 2, "in_UV");
// Linkage du programme
......@@ -217,7 +229,6 @@ bool Shader::charger()
bool Shader::compilerShader(GLuint &shader, GLenum type, std::string code)
{
// Cration du shader
shader = glCreateShader(type);
......
......@@ -16,6 +16,7 @@ class Shader
public:
Shader();
Shader(int glsl, int n);
Shader(int glsl);
Shader(int glsl, Element_col, Element_col, Element_col);
//Shader(Shader const &shaderACopier);
......
......@@ -106,6 +106,14 @@ 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, Element_pos tx, Element_pos ty){
_vertex.push_back(x);
_vertex.push_back(y);
_texture_coord.push_back(tx);
_texture_coord.push_back(ty);
_nbVertex++;
}
int Vbo::add(Element_pos x, Element_pos y, char b){
_vertex.push_back(x);
_vertex.push_back(y);
......@@ -124,9 +132,11 @@ void Vbo::config(int glsl){
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 texture_size = _texture_coord.size() * sizeof(Element_pos);
int shaded_size;
Element_pos * vertex = &_vertex[0];
Element_col * colors = &_colors[0];
Element_pos * texture = &_texture_coord[0];
char * shaded;
float* shaded2;
if(glsl<330){
......@@ -145,10 +155,11 @@ void Vbo::config(int glsl){
//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+texture_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, texture_size, texture);
if(glsl<330)
glBufferSubData(GL_ARRAY_BUFFER, vertex_size+colors_size, shaded_size, shaded2);
else
......@@ -163,6 +174,7 @@ void Vbo::config(int glsl){
std::vector<Element_col>().swap(_colors);
std::vector<char>().swap(_shaded);
std::vector<float>().swap(_shaded2);
std::vector<Element_pos>().swap(_texture_coord);
//Delete old vao if necessary
if(glIsVertexArray(_vaoID))
glDeleteVertexArrays(1, &_vaoID);
......@@ -182,6 +194,10 @@ void Vbo::config(int glsl){
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, BUFFER_OFFSET(vertex_size));
glEnableVertexAttribArray(1);
}
if(texture_size>0){
glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, 0, BUFFER_OFFSET(vertex_size));
glEnableVertexAttribArray(2);
}
if(shaded_size>0){
if(glsl<330){
glVertexAttribPointer(1, 1, GL_FLOAT, GL_FALSE, 0, BUFFER_OFFSET(vertex_size+colors_size));
......
......@@ -65,6 +65,7 @@ private:
vector<Element_col> _colors;
vector<char> _shaded;
vector<float> _shaded2;
vector<Element_pos> _texture_coord;
GLenum _mode;
int _nbVertex;
......@@ -108,6 +109,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, Element_pos tx, Element_pos ty);
int add(Element_pos x, Element_pos y, char b);
int add(Element_pos x, Element_pos y, float b);
......
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