Jump to content
  • Advertisement
Sign in to follow this  
koalacui

OpenGL Question about Bitmap Font!!!!

This topic is 4743 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, guys, my first time to try bitmap font of OpenGL, i have tried a lot of ways, but still cannot display the font, this is the code, i write these code into AppMain.cpp file, and with 5 errors, it's all about g_HDC, i dont know how to solve it, can anybody help me on it!! thanks a lot and best regards!!!
unsigned int listBase;
.
.
.
unsigned int CreateBitmpFont(char *fontName, int fontSize)
{
	HFONT hFont;
	unsigned int base;

	base = glGenLists(96);

	if (stricmp(fontName, "symbol")== 0)
	{
		hFont = CreateFont(fontSize, 0, 0, 0, FW_BOLD, FALSE, FALSE, FALSE,
						   SYMBOL_CHARSET, OUT_TT_PRECIS, CLIP_DEFAULT_PRECIS,
						   ANTIALIASED_QUALITY, FF_DONTCARE | DEFAULT_PITCH,
						   fontName);
	}
	else
	{
		hFont = CreateFont(fontSize, 0, 0, 0, FW_BOLD, FALSE, FALSE, FALSE,
						   ANSI_CHARSET, OUT_TT_PRECIS, CLIP_DEFAULT_PRECIS,
						   ANTIALIASED_QUALITY, FF_DONTCARE | DEFAULT_PITCH,
						   fontName);
	}

	if (!hFont)
		return 0;

	SelectObject(g_HDC, hFont);
	wglUseFontBitmaps(g_HDC, 32, 96, base);

	return base;
}

void PrintString(unsigned int base, char *str)
{
	if ((base == 0 || (str == NULL))
		return;

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

void ClearFont(unsigned int base)
{
	if (base != 0)
		glDeleteLists(base, 96);
}

void Initialize()
{
	glClearColor(0.0f, 0.0f, 0.0f, 0.0f);

	glShadeModel(GL_SMOOTH);
	glEnable(GL_DEPTH_TEST);

	listBase = CreateBitmapFont("Comic Sans MS", 48);
}

void Render()
{
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glLoadIdentity();

	glTranslatef(0.0f, 0.0f, -1.0f);

	glColor3f(1.0f, 1.0f, 1.0f);

	glRasterPos2f(-0.35f, 0.0f);

	PrintString(listBase, "OpenGL Bitmap Fonts!");

	glFlush();
	SwapBuffers(g_HDC);
}
.
.
void main()
.
.
.

Share this post


Link to post
Share on other sites
Advertisement
ok, for the second time:

HDC g_HDC;

at the top of your file. outside of any brackets. to make it work, call GetDC( ) on the handle you get from CreateWindow( ) when you create it.


HWND your_window = CreateWindow(...);

g_HDC = GetDC(your_window);

Share this post


Link to post
Share on other sites
I'm so sorry to trouble you, but I cannot understand your code, can u explain it more in detail? how to call GetDC(), write what in it? ....emmm.....HWND is ....hhe...sorry for these troubles, or you can help me insert the general idea into my code, i am not sure put these coe into which part?? thanks a lot and best regards!!!!

[Edited by - koalacui on September 23, 2005 1:03:58 AM]

Share this post


Link to post
Share on other sites
You need the handle from your created window.
Pass it to GetDC(); the get the device context.

You can find a sample here.
http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=13

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!