Sign in to follow this  
Zeugmal

SDL and NeHe's "glPrint"

Recommended Posts

I set out a few hours earlier to add font support for my game, thinking it might be a trivial matter, but of course, that's always naive foolishness. The font code on NeHe seems fairly straightforward, the only problem being that I'm using SDL, and as such don't have access to the window handle or device context. So, thinking I'd found my solution, I came across SDL_GetWMInfo. This returns a struct containing, among other information, the window handle. Unfortunately, this seems to return 0 instead of a valid window handle. I've also tried the windows function FindWindow(NULL, "SDL_app") but that returns null as well. I am indeed calling all of these functions post SDL initialization. The offending code:
GLvoid VideoManager::BuildFont(GLvoid)					
{
	HFONT	font;										
	HFONT	oldfont;									

	SDL_SysWMinfo info;
	SDL_GetWMInfo(&info);

	HDC hDC = GetDC(info.window);

	m_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, m_base);				
	SelectObject(hDC, oldfont);							
	DeleteObject(font);									
}

I would use SDL_ttf, but it seems I'd have to blit the result via SDL_BlitSurface, and that can't be used as I'm in OpenGL mode. Any suggestions?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this