Commit eda5ea1b authored by Thibault Soucarre's avatar Thibault Soucarre

scaling and position are correct

parent 620c9fa1
...@@ -96,7 +96,7 @@ static bool _draw_event; ...@@ -96,7 +96,7 @@ static bool _draw_event;
**********************************/ **********************************/
Render_alternate::Render_alternate(Core* core, QWidget *parent, const QGLFormat& format) Render_alternate::Render_alternate(Core* core, QWidget *parent, const QGLFormat& format)
: Hook_event(this, core, parent, format), _containers(GL_QUADS), _states(GL_QUADS), _events(GL_POLYGON), _arrows(GL_LINE), _counters(GL_LINE), _shader("vertexshader.vertexshader", "fragmentshader.fragmentshader"), _modelview(glm::mat4(1.0)){ : Hook_event(this, core, parent, format), _containers(GL_QUADS), _states(GL_QUADS), _events(GL_POLYGON), _arrows(GL_LINE), _counters(GL_LINE), _shader("vertexshader.vertexshader", "fragmentshader.fragmentshader"), _modelview(glm::mat4(1.0)), _projection(glm::mat4(1.0)){
setAutoFillBackground(false); setAutoFillBackground(false);
...@@ -119,8 +119,9 @@ Render_alternate::~Render_alternate(){ ...@@ -119,8 +119,9 @@ Render_alternate::~Render_alternate(){
void Render_alternate::initializeGL() { void Render_alternate::initializeGL() {
glewExperimental = GL_TRUE; glewExperimental = GL_TRUE;
GLenum err = glewInit(); GLenum err = glewInit();
if(err!=GLEW_OK) if(err!=GLEW_OK){
std::cout << "ERROR : GlewInit failed" << std::endl; std::cout << "ERROR : GlewInit failed" << std::endl;
}
_shader.charger(); _shader.charger();
glClearColor(0.5f, 0.5f, 0.55f, 0.0f); glClearColor(0.5f, 0.5f, 0.55f, 0.0f);
...@@ -132,7 +133,8 @@ void Render_alternate::initializeGL() { ...@@ -132,7 +133,8 @@ void Render_alternate::initializeGL() {
std::cout << "_core = NULL" << std::endl; std::cout << "_core = NULL" << std::endl;
_core->waitGUIInit->quit(); _core->waitGUIInit->quit();
std::cout << "init ok" << std::endl; std::cout << "init ok" << std::endl;
_modelview = glm::scale(_modelview, glm::vec3(0.01,-0.01,1)); _modelview = glm::scale(_modelview, glm::vec3(1,-1,1));
_modelview = glm::translate(_modelview, glm::vec3(0,-Info::Render::height, 0));
} }
void Render_alternate::resizeGL(int width, int height) { void Render_alternate::resizeGL(int width, int height) {
...@@ -141,12 +143,18 @@ void Render_alternate::resizeGL(int width, int height) { ...@@ -141,12 +143,18 @@ void Render_alternate::resizeGL(int width, int height) {
/* update informations about widget size */ /* update informations about widget size */
Info::Screen::width = width; Info::Screen::width = width;
Info::Screen::height = height; Info::Screen::height = height;
if(_state == DRAWING_STATE_WAITING)
_projection = glm::ortho(-50, 50, -50, 50);//, 0, 1);
else if(_state == DRAWING_STATE_DRAWING)
_projection = glm::ortho(0., Info::Render::width, 0., Info::Render::height, 0., 1.);
else{
message << tr("Undefined value for the drawing state attribute - Render area").toStdString() << Message::ende;
}
glMatrixMode(GL_PROJECTION); /*glMatrixMode(GL_PROJECTION);
glLoadIdentity(); glLoadIdentity();
if(DRAWING_STATE_WAITING == _state){// A wait is drawn if(DRAWING_STATE_WAITING == _state){// A wait is drawn
glOrtho(-50, 50, -50, 50, 0, 1000); glOrtho(-50, 50, -50, 50, 0, 1000);
}else if (DRAWING_STATE_DRAWING == _state){// A trace is drawn }else if (DRAWING_STATE_DRAWING == _state){// A trace is drawn
...@@ -156,7 +164,8 @@ void Render_alternate::resizeGL(int width, int height) { ...@@ -156,7 +164,8 @@ void Render_alternate::resizeGL(int width, int height) {
} }
glMatrixMode(GL_MODELVIEW); glMatrixMode(GL_MODELVIEW);*/
} }
...@@ -168,20 +177,26 @@ void Render_alternate::paintGL(){ ...@@ -168,20 +177,26 @@ void Render_alternate::paintGL(){
//select shader program //select shader program
glUseProgram(_shader.getProgramID()); glUseProgram(_shader.getProgramID());
std::cout << "paintGL" << std::endl; std::cout << "paintGL" << std::endl;
glm::mat4 tmp = _modelview;
/* drawing containers*/ //_modelview = glm::translate(_modelview, glm::vec3(0.0, Info::Render::height, 100.0));
//_modelview = glm::rotate(_modelview, (float)180.0, glm::vec3(1.0, 0.0, 0.0));
tmp = _modelview;
/* drawing containers*/
_containers.lock(); _containers.lock();
//_modelview = glm::translate(_modelview, glm::vec3(0.0f, _ruler_y + _ruler_height -_y_state_translate, _z_container)); //_modelview = glm::translate(_modelview, glm::vec3(0.0f, _ruler_y + _ruler_height -_y_state_translate, _z_container));
//_modelview = glm::scale(_modelview, glm::vec3(_x_scale_container_state/0.20, _y_state_scale, 1.0)); //_modelview = glm::scale(_modelview, glm::vec3(_x_scale_container_state/0.20, _y_state_scale, 1.0));
glUniformMatrix4fv(glGetUniformLocation(_shader.getProgramID(), "modelview"), 1, GL_FALSE, glm::value_ptr(_modelview)); glUniformMatrix4fv(glGetUniformLocation(_shader.getProgramID(), "modelview"), 1, GL_FALSE, glm::value_ptr(_modelview));
glUniformMatrix4fv(glGetUniformLocation(_shader.getProgramID(), "projection"), 1, GL_FALSE, glm::value_ptr(_projection));
glDrawArrays(GL_QUADS, 0, _containers.getNbVertex()); glDrawArrays(GL_QUADS, 0, _containers.getNbVertex());
_containers.unlock(); _containers.unlock();
_modelview = tmp;
/*drawing states*/ /*drawing states*/
_states.lock(); _states.lock();
glm::mat4 tmp = _modelview; _modelview = glm::translate(_modelview, glm::vec3(_default_entity_x_translate - _x_state_translate, 0.0/*_ruler_y + _ruler_height - _y_state_translate*/, 0.0/*_z_state*/));
_modelview = glm::translate(_modelview, glm::vec3(_default_entity_x_translate - _x_state_translate, 0.0, 0.0)); _modelview = glm::scale(_modelview, glm::vec3(_x_state_scale, _y_state_scale, 1));
glUniformMatrix4fv(glGetUniformLocation(_shader.getProgramID(), "modelview"), 1, GL_FALSE, glm::value_ptr(_modelview)); glUniformMatrix4fv(glGetUniformLocation(_shader.getProgramID(), "modelview"), 1, GL_FALSE, glm::value_ptr(_modelview));
glUniformMatrix4fv(glGetUniformLocation(_shader.getProgramID(), "projection"), 1, GL_FALSE, glm::value_ptr(_projection));
glDrawArrays(GL_QUADS, 0, _states.getNbVertex()); glDrawArrays(GL_QUADS, 0, _states.getNbVertex());
_states.unlock(); _states.unlock();
_modelview = tmp; _modelview = tmp;
...@@ -201,11 +216,14 @@ void Render_alternate::paintGL(){ ...@@ -201,11 +216,14 @@ void Render_alternate::paintGL(){
tmp = _modelview; tmp = _modelview;
//change matrix //change matrix
_modelview = glm::translate(_modelview, glm::vec3(_default_entity_x_translate - _x_state_translate, 0 , 0)); _modelview = glm::translate(_modelview, glm::vec3(_default_entity_x_translate - _x_state_translate, 0 , 0));
_modelview = glm::scale(_modelview, glm::vec3(_x_state_scale, _y_state_scale, 1.0));
_modelview = glm::translate(_modelview, glm::vec3(_links[4*i+2], _links[4*i+3], 0)); _modelview = glm::translate(_modelview, glm::vec3(_links[4*i+2], _links[4*i+3], 0));
_modelview = glm::rotate(_modelview, (float) _links[4*i], glm::vec3(0,0,1)); _modelview = glm::rotate(_modelview, (float) _links[4*i], glm::vec3(0,0,1));
_modelview = glm::scale(_modelview, glm::vec3(_links[4*i+1], _links[4*i+1/10], 1)); _modelview = glm::scale(_modelview, glm::vec3(_links[4*i+1], _links[4*i+1/10], 1));
//draw the arrow //draw the arrow
glUniformMatrix4fv(glGetUniformLocation(_shader.getProgramID(), "modelview"), 1, GL_FALSE, glm::value_ptr(_modelview)); glUniformMatrix4fv(glGetUniformLocation(_shader.getProgramID(), "modelview"), 1, GL_FALSE, glm::value_ptr(_modelview));
glUniformMatrix4fv(glGetUniformLocation(_shader.getProgramID(), "projection"), 1, GL_FALSE, glm::value_ptr(_projection));
glDrawArrays(GL_LINES, 0,6); glDrawArrays(GL_LINES, 0,6);
_arrows.unlock(); _arrows.unlock();
//restore matrix //restore matrix
...@@ -591,8 +609,6 @@ GLuint Render_alternate::draw_wait() { ...@@ -591,8 +609,6 @@ GLuint Render_alternate::draw_wait() {
void Render_alternate::call_ruler(){ void Render_alternate::call_ruler(){
Element_pos graduation_diff; Element_pos graduation_diff;
Element_pos coeff_prefix; Element_pos coeff_prefix;
......
...@@ -95,6 +95,7 @@ private: ...@@ -95,6 +95,7 @@ private:
bool _draw_counter; bool _draw_counter;
std::vector<Element_pos> _links; std::vector<Element_pos> _links;
glm::mat4 _modelview; glm::mat4 _modelview;
glm::mat4 _projection;
protected: protected:
/*! /*!
......
...@@ -4,10 +4,11 @@ in vec2 in_Vertex; ...@@ -4,10 +4,11 @@ in vec2 in_Vertex;
in vec3 in_Color; in vec3 in_Color;
uniform mat4 modelview; uniform mat4 modelview;
uniform mat4 projection;
out vec3 color; out vec3 color;
void main(){ void main(){
gl_Position = modelview * vec4(in_Vertex, 1.0, 1.0); gl_Position = projection * modelview * vec4(in_Vertex, 0.0, 1.0);
color = in_Color; color = in_Color;
} }
\ No newline at end of file
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