unknowncheats uc-forum.com ucdownloads ucdownloads.com

Go Back   UC-Tutorials - Multiplayer Game Hacking and Cheat Tutorials > Programming > OpenGL

- Sponsored Advertisement -
http://www.myfpscheats.com/


Reply
 
Thread Tools Display Modes
  #1  
Old 12-24-2006, 07:31 AM
zero_tolerance zero_tolerance is offline
Senior Member
 
Join Date: Dec 2006
Posts: 289
Default Draw Text in GL

By monkey6666

Works on any GL game.

Code:
// for glPrint()
HDC				hDC;
HFONT			hOldFont;				
HFONT			hFont;
UINT			FontBase, FontBaseUnderline, FontBaseBig;
bool                     bFontsBuild = 0;

// ----------------------------------------------------------------------

void BuildFonts()
{
	hDC			= wglGetCurrentDC();
		
	FontBase	= glGenLists(96);
	hFont		= CreateFont(-12, 0, 0, 0, FW_NORMAL,	FALSE, FALSE, FALSE, ANSI_CHARSET, OUT_TT_PRECIS, CLIP_DEFAULT_PRECIS, PROOF_QUALITY, FF_DONTCARE|DEFAULT_PITCH, "Courier"); //"Lucida Console");					
	hOldFont	= (HFONT) SelectObject(hDC, hFont);           
	wglUseFontBitmaps(hDC, 32, 96, FontBase);				
	SelectObject(hDC, hOldFont);							
	DeleteObject(hFont);	
		
	FontBaseUnderline = glGenLists(96);
	hFont			= CreateFont(-10, 0, 0, 0, FW_NORMAL, FALSE, TRUE, FALSE, ANSI_CHARSET, OUT_TT_PRECIS, CLIP_DEFAULT_PRECIS, PROOF_QUALITY, FF_DONTCARE|DEFAULT_PITCH, "Courier"); 					
	hOldFont		= (HFONT) SelectObject(hDC, hFont);           
	wglUseFontBitmaps(hDC, 32, 96, FontBaseUnderline);				
	SelectObject(hDC, hOldFont);							
	DeleteObject(hFont);

	FontBaseBig		= glGenLists(96);
	hFont			= CreateFont(-14, 0, 0, 0, FW_BOLD, FALSE, FALSE, FALSE, ANSI_CHARSET, OUT_TT_PRECIS, CLIP_DEFAULT_PRECIS, PROOF_QUALITY, FF_DONTCARE|DEFAULT_PITCH, "Courier"); 					
	hOldFont		= (HFONT) SelectObject(hDC, hFont);           
	wglUseFontBitmaps(hDC, 32, 96, FontBaseBig);				
	SelectObject(hDC, hOldFont);							
	DeleteObject(hFont);
	
	bFontsBuild = true;
}

// ----------------------------------------------------------------------

void glPrint(int x, int y, const char *fmt, ...)					
{
	if (!bFontsBuild) BuildFonts();

	if (fmt == NULL)	return;	

	glRasterPos2i(x,y);

	char		text[256];								
	va_list		ap;	

	va_start(ap, fmt);									
	vsprintf(text, fmt, ap);						
	va_end(ap);		

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

// ----------------------------------------------------------------------

void glPrintUnderline(int x, int y, const char *fmt, ...)					
{
	if (!bFontsBuild) BuildFonts();

	if (fmt == NULL)	return;	

	glRasterPos2i(x,y);

	char		text[256];								
	va_list		ap;	

	va_start(ap, fmt);									
	vsprintf(text, fmt, ap);						
	va_end(ap);		

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

// ----------------------------------------------------------------------

void glPrintBig(int x, int y, const char *fmt, ...)					
{
	if (!bFontsBuild) BuildFonts();	
	
	if (fmt == NULL)	return;

	glRasterPos2i(x,y);

	char		text[256];								
	va_list		ap;	

	va_start(ap, fmt);
    vsprintf(text, fmt, ap);
	va_end(ap);

	glPushAttrib(GL_LIST_BIT);							
	glListBase(FontBaseBig - 32);								
	glCallLists(strlen(text), GL_UNSIGNED_BYTE, text);	
	glPopAttrib();										
}
creds Pansemuckl
Reply With Quote
Reply

  • Submit Thread to Digg
  • Submit Thread to del.icio.us
  • Submit Thread to StumbleUpon
  • Submit Thread to Google
  • Submit Thread to Facebook
  • Submit Thread to My Yahoo!
  • Submit Thread to MySpace
  • Submit Thread to Twitter
  • Submit Thread to Reddit

Tags
draw, text

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



All times are GMT. The time now is 07:12 AM.