Jump to content
  • Advertisement
Sign in to follow this  
hannibar

text in multiple windows

This topic is 4672 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 have decided to try drawing text using wglUseFontBitmaps(). I have multple windows, and I want to be able to draw on them with the same font. The implementation I have so far is this :
int base;
HFONT	font;

void printText (const char *input, ...){
	char		text[256];
	va_list		ap;

	if (input == NULL) return;

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

	glPushAttrib(GL_LIST_BIT);
	glListBase(base - 32);

	glCallLists(strlen(text), GL_UNSIGNED_BYTE, text);
	glPopAttrib();
}

void killFont(){
	glDeleteLists(base, 96);
}

void gui_drawtext(char *text, Window *win){
	HFONT	oldfont;

	if (win){
		wglMakeCurrent(win->hdc, win->hrc);

		oldfont = (HFONT)SelectObject (win->hdc, font);
		wglUseFontBitmaps (win->hdc, 32, 96, base);
		SelectObject (win->hdc, oldfont);

		glRasterPos2f(20.0F, 0.0F);

		printText(text);

		killFont();
	}
}

void buildLargeFont(){
	base = glGenLists(96);

	font = CreateFont(20, 0, 0, 0, 100, FALSE, FALSE, FALSE,
				ANSI_CHARSET, OUT_TT_PRECIS, CLIP_DEFAULT_PRECIS,
				ANTIALIASED_QUALITY, FF_DONTCARE|DEFAULT_PITCH, "Comic Sans MS");
}
I suspect that this implementation is very slow though, because wglUseFontBitmaps() is called on every frame when text is drawn. Does anyone know how to make this faster ? Keep in mind that I have to use multiple windows, with each window its own DC and RC;

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by hannibar
I suspect that this implementation is very slow though, because wglUseFontBitmaps() is called on every frame when text is drawn. Does anyone know how to make this faster ? Keep in mind that I have to use multiple windows, with each window its own DC and RC;
Just call wglUseFontBitmaps once at setup to create the font display lists. Then for each new window you create call wglShareLists to share the display lists (and other resources such as textures, VBOs, etc) between the rendering context in which you created the font display lists and the new window. Then when you want to render just set whichever context you want to render to as current, set the raster position, and render the text.

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!