PDA

View Full Version : Displaying text on a bitmap



sappy
04-21-2005, 12:43 AM
I am trying to display some text on a loaded bitmap. I tried all possible things I can think of but nothing helped me. Herebelow I show you briefly how I am trying to do it:

// Loaded the image...
load_image("***.bmp");

// Build Font

HFONT font;
HFONT oldfont;
base = glGenLists(96);
font = CreateFont(-24, 0, 0, 0, FW_BOLD, FALSE,
FALSE, FALSE, ANSI_CHARSET, OUT_TT_PRECIS,
CLIP_DEFAULT_PRECIS, ANTIALIASED_QUALITY,
FF_DONTCARE|DEFAULT_PITCH, "Courier New");

oldfont = (HFONT)SelectObject(hDC, font);
wglUseFontBitmaps(hDC, 32, 96, base);
SelectObject(hDC, oldfont);
DeleteObject(font);
glListBase(base - 32);
while(1){
DrawGLScene();
}
...
...
...

DrawGLScene(){
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glTranslatef(0.0f,0.05f,-7.5f);
glBindTexture(GL_TEXTURE_2D, texture[0]);

//////// Part A ///////////
glBegin(GL_QUADS);
glTexCoord2f(0.0f, 0.0f);
glVertex3f(-4.0f, -4.55f, 0.0f);
glTexCoord2f(1.0f, 0.0f);
glVertex3f( 4.0f, -4.55f, 0.0f);
glTexCoord2f(1.0f, 1.0f);
glVertex3f( 4.0f, 3.05f, 0.0f);
glTexCoord2f(0.0f, 1.0f);
glVertex3f(-4.0f, 3.05F, 0.0f);
glEnd();
///////////////////////////

/////// PART B ////////////
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
gluOrtho2D(0.0, 8.0, 6.0, 0.0);
glPushAttrib(GL_LIST_BIT | GL_LIGHTING_BIT);
glDisable(GL_LIGHTING);
glListBase(base);
glColor3f(1.0, 0.0, 0.0);
glRasterPos2i(1, 1);
glCallLists(6, GL_UNSIGNED_BYTE, "a");
glPopAttrib();
glPopMatrix();
glPopMatrix();
SwapBuffers(hDC);
/////////////////////////////

Now I noticed one weired thing happening in my code. When I have both 'PART A' and 'PART B' in my code, the output is a black screen with a letter 'Q' displayed at the raster position rather then 'a'... :(

The same thing happens when I comment 'PART A' and just have 'PART B' in my code.

When I have 'PART A' in the code and comment out 'PART B', the output just showes me the bitmap loaded and does not have the letter displayed.

Can anyone help me with this. Any kind of help with be highly appreciated.

Thanks.
Sappy

p55dom
04-21-2005, 01:22 AM
are u trying to put the text on top of the bitmap or on the gl window screen.
if its on the bitmap;just right on the bitmap using paint and if the text is changing im not so sure.
if its on the screen; it might be the order that u hav drawn your shapes on the screen, as i had that problem with my project, it had 2 shapes, a bitmap and text, and i had to alter the order that they were being drawn down at the bottom of the code in the WINAPI section where it says

drawglscene();

after the bit about

TranslateMessage(&msg);
DispatchMessage(&msg);

i could send u an email of my code if u like, to show u what parts it is.

obirsoy
04-21-2005, 04:58 AM
In your "PART B", you switch to MODELVIEW, change it, switch to PROJECTION, change it, and start drawing (note you do your drawing in PROJECTION mode), and you call 2 glPopMatrix while you are in PROJECTION.
My advice is reverse the order of matrix state changes. First change the PROJECTION, then the MODELVIEW, draw your scene, pop MODELVIEW matrix, switch to PROJECTION, pop it and switch back to MODELVIEW. This last switch to MODELVIEW is required because, as far as I can understand your DrawGLScene() depends on the matrix state to be in MODELVIEW. This should fix "PART A" not showing while "PART B" active. A little advice you should check for errors (ie glGetError) at least once at the end of your frame.

And "a" => "Q" issue, glCallList's first parameter should be the length of your string (length of "a" is not 6). Although you should see some garbage starting with "a". But try fixing these problems and see what happens.

sappy
04-21-2005, 08:44 AM
Thanks obirsoy and p55dom for all your help. But I think the suggestion of obirsoy to switch between PROJECTION and MODELVIEW worked for me. But still the problem with displaying of the string stays. Now I am trying to display a string "Hello" with the first parameter of glCallLists function as 6 but still it just prints "h" and "1" displays "Q" for length 1.

So please if you can also suggest me something about that.

Thanks.
Sappy.

obirsoy
04-21-2005, 10:20 AM
I think glListBase(base) in "PART B", should be glListBase(base-32).