mirror of https://github.com/CGAL/cgal
Draw text done. WIP Blending
This commit is contained in:
parent
5d594fd166
commit
dbb5c07709
|
|
@ -36,6 +36,9 @@
|
|||
#include <boost/foreach.hpp>
|
||||
#include <boost/container/flat_map.hpp>
|
||||
|
||||
|
||||
#include <QPainter>
|
||||
|
||||
namespace PMP = CGAL::Polygon_mesh_processing;
|
||||
|
||||
|
||||
|
|
@ -832,6 +835,7 @@ void Scene_polyhedron_item::set_erase_next_picked_facet(bool b)
|
|||
}
|
||||
|
||||
void Scene_polyhedron_item::draw(CGAL::Three::Viewer_interface* viewer) const {
|
||||
|
||||
if(!are_buffers_filled)
|
||||
{
|
||||
compute_normals_and_vertices();
|
||||
|
|
@ -862,6 +866,9 @@ void Scene_polyhedron_item::draw(CGAL::Three::Viewer_interface* viewer) const {
|
|||
vaos[Facets]->release();
|
||||
else
|
||||
vaos[Gouraud_Facets]->release();
|
||||
|
||||
viewer->qglColor(Qt::black);
|
||||
viewer->drawText(viewer->width()/2, viewer->height()/2, "CENTER");
|
||||
}
|
||||
|
||||
// Points/Wireframe/Flat/Gouraud OpenGL drawing in a display list
|
||||
|
|
|
|||
|
|
@ -806,7 +806,17 @@ void Viewer::drawVisualHints()
|
|||
rendering_program.release();
|
||||
vao[0].release();
|
||||
}
|
||||
|
||||
bool has_text = false;
|
||||
if(has_text)
|
||||
{
|
||||
TextRenderer *textRenderer = new TextRenderer();
|
||||
for(int i=0; i<3; i++)
|
||||
{
|
||||
float x = 30*i, y = 120, z=0;
|
||||
textRenderer->addText(new TextItem(x,y,z,"Under Testing"));
|
||||
}
|
||||
textRenderer->draw(this);
|
||||
}
|
||||
}
|
||||
|
||||
void Viewer::resizeGL(int w, int h)
|
||||
|
|
@ -1131,3 +1141,32 @@ void Viewer::wheelEvent(QWheelEvent* e)
|
|||
else
|
||||
QGLViewer::wheelEvent(e);
|
||||
}
|
||||
|
||||
void TextRenderer::draw(CGAL::Three::Viewer_interface *viewer)
|
||||
{
|
||||
QPainter painter(viewer);
|
||||
QRect rect;
|
||||
qglviewer::Camera* camera = viewer->camera();
|
||||
//fbo = new QOpenGLFramebufferObject(viewer->width(), viewer->height(),QOpenGLFramebufferObject::Depth);
|
||||
//fbo->bind();
|
||||
//viewer->glEnable(GL_DEPTH_TEST);
|
||||
//viewer->glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
Q_FOREACH(TextItem* item, textItems)
|
||||
{
|
||||
qglviewer::Vec src(item->position()->x(), item->position()->y(),item->position()->z());
|
||||
rect = QRect(camera->projectedCoordinatesOf(src).x-item->width()/2,
|
||||
camera->projectedCoordinatesOf(src).y-item->height()/2,
|
||||
item->width(),
|
||||
item->height());
|
||||
painter.setFont(item->font());
|
||||
painter.drawText(rect, item->text());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
void TextRenderer::addText(TextItem *ti)
|
||||
{
|
||||
textItems.push_back(ti);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -11,6 +11,8 @@
|
|||
|
||||
#include <QGLViewer/qglviewer.h>
|
||||
#include <QPoint>
|
||||
#include <QFont>
|
||||
#include <QOpenGLFramebufferObject>
|
||||
|
||||
// forward declarations
|
||||
class QWidget;
|
||||
|
|
@ -92,6 +94,7 @@ protected:
|
|||
std::vector<float> *normals;
|
||||
std::vector<float> *colors;
|
||||
};
|
||||
|
||||
//! The buffers used to draw the axis system
|
||||
QOpenGLBuffer buffers[3];
|
||||
//! The VAO used to draw the axis system
|
||||
|
|
@ -133,4 +136,50 @@ protected:
|
|||
double prev_radius;
|
||||
}; // end class Viewer
|
||||
|
||||
//!This class holds the properties of each line of text to be rendered.
|
||||
class TextItem{
|
||||
public :
|
||||
TextItem(float p_x, float p_y, float p_z, QString p_text, QFont font = QFont(), QColor p_color = Qt::black)
|
||||
:x(p_x), y(p_y), z(p_z), m_text(p_text), m_font(font), color(p_color)
|
||||
{
|
||||
QFontMetrics fm(m_font);
|
||||
_width = fm.width(m_text);
|
||||
_height = fm.height();
|
||||
}
|
||||
QString text()const {return m_text;}
|
||||
//!Returns the position of the center of the text, in world coordinates.
|
||||
QVector3D *position(){return new QVector3D(x,y,z);}
|
||||
float width(){return _width;}
|
||||
float height(){return _height;}
|
||||
QFont font(){return m_font;}
|
||||
private:
|
||||
float x;
|
||||
float y;
|
||||
float z;
|
||||
float _width;
|
||||
float _height;
|
||||
QString m_text;
|
||||
QFont m_font;
|
||||
QColor color;
|
||||
};//end class TextItem
|
||||
|
||||
//!This class draws all the textItems.
|
||||
class TextRenderer{
|
||||
public:
|
||||
TextRenderer()
|
||||
{
|
||||
textItems.resize(0);
|
||||
}
|
||||
/*!
|
||||
* Projects each textItem from the world coordinates to the Screen coordinates
|
||||
* and draws it.
|
||||
*/
|
||||
void draw(CGAL::Three::Viewer_interface* viewer);
|
||||
void addText(TextItem* ti);
|
||||
|
||||
private:
|
||||
std::vector<TextItem*> textItems;
|
||||
QOpenGLFramebufferObject *fbo;
|
||||
|
||||
};//end class TextRenderer
|
||||
#endif // VIEWER_H
|
||||
|
|
|
|||
|
|
@ -114,6 +114,7 @@ Polyhedron_scan_OFF<HDS>:: operator()( HDS& target) {
|
|||
scanner.scan_facet_vertex_index( index, i);
|
||||
B.add_vertex_to_facet( index);
|
||||
}
|
||||
//TO DO : Insert read color
|
||||
B.end_facet();
|
||||
scanner.skip_to_next_facet( i);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue