57 #include <ACG/GL/acg_glew.hh> 59 #include "TextNode.hh" 60 #include "../Utils/ImageConversion.hh" 76 QFont TextNode::qfont_ = QFont(
"Helvetica", 30);
92 const std::string& _name,
102 blendEnabled_(false),
103 texture2dEnabled_(false),
104 cullFaceEnabled_(false),
105 depthEnabled_(false),
106 alwaysOnTop_(_alwaysOnTop),
108 alphaTestValue_(0.5f),
109 alphaTestFunc_(GL_GREATER),
128 glDeleteBuffers(1, &
vbo_);
222 std::map< char, std::pair<unsigned int, unsigned int> >
225 std::map< char, std::pair<unsigned int, unsigned int> > m;
226 unsigned char c =
' ';
227 for (
unsigned int i = 0; i <
rows_; ++i) {
228 for (
unsigned int j = 0; j <
columns_; ++j, ++c) {
229 m[c] = std::make_pair(j, i);
243 if(_state.compatibilityProfile())
244 enterCompat(_state,_drawmode);
275 if(_state.compatibilityProfile())
276 leaveCompat(_state, _drawmode);
305 if (!
text_.empty()) {
315 glDrawArrays(GL_TRIANGLES, 0,
int(
text_.size() * 6) );
331 quint32 n = num > 0 ? num - 1 : 0;
376 QImage tmp(128, 128, QImage::Format_ARGB32);
379 QPainter tempPainter;
380 tempPainter.begin(&tmp);
381 tempPainter.setRenderHints(QPainter::HighQualityAntialiasing
382 | QPainter::TextAntialiasing);
383 tempPainter.setFont(
qfont_);
384 tempPainter.setPen(
color_);
417 QImage finalImage(imageWidth_,
imageHeight_, QImage::Format_ARGB32);
418 finalImage.fill(Qt::transparent);
422 painter.begin(&finalImage);
423 painter.setRenderHints(QPainter::HighQualityAntialiasing
424 | QPainter::TextAntialiasing);
430 for (
char c =
' '; c <
'~'; ++c) {
431 std::pair<unsigned int, unsigned int> coords =
charToIndex_[c];
432 painter.drawText(coords.first*widthPow2,
imageHeight_ - (coords.second+1)*heightPow2, widthPow2, heightPow2, Qt::AlignLeft | Qt::AlignBottom, QString(c));
437 finalImage = ACG::Util::convertToGLFormat(finalImage);
444 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
445 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
446 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
447 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
448 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, finalImage.width(), finalImage.height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, finalImage.bits());
449 glGenerateMipmap(GL_TEXTURE_2D);
462 if (
text_.size() == 0)
468 qreal pixelHeight = 3.0;
469 qreal pixelWidth = 3.0;
483 for (
unsigned int i = 0; i <
text_.size(); ++i) {
497 if (
text_[i] ==
' ')
501 float right = left + width;
510 const float heightTx = (float) height/ (
float)
imageHeight_;
516 const float rightTx = leftTx + widthTx;
520 const float topTx = bottomTx + heightTx;
581 glGenBuffers(1, &
vbo_);
587 glBufferData( GL_ARRAY_BUFFER_ARB,
vertexBuffer_.size() *
sizeof(GLfloat), 0, GL_DYNAMIC_DRAW_ARB );
592 GLfloat *data =
reinterpret_cast<GLfloat*
>(glMapBuffer( GL_ARRAY_BUFFER_ARB, GL_WRITE_ONLY_ARB ));
596 glUnmapBuffer(GL_ARRAY_BUFFER_ARB);
643 ro.debugName = std::string(
"TextNode: ")+
name();
663 ro.blendSrc = GL_SRC_ALPHA;
676 texture.type = GL_TEXTURE_2D;
677 texture.shadow =
false;
690 ro.setMaterial(&localMaterial);
692 ro.glDrawArrays(GL_TRIANGLES, 0, static_cast<GLsizei>(
text_.size()) * 6);
707 scale = pTrans->
scale()(0,0);
710 pParent = pParent->
parent();
725 scale *= heightUnproj.
length();
bool depthEnabled_
stores if GL_DEPTH_TEST was enabled on entering TextNode
static void enable(GLenum _cap, bool _warnRemoved=true)
replaces glEnable, but supports locking
static QFontMetrics fontMetric_
void initFromState(GLState *_glState)
Initializes a RenderObject instance.
void reset_modelview()
reset modelview matrix (load identity)
static QFont qfont_
font that is used to generate the texture in updateFont()
unsigned pixelSize_
pixelSize of the text for the SCREEN_ALIGNED_STATIC_SIZE mode
static GLuint texture_
handle for the texture into which characters from qfont_ are painted in updateFont() ...
void pop_modelview_matrix()
pop modelview matrix
GLint blendDest_
stores the dfactor parameter of glBlendFunc on entering TextNode
static std::map< char, std::pair< unsigned int, unsigned int > > charToIndex_
maps most readable characters to indices for texture coordinate calculation in updateVBO() ...
static std::map< char, std::pair< unsigned int, unsigned int > > createMap()
void draw(GLState &_state, const DrawModes::DrawMode &_drawMode) override
draw Text
void addTexture(const Texture &_t)
adds a texture to stage RenderObjects::numTextures()
std::string name() const
Returns: name of node (needs not be unique)
Namespace providing different geometric functions concerning angles.
static bool initialised_
this is used to ensure that the texture is only generated once when necessary
void leave(GLState &_state, const DrawModes::DrawMode &_drawmode) override
restore texture and drawing states
void applyScreenAligned(GLState &_state)
modifies _state so that the modelviewmatrix will be screenaligned. remember to call "_state...
Vec3d project(const Vec3d &_point) const
project point in world coordinates to window coordinates
void setFont(const QFont &_font)
sets the font to be used for generating a texture with most characters of the chosen font ...
void baseColor(const Vec4f &_c)
set the base color (Sets the baseColor which is the same as the emission(const Vec4f& _c) ) ...
static void bindTexture(GLenum _target, GLuint _buffer)
replaces glBindTexture, supports locking
ShaderGenDesc shaderDesc
Drawmode and other shader params.
void unbindVBO()
unbinds vbo_
Text will always stay parallel to screen.
void scale(double _s)
scale by (_s, _s, _s)
void bindVBO()
binds vbo_ and sets the necessary OpenGL states
GLuint vertexBuffer
VBO, IBO ids, ignored if VAO is provided.
static void texcoordPointer(GLint _size, GLenum _type, GLsizei _stride, const GLvoid *_pointer)
replaces glTexcoordPointer, supports locking
static void vertexPointer(GLint _size, GLenum _type, GLsizei _stride, const GLvoid *_pointer)
replaces glVertexPointer, supports locking
void setSize(const double _size)
sets the size by which the quads displaying the text will be scaled
double size_
scaling factor by which the quads in vbo_ are scaled
Vec3d unproject(const Vec3d &_winPoint) const
unproject point in window coordinates _winPoint to world coordinates
void ambientColor(const Vec4f &_a)
set the ambient color.
void push_modelview_matrix()
push modelview matrix
TextMode textMode_
current display mode of text_ (SCREEN_ALIGNED, SCREEN_ALIGNED_STATIC_SIZE or OBJECT_ALIGNED) ...
void diffuseColor(const Vec4f &_d)
set the diffuse color.
static void disable(GLenum _cap, bool _warnRemoved=true)
replaces glDisable, but supports locking
static quint32 nearestPowerOfTwo(quint32 num)
returns the nearest greater power of 2 to num
void addElement(const VertexElement *_pElement)
bool blendEnabled_
stores if GL_BLEND was enabled on entering TextNode
static void disableClientState(GLenum _cap)
replaces glDisableClientState, supports locking
void boundingBox(Vec3d &_bbMin, Vec3d &_bbMax) override
update bounding box
GLint blendSrc_
stores the sfactor parameter of glBlendFunc on entering TextNode
float lastScale_
stores the last scaling factor the text computed to SCREEN_ALIGNED_STATIC_SIZE
bool cullFaceEnabled_
stores if GL_CULL_FACE was enabled on entering TextNode
static void enableClientState(GLenum _cap)
replaces glEnableClientState, supports locking
BaseNode * parent()
Get the nodes parent node.
const VertexDeclaration * vertexDecl
Defines the vertex buffer layout, ignored if VAO is provided.
static const unsigned int columns_
number of columns of characters in the texture
static int imageWidth_
width of the generated texture
DrawMode POINTS
draw unlighted points using the default base color
static void blendFunc(GLenum _sfactor, GLenum _dfactor)
replaces glBlendFunc, supports locking
bool alwaysOnTop_
stores if text should be drawn always on top
void setPixelSize(const unsigned int _size)
sets the pixelsize of the text (only available for the SCREEN_ALIGNED_STATIC_SIZE mode and only works...
virtual void addRenderObject(RenderObject *_renderObject)
Callback for the scenegraph nodes, which send new render objects via this function.
TextNode(BaseNode *_parent=0, const std::string &_name="<TextNode>", TextMode _textMode=SCREEN_ALIGNED, bool _alwaysOnTop=false)
void setText(std::string _text)
sets the string that will be rendered
int priority
Priority to allow sorting of objects.
std::vector< GLfloat > vertexBuffer_
buffer of vertex coordinates and texture coordinates of the quads
auto length() const -> decltype(std::declval< VectorT< S, DIM >>().norm())
compute squared euclidean norm
void getRenderObjects(ACG::IRenderer *_renderer, ACG::GLState &_state, const ACG::SceneGraph::DrawModes::DrawMode &_drawMode, const ACG::SceneGraph::Material *_mat) override
set RenderObject for Shader pipeline renderer
DrawMode POINTS_COLORED
draw colored, but not lighted points (requires point colors)
static const unsigned int rows_
number of rows of characters in the texture
void specularColor(const Vec4f &_s)
set the specular color
const GLMatrixd & modelview() const
get modelview matrix
void setRenderingMode(TextMode _textMode)
static void bindBufferARB(GLenum _target, GLuint _buffer)
same function as bindBuffer
void enter(GLState &_state, const DrawModes::DrawMode &_drawmode) override
set texture and drawing states
TextMode renderingMode()
returns the rendering mode (SCREEN_ALIGNED or OBJECT_ALIGNED)
bool alwaysOnTop()
returns wheter always on top is setted or not
void setAlwaysOnTop(bool _alwaysOnTop)
draw the text always on top
GLenum blendDest
glBlendFunc: GL_SRC_ALPHA, GL_ZERO, GL_ONE, GL_ONE_MINUS_SRC_ALPHA ...
DrawMode POINTS_SHADED
draw shaded points (requires point normals)
ACG::VertexDeclaration vertexDecl_
stores the vertex declaration
DrawModes::DrawMode availableDrawModes() const override
return available draw modes
static int imageHeight_
height of the generated texture
Interface class between scenegraph and renderer.
static void bindBuffer(GLenum _target, GLuint _buffer)
replaces glBindBuffer, supports locking
void translate(double _x, double _y, double _z, MultiplyFrom _mult_from=MULT_FROM_RIGHT)
translate by (_x, _y, _z)
std::string text_
text to be displayed on quads in vbo_
static void activeTexture(GLenum _texunit)
replaces glActiveTexture, no locking support
static QColor color_
color that is used to draw the characters into the texture in updateFont()
VectorT< double, 3 > Vec3d
GLMatrixd modelview
Modelview transform.