PDA

View Full Version : Problem drawing text



openujs
02-26-2006, 02:15 PM
I am trying to draw some text in the screen, however, no success so far. I just see PITCH BLACK screen. Here is my code:

void init( void )
{
HDC hDC = wglGetCurrentDC();


base = glGenLists( 256 );
HFONT hFont;

hFont = CreateFont( fontSize,//Height
0, //Width
0, //Escapement
0, //Orientation
FW_BOLD, //Weight
FALSE, //Italic
FALSE, //Underline
FALSE, //Strikeout
ANSI_CHARSET, //Charset
OUT_TT_PRECIS, //Output Precision
CLIP_DEFAULT_PRECIS,//Clipping Precision
ANTIALIASED_QUALITY, //Output Quality
FF_DONTCARE|DEFAULT_PITCH, //Pitch and Family
fontName //LPCTSTR pointer to typeface name string
);
if( !hFont ) return 0;

//Select a device Context for the font
SelectObject( hDC, hFont );

//Prepare the bitmap font
wglUseFontBitmaps( hDC, 32, 96, base );
}

void display( char* str )
{
char text[256];
va_list args;

if( base==0 || str == NULL ){
return;
}
va_start(args, str);
vsprintf(text, str, args);
va_end(args);

glRasterPos3f(-0.25, 0.15, -0.1);

glPushAttrib(GL_LIST_BIT);
glListBase(base - 32);
glCallLists(strlen(text), GL_UNSIGNED_BYTE, text);
glPopAttrib();
}

toocool_4181
02-27-2006, 04:26 AM
hello

Could you plz help me in drawing the alphabet F in openGL with the code..... could u also plz mention the vertices used... i just want to go through it and understand throughly....

openujs
02-27-2006, 05:35 AM
toocool, i am having problem drawing text and u r asking me a question :)

Well, the code i have above supposed to work, u just pass whatever string u want to draw, on init() pass font name, and font size. As long as u pass the correct DEVICE CONTEXT ( in windows), it should work, but my case, it is not working. My guess is i have to do some glLoadIdentity(), or some clearing the buffer,,,i tried those, still does not work.

gemelli_d
02-27-2006, 06:05 AM
have a look at NeHe website
it is in lesson #13
http://nehe.gamedev.net/

openujs
02-27-2006, 10:32 AM
i figured out the problem. I commented out this line
//glEnable( GL_LINE_SMOOTH|GL_CULL_FACE| GL_POLYGON_SMOOTH );

and it worked. but I DUNNO WHY??? anyone has CLUES :)