0

I have a situation where in, I need to print dymanic text(updated every 20 ms) on openGL window. I am using QGLWidget, where paintGL method is implemented using native openGL commands. I tried using renderText, but found problem with positioning texts. so I decided to go by render bitmap text approach. For every text to draw I would create an QImage and render this image. Everything works as expected text rendered at the right position in right size. So far so good. But(a big one :P), if i look in to my application memory expansion it grows and grows even when there are no updates to be drawn. I am quite skeptical on bindTexture interface using at dynamic situation. Does compiling image textures could casuse this? Anybody help me understand this issue. And with some possible solutions :)

void DrawText(Pos_st f_img_pos, Rot_st f_img_Rot, Dimensions_st f_Img_Dim, QString Text)
{
   Rot_st f_img_Rot1;
   QImage f_TextImg(fontImageWidth, fontImageHeight,QImage::Format_ARGB8555_Premultiplied);
   QPainter f_Painter(&f_TextImg);
   f_Painter.setCompositionMode(QPainter::CompositionMode_Source);
   f_Painter.setBrush(Qt::transparent);
   f_Painter.fillRect(f_TextImg.rect(), Qt::transparent);
   f_Painter.setPen(QColor(f_Color.g_Red_sfl32 * 255 , f_Color.g_Green_sfl32 * 255 ,  
   f_Color.g_Blue_sfl32 * 255));
   f_Painter.setFont(QFont(Text, f_TextFont_st.g_FontSize_si32,  
   f_TextFont_st.g_FontConst_enm));
   f_Painter.drawText(f_TextImg.rect(), Qt::AlignCenter, Text);
   LoadPicture(f_img_pos, f_img_Rot1, f_Img_Dim, bindTexture(f_TextImg));
}

void LoadPicture(Pos_st f_img_pos, Rot_st f_img_Rot, Dimensions_st f_img_Dim, GLuint f_Img_ID  )
{
    glTranslated( f_img_pos.g_XPOS_sfl32 , f_img_pos.g_YPOS_sfl32 , f_img_pos.g_ZPOS_sfl32 );    
    glRotatef( f_img_Rot.g_Angle_sfl32 , f_img_Rot.g_XROT_sfl32 , f_img_Rot.g_YROT_sfl32 , f_img_Rot.g_ZROT_sfl32 ); 

    glColor4f( 250, 235, 215 , 1.0f );    
    glEnable(GL_BLEND);
    glEnable(GL_TEXTURE_2D);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    glBindTexture(GL_TEXTURE_2D, f_Img_ID );
    glBegin(GL_QUADS);
    glTexCoord2d(0.0,0.0);
    glVertex3f( -f_Img_Dim.g_Img_Width_sfl32/2 , -f_Img_Dim.g_Img_Height_sfl32/2, 0.0f);
    glTexCoord2d(0.0,1.0);
    glVertex3f( -f_Img_Dim.g_Img_Width_sfl32/2 , +f_Img_Dim.g_Img_Height_sfl32/2 , 0.0f);
    glTexCoord2d(1.0,1.0);
    glVertex3f( +f_Img_Dim.g_Img_Width_sfl32/2 , +f_Img_Dim.g_Img_Height_sfl32/2 , 0.0f);
    glTexCoord2d(1.0,0.0);
    glVertex3f( +f_Img_Dim.g_Img_Width_sfl32/2 , -f_Img_Dim.g_Img_Height_sfl32/2 , 0.0f);

    glEnd();
    glFlush( );
        glDisable(GL_TEXTURE_2D);
    glDisable(GL_BLEND);
}
genpfault
  • 47,669
  • 9
  • 68
  • 119
Keen Learner
  • 145
  • 1
  • 11
  • Show us the `LoadPicture` code. – cmannett85 Jun 20 '13 at 12:12
  • I use raw OpenGL calls myself, but don't you have to delete the texture you have created? `bindTexture(..)` returns a `GLuint` for the texture id, I think you are supposed to call `deleteTexture(..)` with it once you are finished. Also `bindTexture(..)` caches the image, so that's presumably why are seeing CPU side memory increases. – cmannett85 Jun 20 '13 at 12:16
  • Thank you for your reply. I tried deleteTexture didnt find any difference with memory status. Is there any other fine approach(or possibility) to edit the pre-compiled texture at the runtime. – Keen Learner Jun 20 '13 at 12:55
  • What about not creating the `f_TextImg` in your draw code? This is something you only need to do once. – Grimmy Jun 20 '13 at 23:32
  • Yes that is what i wanted to do, create f_TextImg once bindtexture once at init. Then later when the text changes is there any possiblity I can edit the texture of f_TextImg. Consider I just need to change the size of the text. Is there a possibility of just changing the texture without compiling it. May be its too crazy idea to have a dynamic texture..!! – Keen Learner Jun 21 '13 at 14:27

0 Answers0