diff --git a/ExampleViewOpenGL/src/ExampleGLWidget.cpp b/ExampleViewOpenGL/src/ExampleGLWidget.cpp index 51868a1..75755cf 100644 --- a/ExampleViewOpenGL/src/ExampleGLWidget.cpp +++ b/ExampleViewOpenGL/src/ExampleGLWidget.cpp @@ -3,16 +3,16 @@ #include #include +#include ExampleGLWidget::ExampleGLWidget() : QOpenGLWidget(), _isInitialized(false), _backgroundColor(235, 235, 235, 255), - _pointRenderer(), + _pointRenderer(this), _pixelRatio(1.0f), _points(), - _colors(), - _bounds() + _colors() { setAcceptDrops(true); @@ -39,7 +39,6 @@ ExampleGLWidget::ExampleGLWidget() : surfaceFormat.setSamples(16); setFormat(surfaceFormat); - } ExampleGLWidget::~ExampleGLWidget() @@ -59,29 +58,31 @@ void ExampleGLWidget::setData(const std::vector& points, float poi constexpr mv::Vector3f pointColor = {0.f, 0.f, 0.f}; for(unsigned long i = 0; i < numPoints; i++) - _colors.emplace_back(pointColor); + _colors.push_back(pointColor); - _bounds = Bounds::Max; + Bounds bounds = Bounds::Max; - for (const Vector2f& point : _points) + for (const Vector2f& point : points) { - _bounds.setLeft(std::min(point.x, _bounds.getLeft())); - _bounds.setRight(std::max(point.x, _bounds.getRight())); - _bounds.setBottom(std::min(point.y, _bounds.getBottom())); - _bounds.setTop(std::max(point.y, _bounds.getTop())); + bounds.setLeft(std::min(point.x, bounds.getLeft())); + bounds.setRight(std::max(point.x, bounds.getRight())); + bounds.setBottom(std::min(point.y, bounds.getBottom())); + bounds.setTop(std::max(point.y, bounds.getTop())); } - _bounds.makeSquare(); - _bounds.expand(0.1f); + bounds.makeSquare(); + bounds.expand(0.1f); // Send the data to the renderer - _pointRenderer.setBounds(_bounds); + _pointRenderer.setDataBounds(QRectF(QPointF(bounds.getLeft(), bounds.getBottom()), QSizeF(bounds.getWidth(), bounds.getHeight()))); _pointRenderer.setData(_points); _pointRenderer.setColors(_colors); _pointRenderer.setPointSize(pointSize); _pointRenderer.setAlpha(pointOpacity); + _pointRenderer.initView(); + // Calls paintGL() update(); } diff --git a/ExampleViewOpenGL/src/ExampleGLWidget.h b/ExampleViewOpenGL/src/ExampleGLWidget.h index 0fd3e60..cd63c81 100644 --- a/ExampleViewOpenGL/src/ExampleGLWidget.h +++ b/ExampleViewOpenGL/src/ExampleGLWidget.h @@ -3,7 +3,6 @@ #include #include #include -#include #include #include @@ -42,7 +41,6 @@ class ExampleGLWidget : public QOpenGLWidget, protected QOpenGLFunctions float _pixelRatio; /* device pixel ratio */ std::vector _points; /* 2D coordinates of points */ std::vector _colors; /* Color of points - here we use a constant color for simplicity */ - Bounds _bounds; /* Min and max point coordinates for camera placement */ QColor _backgroundColor; /* Background color */ bool _isInitialized; /* Whether OpenGL is initialized */ };