PDA

View Full Version : problem about renderText



tyzhang3
30th August 2007, 01:48
hi:

I used two qglwidget in my mainwindow. And I invoked renderText in both of the qglwidget. But in one of the qglwidget, I just cannot change the color of text. Could you please help me?

Code like below:


void VARDrawer::DrawLabel()
{
setting->ValidateLabels();
glLineWidth(1.2f);
glColor4f(1.0f,0.0f,0.0f,1.0f);:confused:Do not work here

map<int,TextureSetting*>::iterator mi;
for (mi = setting->varMap.begin();
mi != setting->varMap.end() ; mi++)
{
TextureSetting* texSetting = mi->second;
if (texSetting->isDrawLabel)
{

QString label(texSetting->srcDim->GetDimensionName().c_str());
Vec3 pos = Vec3(texSetting->blockPos.X,
texSetting->blockPos.Y+texSetting->VisSize.height+0.02f,
0.0f);

renderText(pos.X, pos.Y,0.0f,
texSetting->srcDim->GetDimensionName().c_str());

}
}
}
void PareCoordDrawer::DrawAxisLabel(void)
{
setting->ValidateAxisLabel(dataSet);
glLineWidth(1.2f);
qglColor(Qt::red);
QVector<float>::iterator qli;
QList<string>::iterator qsli;
for (qli = setting->axisPos.begin(), qsli = setting->labelList.begin();
qli != setting->axisPos.end(); qli++, qsli++)
{
float pos = *qli;
string dimName = *qsli;
renderText(pos, 1.05f, 0.0f, dimName.c_str());:o Every thing just fine here
}
}


Thanks,
zhang

wysota
19th September 2007, 10:52
Did you try using qglcolor() instead?

ntp
19th September 2007, 17:45
I was also having trouble with renderText. I talked to Trolltech and they said:


Note that renderText() will often have a different color than you expect
since it calls "glDisable(GL_LIGHTING)".

I was having trouble with the color when it was inside of a glCallList. However, I don't do anything with lighting so I am not sure why glCallList was affecting it.

ToddAtWSU
19th September 2007, 20:58
I haven't worked with OpenGL display lists in a while, but if I remember correctly, you can only set the color once for a display list, and that is upon creation of the display list. Every time you call glCallList( ) it will use the color that the object used upon the creation of the display list, not whatever color you try to set for it. So in order to change you color of your display list, you would have to destroy the current display list and create a new one with the new color. If this color changes many times, display lists would then not be the way you would want to handle your situation. But if you only change the color once or twice throughout the execution of the program, display lists would be okay to use.

ntp
19th September 2007, 21:35
Thanks, I was setting the color in the glCallList and it still would not always be the color that I set it (I tried both qglColor and the gl color call). RenderText calls its own glCallList so I wonder if that had something to do with it (though calling glCallLists within glCallLists is allowed and should work).