View Full Version : Problem in displaying text

10-16-2011, 07:05 AM
Dear Friends
I am finding some difficulty in displaying the text in properposition mean at proper coordinate position. I am using bitmap fonts.. Using nehe tutorials I am able to draw a text. but now I want customize the text. Basically I want to display X, Y, Z at x=10, y=10 and z=10 location. I have an axes xyz threee lines I have already drawn.

For that I am doing like this.

glRasterPos3f(10.0f, 0.0f, 0.0f);
glRasterPos3f(0.0f, 10.0f, 0.0f);
glRasterPos3f(0.0f, 0.0f, 10.0f);

But I can see XYandZ all are coming at (10,0,0) position....Y and Z shoulb be at 0,10,0 and 0,0,10 respectively. Please help me someone whats going wrong in this.

My glPrint is like this
GLvoid CRevolutionProjView::glPrint(const char *fmt, ...) // Custom GL "Print" Routine
CDC* pDC = GetDC();
wglMakeCurrent(pDC->m_hDC, m_hrc);
char text[256]; // Holds Our String
va_list ap; // Pointer To List Of Arguments

if (fmt == NULL) // If There's No Text
return; // Do Nothing

va_start(ap, fmt); // Parses The String For Variables
vsprintf(text, fmt, ap); // And Converts Symbols To Actual Numbers
va_end(ap); // Results Are Stored In Text

glPushAttrib(GL_LIST_BIT); // Pushes The Display List Bits
glListBase(base - 32); // Sets The Base Character to 32
glCallLists(strlen(text), GL_UNSIGNED_BYTE, text); // Draws The Display List Text
glPopAttrib(); // Pops The Display List Bits

and I am creating font like this....
GLvoid CRevolutionProjView::BuildFont(GLvoid) // Build Our Bitmap Font
CDC* pDC = GetDC();
wglMakeCurrent(pDC->m_hDC, m_hrc);

HFONT font; // Windows Font ID
HFONT oldfont; // Used For Good House Keeping

base = glGenLists(96); // Storage For 96 Characters

font = CreateFont( -24, // Height Of Font
0, // Width Of Font
0, // Angle Of Escapement
0, // Orientation Angle
FW_BOLD, // Font Weight
FALSE, // Italic
FALSE, // Underline
FALSE, // Strikeout
ANSI_CHARSET, // Character Set Identifier
OUT_TT_PRECIS, // Output Precision
CLIP_DEFAULT_PRECIS, // Clipping Precision
L"Courier New"); // Font Name

oldfont = (HFONT)SelectObject(pDC->m_hDC, font); // Selects The Font We Want
wglUseFontBitmaps(pDC->m_hDC, 32, 96, base); // Builds 96 Characters Starting At Character 32
SelectObject(pDC->m_hDC, oldfont); // Selects The Font We Want
DeleteObject(font); // Delete The Font

I am calling BuildFont in PrepareScene like this

void CRevolutionProjView::PrepareScene(CDC *pDC)
wglMakeCurrent(pDC->m_hDC, m_hrc);
glClearColor (0.0, 0.0, 0.0, 1.0);
wglMakeCurrent(NULL, NULL);

Please tell me why they'are not coming at their proper positions. How can I achieve this. Thanks a lot in advance for the reply. Thanks Sujan

10-16-2011, 11:44 AM
You have missed from your post perhaps the most important thing - the conents of each displaylist.

Is glRasterPos realy the right command?
Here's part of the definition of the command:

OpenGL maintains a 3-D position in window coordinates. This position, called the raster position, is maintained with subpixel accuracy. It is used to position pixel and bitmap write operations. See glBitmap, glDrawPixels, and glCopyPixels.

So instead try glTranslatef to position your text.

10-16-2011, 11:52 AM
glTranslatef is not working either. I have tried glTranslatef nothing happening with that. Please whatelse I can do for this. Thanks Sujan

10-16-2011, 12:38 PM
Like I said really. What's in the display list?
Did you use glVertex2f to draw a quad per text character?
If so then glTranslatef will work as that's how 99% of gl programs are written.

10-17-2011, 12:06 AM
No I am not using glVertex2f

glCallLists(strlen(text), GL_UNSIGNED_BYTE, text); // Draws The Display List Text

this is how I am displaying the text.
Thanks for your help. My problem is resolved now. I am calling glRasterPosf() inside glPrint() just before glCallLists(). So now I need to write three separate api glPrintX() with x position, glPrintY() with y position and glPrintZ() with z position. Then I call separately them in the paint() function. Its now displaying 3 legends at their respective positions. Thanks a lot for your help.

10-17-2011, 05:04 AM
Like I said really. What's in the display list?
Did you use glVertex2f to draw a quad per text character?
If so then glTranslatef will work as that's how 99% of gl programs are written.

wglUseFontBitmaps generates the display lists.
It probably call glBitmap or glDrawPixels.
So the function to use is glColor (to setup the color) followed by glRasterPos and then glCallList.