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);
}
4

0 回答 0