Jump to content
  • Advertisement
Sign in to follow this  
Zeugmal

SDL and NeHe's "glPrint"

This topic is 3429 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

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
Advertisement
You can use a custom bitmap font instead.
I did a demo in assembly language here...
http://board.flatassembler.net/topic.php?t=9885
Somewhere around here i have a C version i can post later.

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!