From 06c048eb724b64a82fb18ecff266064d6f0ff2a1 Mon Sep 17 00:00:00 2001 From: Matt Keeter Date: Sun, 9 Mar 2014 10:06:56 -0700 Subject: [PATCH] Painting status string as text --- src/canvas.cpp | 20 ++++++++++++++++---- src/canvas.h | 4 +++- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/canvas.cpp b/src/canvas.cpp index 39081b0..98c0a29 100644 --- a/src/canvas.cpp +++ b/src/canvas.cpp @@ -35,6 +35,12 @@ void Canvas::load_mesh(Mesh* m) delete m; } +void Canvas::set_status(const QString &s) +{ + status = s; + update(); +} + void Canvas::initializeGL() { mesh_shader.addShaderFromSourceFile(QGLShader::Vertex, ":/gl/mesh.vert"); @@ -42,19 +48,25 @@ void Canvas::initializeGL() mesh_shader.link(); backdrop = new Backdrop(); - - glClearColor(0.0, 0.0, 0.0, 0.0); - glEnable(GL_DEPTH_TEST); } -void Canvas::paintGL() +void Canvas::paintEvent(QPaintEvent *event) { + Q_UNUSED(event); + + glClearColor(0.0, 0.0, 0.0, 0.0); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + glEnable(GL_DEPTH_TEST); backdrop->draw(); if (mesh) draw_mesh(); + + QPainter painter(this); + if (!status.isNull()) + painter.drawText(10, height() - 10, status); } + void Canvas::draw_mesh() { mesh_shader.bind(); diff --git a/src/canvas.h b/src/canvas.h index c094e5b..6507dca 100644 --- a/src/canvas.h +++ b/src/canvas.h @@ -18,10 +18,11 @@ public: Canvas(const QGLFormat& format, QWidget* parent=0); void initializeGL(); - void paintGL(); + void paintEvent(QPaintEvent* event); ~Canvas(); public slots: + void set_status(const QString& s); void load_mesh(Mesh* m); @@ -49,6 +50,7 @@ private: float yaw; QPoint mouse_pos; + QString status; }; #endif // CANVAS_H -- 2.39.5