View Full Version : Qt3 -> Qt4 QGLWidget::renderText problem

25th September 2006, 08:53
Hi all,

Over the weekend, I ported my OpenGl application from Qt3 to Qt4. Everything went fine, except that renderText is now rendering the text *behind* my geometry in the projection matrix (perspective). I am still only passing the X and Y coordinates to the function. Again, I did not change anything from Qt3 to Qt4.

Has anyone experienced this? Anyone know the solution? The relevant code is pasted below.

Thanks!! Kindest regards,

//render some text
//lighting should be disabled before calling this
//or we won't be able to set the color
//disable textures
QFont my_font("Arial");
//this is a required bug-fix
my_font.setStyleHint(QFont::AnyStyle, QFont::PreferBitmap);
glColor4f(1.0, 1.0, 1.0, 1.0);

//if they are viewing the earth/moon system
//from perspective view then show a label
if(view == 1){
renderText(27, 27, "The Earth & Moon from Perspective", my_font);

//if they are viewing the earth and moon from the sun
if(view == 2){
renderText(27, 27, "The Earth & Moon from the Sun", my_font);

//if they are viewing the moon from earth
//then iterate through the moon_coord_array
if(view == 3){

//render a label
renderText(27, 27, "The Moon from the Earth", my_font);

//now make the font size smaller

for(int i=0; i<coord_array_index; i++){
double my_x = moon_coord_array[i].getX();
double my_y = moon_coord_array[i].getY();
QString my_label = moon_coord_array[i].getLabel();
renderText(my_x, my_y, my_label, my_font);

//if they are viewing the earth from the moon
if(view == 4){
renderText(27, 27, "The Earth from the Moon", my_font);

//re-enable lighting
//enable textures

25th September 2006, 13:14
Everything went fine, except that renderText is now rendering the text *behind* my geometry in the projection matrix (perspective).

Are you calling renderText() before or after calling your other display lists??

26th September 2006, 02:57
Hey there,

Thanks for replying.

This app does not use any display lists. Do you think that will solve this problem?

I didn't need a display list when this app ran on Qt3, and it worked fine.

Thanks again!! Kindest regards,

26th September 2006, 02:59
By the way, I should point out that I do call rendertext before I draw any geometry. I didn't think that should matter anyway, since without a Z parameter, renderText should just print on top of everything else.



26th September 2006, 11:45
If you aren't using display lists, then its like drawing in immediate mode.

Then the order certainly matters. Try changing the order of drawing.

28th September 2006, 05:06
Thanks, and I will try that.

But it still doesn't explain the problem, does it? Isn't renderText supposed to draw on top of everything if no Z parameter was passed?

And, can someone confirm that renderText did indeed change in Qt4? Becuase, again, the app was working fine in Qt3, and the OpenGL code was not changed.

Thanks again!! best regards,

1st October 2006, 02:52
Hi all,

I solved this: it was becuase I had depth testing enabled.

I don't know why it worked for Qt3 and not Qt4, but anyway, it's solved now.

Thanks again for the help!! Kindest regards,