Commit b0133cf7 authored by Thibault Soucarre's avatar Thibault Soucarre

add depth and transparency

parent e0a0610a
......@@ -43,7 +43,6 @@
/*!
*\file Render_alternate.cpp
*/
#include "common/common.hpp"
#include "common/Info.hpp"
#include "common/Message.hpp"
......@@ -149,7 +148,7 @@ void Render_alternate::resizeGL(int width, int 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.);
_projection = glm::ortho(0., Info::Render::width, 0., Info::Render::height, 0., 100.);
else{
message << tr("Undefined value for the drawing state attribute - Render area").toStdString() << Message::ende;
}
......@@ -180,6 +179,7 @@ void Render_alternate::paintGL(){
//glClearColor(0.0, 1.0, 0.0, 1.0);
resizeGL(Render_alternate::QGLWidget::width(), Render_alternate::QGLWidget::height());
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glEnable(GL_DEPTH_TEST);
//select shader program
glUseProgram(_shader.getProgramID());
std::cout << "paintGL" << std::endl;
......@@ -188,18 +188,24 @@ void Render_alternate::paintGL(){
call_ruler();
end_ruler();
_ruler.config();
//_modelview = glm::translate(_modelview, glm::vec3(0.0, Info::Render::height, 100.0));
//_modelview = glm::translate(_modelview, glm::vec3(0.0, 0.0, -1));
//_modelview = glm::rotate(_modelview, (float)180.0, glm::vec3(1.0, 0.0, 0.0));
_ruler.lock();
_modelview = glm::translate(_modelview, glm::vec3(0.0, 0.0, _z_ruler));
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, 8);
_modelview = tmp;
_modelview = glm::translate(_modelview, glm::vec3(0.0, 0.0, _z_ruler_over));
glUniformMatrix4fv(glGetUniformLocation(_shader.getProgramID(), "modelview"), 1, GL_FALSE, glm::value_ptr(_modelview));
glDrawArrays(GL_LINES, 8, _ruler.getNbVertex());
_ruler.unlock();
_modelview = tmp;
/* drawing containers*/
_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.0, _ruler_y + _ruler_height - _y_state_translate, 0.0));
_modelview = glm::translate(_modelview, glm::vec3(0.0, _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));
......@@ -209,7 +215,7 @@ void Render_alternate::paintGL(){
/*drawing states*/
_states.lock();
_modelview = glm::translate(_modelview, glm::vec3(_default_entity_x_translate - _x_state_translate, _ruler_y + _ruler_height - _y_state_translate, 0.0/*_z_state*/));
_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));
glUniformMatrix4fv(glGetUniformLocation(_shader.getProgramID(), "modelview"), 1, GL_FALSE, glm::value_ptr(_modelview));
glUniformMatrix4fv(glGetUniformLocation(_shader.getProgramID(), "projection"), 1, GL_FALSE, glm::value_ptr(_projection));
......@@ -231,7 +237,7 @@ void Render_alternate::paintGL(){
//save current modelview
tmp = _modelview;
//change matrix
_modelview = glm::translate(_modelview, glm::vec3(_default_entity_x_translate - _x_state_translate, _ruler_y + _ruler_height - _y_state_translate , 0));
_modelview = glm::translate(_modelview, glm::vec3(_default_entity_x_translate - _x_state_translate, _ruler_y + _ruler_height - _y_state_translate , _z_arrow));
_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));
......@@ -248,13 +254,16 @@ void Render_alternate::paintGL(){
/*draw selection if necessary*/
if (_mouse_pressed && (Info::Render::_key_ctrl == false) && !_mouse_pressed_inside_container){
//allow transparency
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
Element_pos x0, x1, y0, y1;
x0 = screen_to_render_x(_mouse_x);
y0 = /*Info::Render::height -*/ screen_to_render_y(_mouse_y);
x1 = screen_to_render_x(_new_mouse_x);
y1 = /*Info::Render::height -*/ screen_to_render_y(_new_mouse_y);
float selection[8] = {x0, y0, x0, y1, x1, y1, x1, y0};
float selection_colors[12] = {0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5};
float selection[12] = {x0, y0, x0, y1, x1, y1, x1, y0};
float selection_colors[16] = {1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0};
/*_modelview = glm::translate(_modelview, glm::vec3(_default_entity_x_translate - _x_state_translate,
_ruler_y + _ruler_height - _y_state_translate,
0));*/
......@@ -268,11 +277,12 @@ void Render_alternate::paintGL(){
glDrawArrays(GL_QUADS, 0, 4);
glDisableVertexAttribArray(0);
glDisableVertexAttribArray(1);
glDisable(GL_BLEND);
_modelview = tmp;
}
// _containers.display(_modelview);
//rendu
glDisable(GL_DEPTH_TEST);
//deselect shader
glUseProgram(0);
//_modelview = glm::translate(_modelview, glm::vec3(0.0, -100*Info::Render::height, 0.0));
......@@ -763,10 +773,10 @@ void Render_alternate::call_ruler(){
//coeff_prefix = Ruler::get_coeff_for_common_prefix(Info::Render::_x_min_visible, Info::Render::_x_max_visible);
//draw quads
set_color(0.0, 0.0, 1.0);
_ruler.add(trace_to_render_x(Info::Render::_x_min_visible), 0, _r, _g, _b);
_ruler.add(trace_to_render_x(Info::Render::_x_min_visible), 3, _r, _g, _b);
_ruler.add(trace_to_render_x(Info::Render::_x_min_visible), 8, _r, _g, _b);
_ruler.add(trace_to_render_x(Info::Render::_x_max_visible), 8, _r, _g, _b);
_ruler.add(trace_to_render_x(Info::Render::_x_max_visible), 0, _r, _g, _b);
_ruler.add(trace_to_render_x(Info::Render::_x_max_visible), 3, _r, _g, _b);
set_color(0.0, 0.0, 0.0);
_ruler.add(trace_to_render_x(Info::Render::_x_min_visible), 0, _r, _g, _b);
_ruler.add(trace_to_render_x(Info::Render::_x_min_visible), 3, _r, _g, _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