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;
**********************************/
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);
......@@ -119,8 +119,9 @@ Render_alternate::~Render_alternate(){
void Render_alternate::initializeGL() {
glewExperimental = GL_TRUE;
GLenum err = glewInit();
if(err!=GLEW_OK)
if(err!=GLEW_OK){
std::cout << "ERROR : GlewInit failed" << std::endl;
}
_shader.charger();
glClearColor(0.5f, 0.5f, 0.55f, 0.0f);
......@@ -132,7 +133,8 @@ void Render_alternate::initializeGL() {
std::cout << "_core = NULL" << std::endl;
_core->waitGUIInit->quit();
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) {
......@@ -141,12 +143,18 @@ void Render_alternate::resizeGL(int width, int height) {
/* update informations about widget size */
Info::Screen::width = width;
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();
if(DRAWING_STATE_WAITING == _state){// A wait is drawn
glOrtho(-50, 50, -50, 50, 0, 1000);
}else if (DRAWING_STATE_DRAWING == _state){// A trace is drawn
......@@ -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(){
//select shader program
glUseProgram(_shader.getProgramID());
std::cout << "paintGL" << std::endl;
/* drawing containers*/
glm::mat4 tmp = _modelview;
//_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();
//_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));
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());
_containers.unlock();
_modelview = tmp;
/*drawing states*/
_states.lock();
glm::mat4 tmp = _modelview;
_modelview = glm::translate(_modelview, glm::vec3(_default_entity_x_translate - _x_state_translate, 0.0, 0.0));
_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::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(), "projection"), 1, GL_FALSE, glm::value_ptr(_projection));
glDrawArrays(GL_QUADS, 0, _states.getNbVertex());
_states.unlock();
_modelview = tmp;
......@@ -201,11 +216,14 @@ void Render_alternate::paintGL(){
tmp = _modelview;
//change matrix
_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::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));
//draw the arrow
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);
_arrows.unlock();
//restore matrix
......@@ -591,8 +609,6 @@ GLuint Render_alternate::draw_wait() {
void Render_alternate::call_ruler(){
Element_pos graduation_diff;
Element_pos coeff_prefix;
......
......@@ -95,6 +95,7 @@ private:
bool _draw_counter;
std::vector<Element_pos> _links;
glm::mat4 _modelview;
glm::mat4 _projection;
protected:
/*!
......
......@@ -4,10 +4,11 @@ in vec2 in_Vertex;
in vec3 in_Color;
uniform mat4 modelview;
uniform mat4 projection;
out vec3 color;
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;
}
\ 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