
wglUseFontBitmaps- Please help
I''m new to OpenGL and need some help...
i''ve got a 3D environment with an object drawn in the center...the object can be rotated by mouse clicking and dragging...rotated along the z-axis by scrolling up and down the mouse-scroll if they have one or through options...to increase scale i''ve got it rigged to increase by a proportional increment the X,Y and Z values...
the problem:
i need text in the top left hand corner of the window to display relevant textual information about the object being drawn without the object overlapping and concealing the text (which happens because the object can be rotated if i allow the Z scale to be defaulted to 0)...i''m using wglUseFontBitmaps to do it, however, when the window is sized, the text gets bumped off the screen because i''m drawing the text in front of the object, or literally, i''m trying to draw the object in the top left hand corner of the viewport (in 3D space, i''m 4 spaces away from the object with .1 for the front display cut off point...so i''m drawing my text at 3.89 Z scale, and then trying to proportionately put the text in the top left corner so that despite sizing of the viewport, it stays in the top left)
the code i have so far keeps the X value in the right spot nearly perfectly (very very very little shifting of the X position as the screen is sized)
the code:
wglUseFontBitmaps(m_pCDC->GetSafeHdc(), 0, 256, 1000);
// The line below is almost exactly where i want the text to stay at despite sizing, but sizing totally screws it up
// glRasterPos3f(-0.09f, 0.035f, 3.89f);
double pd[4];
glGetDoublev(GL_VIEWPORT, pd);
// raster position below positions X value almost perfectly, despite tweaking of the "magic" number -0.355 to position the text in the top left corner
glRasterPos3d((((0.1111111 * pd[2]) / pd[3]) * -0.355), 0.035, 3.89f);
// set up for a string-drawing display list call
glListBase(1000);
// draw a string using font display lists
glCallLists(strlen(MyOutputString), GL_UNSIGNED_BYTE, MyOutputString);
thanks for the help

ugh. hardcoding those numbers is painful. might i suggest:
- use an independent ortho matrix for text. keep the width constant and adjust the height using your window aspect ratio (rc.right-rc.left)/(rc.bottom-rc.top).
- use GetTextExtentPoint32 to determine how big your text is.
- do a rc.right-sz.cx-spacing to find out where you should start drawing your text so that you have ''spacing'' between end of text and right screen edge.
i suppose that will work?
- use an independent ortho matrix for text. keep the width constant and adjust the height using your window aspect ratio (rc.right-rc.left)/(rc.bottom-rc.top).
- use GetTextExtentPoint32 to determine how big your text is.
- do a rc.right-sz.cx-spacing to find out where you should start drawing your text so that you have ''spacing'' between end of text and right screen edge.
i suppose that will work?
I'm willing to give it a try...but i'm a bit confused by the Ortho matrix stuff...i've tried instatiating a 2D ortho "on top" of my 3D viewport..but when i do, it seems to be wiping my 3d image, then i only have text...
does the width of the text affect its relative position on the screen? i thought the width and height were referring to the size of the font not the screen position...if i'm wrong that may be a huge part...
i've only got patchwork knowledge of OpenGL (that and what i can glean from online/hard copy books)
[edited by - cxx on August 7, 2002 12:50:38 PM]
does the width of the text affect its relative position on the screen? i thought the width and height were referring to the size of the font not the screen position...if i'm wrong that may be a huge part...
i've only got patchwork knowledge of OpenGL (that and what i can glean from online/hard copy books)
[edited by - cxx on August 7, 2002 12:50:38 PM]
I know exactly where the first problem probably is. Chances are that, when you swapped over to the ortho layer, you used glClear on the color buffer and depth buffer. When you clear the buffer, it works on the HDC, and will erase it for anything using that HDC that you specify. Clearing the color buffer erased all the pixels you drew. Take off the color buffer erasing part but keep the depth buffer erasing to keep the image intact but force everything new to be in the front of that image. See NeHe''s code on overlays. (It''s only under the news area, I think.) I helped him with this version of layer work, so if you have any questions on this method, feel free to ask me.
man, i really like that green smiley face with the confused eyes...that''s been my expression throughout my OpenGL experience 
i guess i should let you know a bit more about my code...it''s an MDI app (MFC generated) that''s OpenGL enabled (i used code from Alasandro Falapa''s (probably spelled that wrong) CGLEnabledView which he posted on www.codeguru.com to create an MFC app that uses openGL drawing code to render the contents (if not the entire) window (i''m not entirely sure...))
so my drawing commands are broken up among a couple of functions...but in a nut shell, you do most of the drawing under the OnDrawGL function...which is called in the base class from the OnDraw command and then the HDC is gathered, GL commands are all taken care of (oddly enough, i''ve never seen an Ortho call in all of his code...so my ortho call was just before i drew my scene (i don''t even use a flush command, i use a glFinish() which i understand is the same, but maybe a bit slower than a glFlush() since i''m not on a network...dunno, but i only use 1 glFinish...should i be using more?)
i guess, in a nut shell...what i''m trying to do is replicate a GDI call...if you use
cDC->textout(3, 10 , 10, "doh");
no matter how you size the screen, it stays at (10,10) which is the behavior i want from my text with the benefits of the double buffering...is there a way to get the GDI call to be double buffered?
or is there code that converts the (10,10) position to the same position in a translated/post-perspective modified opengl rendered scene so that it puts it on top of the object but never moves it (i may have not understood previous posts...i cannot stress how new i am at this
)
i took a look at the code for overlays, btw...still having a problem with keeping text in the same position while sizing except when it''s in (0,0) since that''s the center of the translated pic
sorry if i''m trouble..and many thanks for all the help so far!

i guess i should let you know a bit more about my code...it''s an MDI app (MFC generated) that''s OpenGL enabled (i used code from Alasandro Falapa''s (probably spelled that wrong) CGLEnabledView which he posted on www.codeguru.com to create an MFC app that uses openGL drawing code to render the contents (if not the entire) window (i''m not entirely sure...))
so my drawing commands are broken up among a couple of functions...but in a nut shell, you do most of the drawing under the OnDrawGL function...which is called in the base class from the OnDraw command and then the HDC is gathered, GL commands are all taken care of (oddly enough, i''ve never seen an Ortho call in all of his code...so my ortho call was just before i drew my scene (i don''t even use a flush command, i use a glFinish() which i understand is the same, but maybe a bit slower than a glFlush() since i''m not on a network...dunno, but i only use 1 glFinish...should i be using more?)
i guess, in a nut shell...what i''m trying to do is replicate a GDI call...if you use
cDC->textout(3, 10 , 10, "doh");
no matter how you size the screen, it stays at (10,10) which is the behavior i want from my text with the benefits of the double buffering...is there a way to get the GDI call to be double buffered?
or is there code that converts the (10,10) position to the same position in a translated/post-perspective modified opengl rendered scene so that it puts it on top of the object but never moves it (i may have not understood previous posts...i cannot stress how new i am at this

i took a look at the code for overlays, btw...still having a problem with keeping text in the same position while sizing except when it''s in (0,0) since that''s the center of the translated pic
sorry if i''m trouble..and many thanks for all the help so far!
I haven''t done much in an attempt for an MFC OpenGL program. I don''t really like MFC since it requires all those extra DLLs.
About the font position problem-whenever you use the Ortho or Perspective setup functions that aren''t in the GLU library, I''m pretty sure it multiplies those matrixes by the current matrix. Here''s a basic code outline that could help.
glMatrixMode(GL_PROJECTION); //Swaps to the needed matrix mode
glLoadIdentity(); //Creates the identity matrix, unmodified.
//Setup your projection stuff here, like ortho or perspective.
glMatrixMode(GL_MODELVIEW); /*Swaps back to the required mode for placing the vertices. (probably the mode it was on before this) */
It seems that you had accidentally multiplied the old perspective projection matrix by the orthographic projection matrix, which definitely could have messed up your coding. Hope this helps.
About the font position problem-whenever you use the Ortho or Perspective setup functions that aren''t in the GLU library, I''m pretty sure it multiplies those matrixes by the current matrix. Here''s a basic code outline that could help.
glMatrixMode(GL_PROJECTION); //Swaps to the needed matrix mode
glLoadIdentity(); //Creates the identity matrix, unmodified.
//Setup your projection stuff here, like ortho or perspective.
glMatrixMode(GL_MODELVIEW); /*Swaps back to the required mode for placing the vertices. (probably the mode it was on before this) */
It seems that you had accidentally multiplied the old perspective projection matrix by the orthographic projection matrix, which definitely could have messed up your coding. Hope this helps.
thank you! that allowed me to assign an ortho to it, which worked for positioning the text...the problem that i''m running into now is the EXACT positioning of it...
take this window for instance...the browser window...at the top left there is the text of the word file (the file menu option, i''m assuming netscape has the same thing), always in the same position no matter how you size the window...if you left click and drag the right border all the way to the left, the position of file stays the same, as well as edit, view, etc. even as they are covered over...they do not remain in proportionate positions dependent on screen size...
unfortunately, i cannot replicate this...i can''t keep the text in the top left hand corner at 10,10 in logical coords, even with an ortho... does anyone have any ideas on how to position the text at (10,10) logical coordinates (where 0,0 represents the left-upper most corner of a window)?
The MSDN article for textout, the GDI call which positions it in a single place despite sizing is below (as long as you use a straight number)
MSDN-
"TextOut
The TextOut function writes a character string at the specified location, using the currently selected font, background color, and text color.
BOOL TextOut(
HDC hdc, // handle to device context
int nXStart, // x-coordinate of starting position
int nYStart, // y-coordinate of starting position
LPCTSTR lpString, // pointer to string
int cbString // number of characters in string
);
Parameters
hdc
Handle to the device context.
nXStart
Specifies the logical x-coordinate of the reference point that the system uses to align the string.
nYStart
Specifies the logical y-coordinate of the reference point that the system uses to align the string.
lpString
Pointer to the string to be drawn. The string does not need to be zero-terminated, since cbString specifies the length of the string.
cbString
Specifies the number of characters in the string. "
is there a particular way i need to declare the ortho to be able to position something so that it stays statically in the top-left corner?
take this window for instance...the browser window...at the top left there is the text of the word file (the file menu option, i''m assuming netscape has the same thing), always in the same position no matter how you size the window...if you left click and drag the right border all the way to the left, the position of file stays the same, as well as edit, view, etc. even as they are covered over...they do not remain in proportionate positions dependent on screen size...
unfortunately, i cannot replicate this...i can''t keep the text in the top left hand corner at 10,10 in logical coords, even with an ortho... does anyone have any ideas on how to position the text at (10,10) logical coordinates (where 0,0 represents the left-upper most corner of a window)?
The MSDN article for textout, the GDI call which positions it in a single place despite sizing is below (as long as you use a straight number)
MSDN-
"TextOut
The TextOut function writes a character string at the specified location, using the currently selected font, background color, and text color.
BOOL TextOut(
HDC hdc, // handle to device context
int nXStart, // x-coordinate of starting position
int nYStart, // y-coordinate of starting position
LPCTSTR lpString, // pointer to string
int cbString // number of characters in string
);
Parameters
hdc
Handle to the device context.
nXStart
Specifies the logical x-coordinate of the reference point that the system uses to align the string.
nYStart
Specifies the logical y-coordinate of the reference point that the system uses to align the string.
lpString
Pointer to the string to be drawn. The string does not need to be zero-terminated, since cbString specifies the length of the string.
cbString
Specifies the number of characters in the string. "
is there a particular way i need to declare the ortho to be able to position something so that it stays statically in the top-left corner?
woohoo! thank you for your help Josh Horton!
i was able to get the ortho to work after assigning it the respective size of the viewport and then multiplying that by the fraction that represented the correct positioning i wanted in windows logical coordinates (i wanted it to be at (10,10) in a window of (656, 276) so i multiplied the width of the viewport by 10/656 and it put it in the right spot
and no matter how i size it, it stays put!)
take a look please at my other post for the code snipet evaluation...i''m not entirely sure i used the calls correctly (or if i used them too many times in a row or incorrectly) so if you see anything, could you please point out the line? i guess i know enough to get things drawn and when it draws correctly i''m happy (but i want to make sure i''m not doing something stupid, because i kinda like OpenGL and would sure like to be able to proficiently use it in the future!)
i was able to get the ortho to work after assigning it the respective size of the viewport and then multiplying that by the fraction that represented the correct positioning i wanted in windows logical coordinates (i wanted it to be at (10,10) in a window of (656, 276) so i multiplied the width of the viewport by 10/656 and it put it in the right spot

take a look please at my other post for the code snipet evaluation...i''m not entirely sure i used the calls correctly (or if i used them too many times in a row or incorrectly) so if you see anything, could you please point out the line? i guess i know enough to get things drawn and when it draws correctly i''m happy (but i want to make sure i''m not doing something stupid, because i kinda like OpenGL and would sure like to be able to proficiently use it in the future!)
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement