diff options
author | ccolin | 2021-01-04 13:34:34 +0100 |
---|---|---|
committer | ccolin | 2021-01-04 13:34:34 +0100 |
commit | 0f06601bc69d08baaa6c5b11c03e59ac818c426e (patch) | |
tree | b9225f8b6529b74f289591bdea63992393315f9c /src/drone_controller.cc | |
parent | 7fe6bf15180110ba0df803472444cd7fd6a4e414 (diff) |
fix misc rendering issue
Diffstat (limited to 'src/drone_controller.cc')
-rw-r--r-- | src/drone_controller.cc | 71 |
1 files changed, 36 insertions, 35 deletions
diff --git a/src/drone_controller.cc b/src/drone_controller.cc index f1b4a48..cede63d 100644 --- a/src/drone_controller.cc +++ b/src/drone_controller.cc @@ -45,9 +45,9 @@ DroneController::DroneController(const QJsonObject &json) } -void DroneController::drawTrajectory(QOpenGLExtraFunctions *f, const Drone &d) const { - OpenGLWidget::instance->getLineProgram()->bind(); - OpenGLWidget::instance->getLineProgram()->setUniformValue("color", 1, 0, .532); +void DroneController::drawTrajectory(OpenGLWidget *glw, const Drone &d) const { + glw->getLineProgram()->bind(); + glw->getLineProgram()->setUniformValue("color", 1, 0, .532); size_t trajectory_len = 1; for (const Waypoint &wp : d.getWaypoints()) { if (wp.frame > frame) break; @@ -65,25 +65,23 @@ void DroneController::drawTrajectory(QOpenGLExtraFunctions *f, const Drone &d) c trajectory[i] = d.getPos().x(); trajectory[i + 1] = d.getPos().y(); trajectory[i + 2] = d.getPos().z(); - f->glEnableVertexAttribArray(0); - f->glBindBuffer(GL_ARRAY_BUFFER, 0); - f->glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, trajectory); + glw->glEnableVertexAttribArray(0); + glw->glBindBuffer(GL_ARRAY_BUFFER, 0); + glw->glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, trajectory); glLineWidth(2); - f->glDisable(GL_CULL_FACE); - f->glDrawArrays(GL_LINE_STRIP, 0, trajectory_len); - f->glEnable(GL_CULL_FACE); - OpenGLWidget::instance->getLineProgram()->release(); - OpenGLWidget::instance->getMainProgram()->bind(); + glw->glDisable(GL_CULL_FACE); + glw->glDrawArrays(GL_LINE_STRIP, 0, trajectory_len); + glw->glEnable(GL_CULL_FACE); + glw->getLineProgram()->release(); + glw->getMainProgram()->bind(); } -void DroneController::drawGuide(QOpenGLExtraFunctions *f, const Drone &d) const { - OpenGLWidget *glw = OpenGLWidget::instance; - +void DroneController::drawGuide(OpenGLWidget *glw, const Drone &d) const { glw->getLineProgram()->bind(); - f->glEnableVertexAttribArray(0); - f->glBindBuffer(GL_ARRAY_BUFFER, 0); - f->glDisable(GL_CULL_FACE); + glw->glEnableVertexAttribArray(0); + glw->glBindBuffer(GL_ARRAY_BUFFER, 0); + glw->glDisable(GL_CULL_FACE); QVector<GLfloat> support_line { d.getPos().x(), 0, d.getPos().z(), @@ -91,8 +89,8 @@ void DroneController::drawGuide(QOpenGLExtraFunctions *f, const Drone &d) const }; glLineWidth(2); glw->getLineProgram()->setUniformValue("color", .2, .2, .4); - f->glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, support_line.constData()); - f->glDrawArrays(GL_LINES, 0, 2); + glw->glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, support_line.constData()); + glw->glDrawArrays(GL_LINES, 0, 2); QVector<GLfloat> grid; const int size = 100; @@ -113,8 +111,8 @@ void DroneController::drawGuide(QOpenGLExtraFunctions *f, const Drone &d) const } glLineWidth(1); glw->getLineProgram()->setUniformValue("color", .2, .2, .2); - f->glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, grid.constData()); - f->glDrawArrays(GL_LINES, 0, grid.size() / 3); + glw->glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, grid.constData()); + glw->glDrawArrays(GL_LINES, 0, grid.size() / 3); glDisable(GL_DEPTH_TEST); // pro-gamer move QVector<GLfloat> axes { @@ -124,17 +122,17 @@ void DroneController::drawGuide(QOpenGLExtraFunctions *f, const Drone &d) const }; glLineWidth(2); glw->getLineProgram()->setUniformValue("color", 1, 0, 0); - f->glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, axes.constData()); - f->glDrawArrays(GL_LINES, 0, 2); + glw->glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, axes.constData()); + glw->glDrawArrays(GL_LINES, 0, 2); glw->getLineProgram()->setUniformValue("color", 0, 1, 0); - f->glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, axes.constData() + 6); - f->glDrawArrays(GL_LINES, 0, 2); + glw->glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, axes.constData() + 6); + glw->glDrawArrays(GL_LINES, 0, 2); glw->getLineProgram()->setUniformValue("color", 0, 0, 1); - f->glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, axes.constData() + 12); - f->glDrawArrays(GL_LINES, 0, 2); + glw->glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, axes.constData() + 12); + glw->glDrawArrays(GL_LINES, 0, 2); glDisable(GL_DEPTH_TEST); - f->glEnable(GL_CULL_FACE); + glw->glEnable(GL_CULL_FACE); glw->getLineProgram()->release(); glw->getMainProgram()->bind(); @@ -154,27 +152,30 @@ void DroneController::drawGuide(QOpenGLExtraFunctions *f, const Drone &d) const } -void DroneController::draw(QOpenGLExtraFunctions *f) const { +void DroneController::draw(OpenGLWidget *glw) const { const QVector<QPair<int, int>> &col = collisions[frame]; for (const Drone &d : drones) { + glw->getMainProgram()->bind(); QMatrix4x4 mat; mat.translate(d.getPos()); for (const QPair<int, int> &p : col) { if (d.getId() == p.first || d.getId() == p.second) { - OpenGLWidget::instance->getMainProgram()->setUniformValue("highlight", true); + glw->getMainProgram()->setUniformValue("highlight", true); } } - d.getMesh()->draw(f, mat); + d.getMesh()->draw(glw, mat); if (draw_spheres) { mat.scale(sphere_radius); - sphere->draw(f, mat); + sphere->draw(glw, mat); } - OpenGLWidget::instance->getMainProgram()->setUniformValue("highlight", false); + glw->getMainProgram()->bind(); + glw->getMainProgram()->setUniformValue("highlight", false); + glw->getMainProgram()->release(); if (draw_trajectories) { - drawTrajectory(f, d); + drawTrajectory(glw, d); } if (draw_guides) { - drawGuide(f, d); + drawGuide(glw, d); } } } |