Re: [PyOpenGL-Users] true type fonts
Brought to you by:
mcfletch
From: Mike C. F. <mcf...@ro...> - 2003-01-12 06:17:45
|
This is taken from OpenGLContext/tests/glprint.py , the major difference I can see is that it generates the display-lists before trying to fill them with wglUseFontBitmaps(...) self.base = glGenLists(96) # Storage For 96 Characters wgldc = wglGetCurrentDC() dc = win32ui.CreateDCFromHandle( wgldc ) ## pitch and family value f = win32ui.CreateFont( { 'italic': None, #use of None is required, 0 doesn't work 'underline': None, #use of None is required, 0 doesn't work 'name': 'Times New Roman', 'weight': 700, 'height': 20, } ) dc.SelectObject( f ) wglUseFontBitmaps(wgldc, 32, 96, self.base) # Builds 96 Characters Starting At Character 32 # f is deleted here, if it is deleted before the display-lists # are created they will just use the default font! I only have one machine to test on, so it's possible that too will fail on some machines, but I'm pretty sure you want the glGelLists call regardless. You can also find sample code in NeHe tutorials #13 and #14, and the OpenGLContext/scenegraph/text package. Also note that there's no decent way to get font metrics that I've found for the bitmap versions of fonts using WGL. If anyone finds one I'd like to include that functionality in OpenGLContext/scenegraph/text. Good luck, Mike Sean Riley wrote: >Here is some code I used to get true type font working. This took a while to >figure out... > >handle = 55 > >def createFont(fontName, fontSize): > props = {"name":fontName, > "height":(int)(fontSize), > "charset":0, "weight":1, > "pitch and family":18} > > pf = win32ui.CreateFont( props ) > hdc = wglGetCurrentDC() > pdc = win32ui.CreateDCFromHandle(hdc) > > old = pdc.SelectObject(pf) > result = wglUseFontBitmaps(hdc , 0, 255, handle) > if not result: > print "ERROR!" > pdc.SelectObject(old) > >def drawText(text, pos, color): > glColor4ub( color[0], color[1], color[2], color[3] ) > glRasterPos2i(position[0], position[1]) > glListBase(handle) > glCallLists(text) > >This fails on some machines though, when trying to create the truetype >font... I >dunno why. > >--------------------------------- >"I'm not as interested in being witty as I am in being clear", Scott Meyers >Sean Riley >MrR...@ya... > > |