openGL text in multiple windows

This is a discussion on openGL text in multiple windows within the Windows Programming forums, part of the Platform Specific Boards category; I have decided to try drawing text using wglUseFontBitmaps() (in openGL). I have multple windows, and I want to be ...

  1. #1
    Registered User
    Join Date
    Feb 2005
    Posts
    61

    openGL text in multiple windows

    I have decided to try drawing text using wglUseFontBitmaps() (in openGL). 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 :

    Code:
    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;

  2. #2
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348
    Interesting. Consider raster fonts.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Rendering into multiple windows
    By VirtualAce in forum Game Programming
    Replies: 1
    Last Post: 03-31-2006, 07:00 AM
  2. Linking OpenGL in Dev-C++
    By linkofazeroth in forum Game Programming
    Replies: 4
    Last Post: 09-13-2005, 10:17 AM
  3. OpenGL Window
    By Morgul in forum Game Programming
    Replies: 1
    Last Post: 05-15-2005, 12:34 PM
  4. Question..
    By pode in forum Windows Programming
    Replies: 12
    Last Post: 12-19-2004, 06:05 PM
  5. Multiple windows.
    By Rare177 in forum Windows Programming
    Replies: 1
    Last Post: 09-30-2004, 06:58 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21