Results 1 to 12 of 12

Thread: About QGLWidget::renderText

  1. #1
    Join Date
    Jan 2006
    Posts
    26
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Exclamation About QGLWidget::renderText

    Hi,all
    Here is my problem about renderText(). As we all know,the QGLWidget int Qt is very convience for us to write OpenGL command. Now I have to annotate some text on the GL scence and I want to use renderText() like the following attached image(please click on it). Who can give me some good advices about it. Thanks a lot!
    Attached Images Attached Images
    • File Type: bmp 1.bmp (6.7 KB, 160 views)
    Last edited by showhand; 18th January 2006 at 08:41.
    There is no secret in the face of the code.

  2. #2
    Join Date
    Jan 2006
    Location
    Paris, France
    Posts
    227
    Thanks
    3
    Thanked 21 Times in 21 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: About QGLWidget::renderText

    Hello,

    Well this method is quite simple to use, you just have to create a QString containing your text,
    reshape it with a QFont....and place it in the scene

    I see in your image that it must be vertical, so, you can use the second method, with 3 parameters for coordinates...

    These coordinates are relative to the current transformations applied to the projection matrix, and you could do something like this :

    glPushMatrix();
    glRotatef(90, 0, 0, 1);
    renderText(x, y, z, QString("My Text"), ...)
    glPopMatrix();

    I haven't written OpenGL for ages, so there may be some syntax errors

    Does that help ?

    Guilugi.

  3. #3
    Join Date
    Jan 2006
    Posts
    26
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: About QGLWidget::renderText

    That's a good idear! Thank you very much! I'll try it at once. But now, I have another problem about renderText() and glCallList().Please look at my following code:

    void NgiDrawWiggle::initializeGL()
    {
    z=(this->h/2)/(tan((45.0/2.0)*(3.1415926/180.0)))+0.5;
    glShadeModel( GL_SMOOTH );
    glClearColor( 1.0, 1.0, 1.0, 0.0 );
    glClearDepth( 1.0 );
    glDisable( GL_DEPTH_TEST );
    glHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST );
    }
    void NgiDrawWiggle::paintGL()
    {
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glCallList(objectRectRegion);
    drawText("ffffffffffff");
    glColor3ub(0,255,0);
    renderText(170,140,"111");
    glColor3ub(0,255,255);
    renderText(100,150,"222");
    drawText("ggggg");

    }
    void NgiDrawWiggle::resizeGL(int width,int height)
    {
    if ( height == 0 )
    {
    height = 1;
    }
    glViewport( 0, 0, (GLint)width, (GLint)height );
    glMatrixMode( GL_PROJECTION );
    glLoadIdentity();
    gluPerspective( 45.0, (GLfloat)width/(GLfloat)height, 0.1, 1000 );//
    glMatrixMode( GL_MODELVIEW );
    }
    void NgiDrawWiggle::drawText(QString str)
    {
    glColor3ub(1,10,10);
    this->renderText(10,10,str);
    }
    GLuint NgiDrawWiggle::drawRectRegion()
    {
    GLuint list = glGenLists(1);
    glNewList(list,GL_COMPILE);
    glLoadIdentity();
    glTranslatef( -w/2, -h/2, -z );
    glBegin(GL_LINES);
    glVertex3f(w/10,5,0);
    glVertex3f(9*w/10,5,0);
    glVertex3f(9*w/10,5,0);
    glVertex3f(9*w/10,7*h/10,0);
    glVertex3f(9*w/10,7*h/10,0);
    glVertex3f(w/10,7*h/10,0);
    glVertex3f(w/10,7*h/10,0);
    glVertex3f(w/10,5,0);
    glEnd();
    glEndList();
    return list;
    }
    void NgiDrawWiggle::startDrawWiggle()
    {
    z=(this->h/2)/(tan((45.0/2.0)*(3.1415926/180.0)))+0.5; //弧度运算
    objectRectRegion=drawRectRegion();
    updateGL();
    }
    void main(void)
    {
    NgiDrawWiggle* p=new NgiDrawWiggle();
    p->startDrawWiggle();
    }
    Question:Look at paintGL(),both drawText() do not work, so the scene show "111" and "222" at the valid position. But when I glCallList() at last(ie. all the drawText and renderText before glCallList), all the string can be shown.why? I'm very perplex about it. Thanks for your help!
    There is no secret in the face of the code.

  4. #4
    Join Date
    Jan 2006
    Location
    Paris, France
    Posts
    227
    Thanks
    3
    Thanked 21 Times in 21 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: About QGLWidget::renderText

    Well, maybe that's because you reset your matrix with glLoadIdentity() in your display list,
    and it messes up coordinates for your renderText & drawText calls...

    I'm sorry, but I have no time to test something now...

    Good luck

    Guilugi.

  5. #5
    Join Date
    Jan 2006
    Posts
    26
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: About QGLWidget::renderText

    Hi,thank you for your help firstly.This is still the first problem for me.Could you please give me detailed information about the second method of renderText(). The parameter "z" puzzle me .I have tried the method that you told me yesterday and the coordinates rotated indeed,but the direction of the text was still horizontal (ie. not vertiacal) and its position changed as the coordinates were rotated. Can you help me again,thank you!
    Last edited by showhand; 19th January 2006 at 03:45.
    There is no secret in the face of the code.

  6. #6
    Join Date
    Jan 2006
    Location
    Paris, France
    Posts
    227
    Thanks
    3
    Thanked 21 Times in 21 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: About QGLWidget::renderText

    Well, 'z' is the third dimension of the space, the depth of your scene.

    In the small code I posted earlier, I did a rotation around this z-axis, to have the x-axis vertical and the y-axis horizontal...to have the text rendered vertical.

    That's strange it doesn't work...
    Can you post me a full sample of code I could compile and debug ?

    Guilugi.

  7. #7
    Join Date
    Jan 2006
    Posts
    26
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: About QGLWidget::renderText

    Sure,following are complete code, plese help me !
    Qt Code:
    1. draw.h
    2. #include<QtOpenGL>
    3. #include<QString>
    4. class Draw:public QGLWidget
    5. {
    6. public:
    7. Draw(QWidget* parent=0);
    8. Draw(void);
    9. void drawText(QString,int,int);
    10. protected:
    11. void initializeGL();
    12. void paintGL();
    13. void resizeGL(int width,int height);
    14. }
    15. draw.cpp
    16. #include "draw.h"
    17. void NgiDrawWiggle::initializeGL()//called firstly
    18. {
    19. z=(this->h/2)/(tan((45.0/2.0)*(3.1415926/180.0)))+0.5;
    20. glShadeModel( GL_SMOOTH );
    21. glClearColor( 1.0, 1.0, 1.0, 0.0 );
    22. glClearDepth( 1.0 );
    23. glDisable( GL_DEPTH_TEST );
    24. // glDepthFunc( GL_LEQUAL );
    25. glHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST );
    26. }
    27. void NgiDrawWiggle::paintGL()
    28. {
    29. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    30. glColor3ub(0,10,250);
    31. drawText("Time",-65,(50-7*h)/20.0);
    32. }
    33. void NgiDrawWiggle::resizeGL(int width,int height)
    34. {
    35. if ( height == 0 )
    36. {
    37. height = 1;
    38. }
    39. glViewport( 0, 0, (GLint)width, (GLint)height );
    40. glMatrixMode( GL_PROJECTION );
    41. glLoadIdentity();
    42. gluPerspective( 45.0, (GLfloat)width/(GLfloat)height, 0.1, 1000 );//
    43. glMatrixMode( GL_MODELVIEW );
    44. }
    45. void Draw::drawText(QString str,int x,int y)
    46. {
    47. glLoadIdentity();
    48. glTranslatef(30.0,30.0,-z);//"z" is the depth of the scene through the "z=(this->h/2)/(tan((45.0/2.0)*(3.1415926/180.0)))+0.5","h" is the height of the scene.
    49. glRotatef(90,0,0,1);
    50. renderText(x,y,0,str);
    51. }
    To copy to clipboard, switch view to plain text mode 
    I really don't know what I should do in the drawText(),thanks for your helping. Would you please give the complete debugged code?By the way, can I use "show list" in which renderText() is included?
    Last edited by showhand; 20th January 2006 at 09:19.
    There is no secret in the face of the code.

  8. #8
    Join Date
    Jan 2006
    Location
    Paris, France
    Posts
    227
    Thanks
    3
    Thanked 21 Times in 21 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: About QGLWidget::renderText

    Okay,

    So a did some modifications to your code in order to compile it...
    Strangely, I can't see any string drawn...I have to check all the code but I can't do it now

    Meantime, did you solve you problem ?

    Guilugi.

  9. #9
    Join Date
    Jan 2006
    Posts
    26
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: About QGLWidget::renderText

    Hi, thank you for your help these days. I have still not solve my problem. Would you please check my all code which I sent you some days ago. I was perplexed about the method. I will wait for your replying for ever. Would you mind telling me your email and I think I could send the message about other questions. Thank you !
    There is no secret in the face of the code.

  10. #10
    Join Date
    Jan 2006
    Location
    Paris, France
    Posts
    227
    Thanks
    3
    Thanked 21 Times in 21 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: About QGLWidget::renderText

    Sure,

    (One of) my e-mail addresses : guiluge@hotmail.com
    If you use MSN, you can add, me it will be easier to talk

    Good luck, I'll keep you in touch

    Guilugi.

  11. #11
    Join Date
    Jan 2006
    Posts
    26
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Thumbs up Re: About QGLWidget::renderText

    Hi, I'm so sorry for not keeping touch you because of some reasons these days. This is my MSN: ccc_xiaohan@hotmail.com. I'm afraid we have different time because you are in France and I am in China. But I'll try my best to keep touch with you as possible as I can.
    Thank you.
    There is no secret in the face of the code.

  12. #12
    Join Date
    Jan 2006
    Location
    Boston, MA
    Posts
    40
    Thanks
    1
    Thanked 6 Times in 6 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: About QGLWidget::renderText

    What's in the result, guys ?

Similar Threads

  1. Qt3 -> Qt4 QGLWidget::renderText problem
    By cometlinear in forum Qt Programming
    Replies: 6
    Last Post: 1st October 2006, 02:52

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.