PDA

View Full Version : QtOpenGL how to draw text?



AndreaCe
22nd July 2009, 01:50
I extended QGLWidget class and then i have reimplement the three virtual method (init, paint and update) to perform the typical OpenGL tasks.

I created also another class Cylinder. That class have a draw() method that display a typical cylinder. But i need to have a lot of cylinders, so i decided to have a vector of Cylinder (QVector<Cylinder*>).
When i pushed all cylinders in the Vector i iterate on the vector, like this:

for(...){
figureID = glGenLists(1);
fFiguresID.append(figureID);
glNewList(figureID, GL_COMPILE);
{
Cylinder->draw(parent);
}
glEndList();
}

so i create a new vector of int that contain the figure ID. At the and in my GLWidget class i iterate on my figures ID vector and i call the method: glCallList(figureID).

I works well, but now i want to drow also some text near the cylinder. I try to use QGLWidget::renderText(...) but it works just in a subclass of QGLWidget. I can't call this method in my Cylinder class. Another problem is that QGLWidget::renderTet(...) already use a glCallList(...).
How can i draw text near my cylinder? I wold like to insert the code to draw the text in the method: Cylinder::draw(), how can i do it?

Maybe there is some possibility with the basic OpenGL functions?

Someone can help me?

P.S.
I'm sorry for my english