Skip to content

Commit

Permalink
bug fix: confirmed that the previous opengl error was due to the inac…
Browse files Browse the repository at this point in the history
…tive OpenGL context. Fixed it by moving the update function into paintGL(). This causes a delay when updating the approximation, will probably need multithreaded solution (low-priority / future work)
  • Loading branch information
denizdiktas committed Jul 17, 2023
1 parent 13111f4 commit a43389d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
27 changes: 21 additions & 6 deletions Arrangement_on_surface_2/demo/earth/Main_widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,8 @@ void Main_widget::initializeGL()
init_geometry();
init_shader_programs();

init_country_borders(0.001);
m_current_approx_error = 0.001;
init_country_borders(m_current_approx_error);
init_country_selection();

glClearColor(0, 0, 0, 1);
Expand All @@ -213,6 +214,7 @@ void Main_widget::initializeGL()
m_timer.start(12, this);
}


void Main_widget::init_camera()
{
m_camera.set_pos(0, 0, 3);
Expand All @@ -224,8 +226,9 @@ void Main_widget::init_camera()
Message_manager::add("zoom_changed", [&]
{
qDebug() << "ZOOM CHANGED!!!";
const auto error = compute_backprojected_error(0.5);
qDebug() << "new error = " << error;
//const auto error = compute_backprojected_error(0.5);
//qDebug() << "new error = " << error;
m_update_approx_error = true;
//qDebug() << "re-initializing the country borders..";
//init_country_borders(error);
});
Expand Down Expand Up @@ -404,9 +407,8 @@ void Main_widget::resizeGL(int w, int h)
const qreal z_near = 0.1, z_far = 100.0, fov = 45.0;
m_camera.perspective(fov, aspect, z_near, z_far);

// compute the world-space error for the given pixel-error
const auto err = compute_backprojected_error(0.5f);
std::cout << "error = " << err << std::endl;
// signal to look into the approximation error
m_update_approx_error = true;
}

template<typename T>
Expand All @@ -418,6 +420,19 @@ void draw_safe(T& ptr)

void Main_widget::paintGL()
{
if (m_update_approx_error)
{
const auto error = compute_backprojected_error(0.5);
qDebug() << "new approx error = " << error;
qDebug() << "current error = " << m_current_approx_error;
if(error < m_current_approx_error)
{
init_country_borders(error);
m_current_approx_error = error;
}
m_update_approx_error = false;
}

QMatrix4x4 model;
model.rotate(-90, 1,0,0); // this makes z-axes point upwards!
const auto view = m_camera.get_view_matrix();
Expand Down
7 changes: 7 additions & 0 deletions Arrangement_on_surface_2/demo/earth/Main_widget.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,13 @@ class Main_widget : public QOpenGLWidget, protected OpenGLFunctionsBase
// view-port
int m_vp_width = 0, m_vp_height = 0;

// After zooming in or making the viewport larger, the approximation-error
// needs to be updated and checked against the old value. If a lower approxi-
// mation error is needed the necessary graphics-side updates need to be made
// INSIDE the paintGL (or whereever the OpenGL context is active)!
bool m_update_approx_error = false;
float m_current_approx_error;

// Timer for continuous screen-updates
QBasicTimer m_timer;
};
Expand Down

0 comments on commit a43389d

Please sign in to comment.