Size: 1500
Comment:
|
Size: 2722
Comment:
|
Deletions are marked like this. | Additions are marked like this. |
Line 1: | Line 1: |
=== Compiling EMAN2 with FTGL support === To compile EMAN2 with FTGL support set ENABLE_FTGL to ON in cmake setup. |
|
Line 5: | Line 9: |
{{{ |
{{{#!python |
Line 11: | Line 14: |
self.font_renderer.set_font_mode(FTGLFontMode.TEXTURE) # or EXTRUDE, or PIMAP | self.font_renderer.set_font_mode(FTGLFontMode.TEXTURE) # or EXTRUDE, PIXMAP, BITMAP, POLYGON or OUTLINE |
Line 13: | Line 16: |
Line 16: | Line 18: |
Note that the EMFTGL has default values for all of its parameters and that in general you want to limit the number of times you call the setter functions, because they cause FTGL to regenerate a FTFont class and this is not a trivial expense. | A platform independent solution to getting a font renderer is available and is the recommended approach {{{#!python from EMAN2 import get_3d_font_renderer self.font_renderer = get_3d_font_renderer() self.font_renderer.set_face_size(16) # etc }}} Note that the EMFTGL has default values for all of its parameters and that in general you want to limit the number of times you call the setter functions, because they cause FTGL to regenerate an FTFont class and this is not a trivial expense. However the EMFTGL uses a cache so any FTFonts (which are characterized by face size, depth, display list use, mode, and font file) which have previously been created will automatically be reused (if parameters match). The EMFTGL cache is not static. This is related to OpenGL contexts and display lists... |
Line 20: | Line 32: |
{{{ | {{{#!python glPushMatrix() # FTGL does transformations - must push |
Line 22: | Line 35: |
glPopMatrix() | |
Line 25: | Line 39: |
{{{ | {{{#!python |
Line 29: | Line 44: |
As an example, if you want to rotate the font as though it is centered on the origin you might use | If you want to rotate the font as though it is centered on the origin you might use |
Line 31: | Line 46: |
{{{ | ---- /!\ '''Edit conflict - other version:''' ---- {{{#!python ---- /!\ '''Edit conflict - your version:''' ---- {{{#!python ---- /!\ '''End of edit conflict''' ---- |
Line 36: | Line 58: |
glPushMatrix() |
|
Line 41: | Line 64: |
glPopMatrix() | |
Line 42: | Line 66: |
=== Recommendations === TEXTURE fonts are probably the most versatile types. They are fast, antialiased, and can be transformed just like any OpenGL primitive. See http://ftgl.sourceforge.net/docs/html/ftgl-tutorial.html |
Compiling EMAN2 with FTGL support
To compile EMAN2 with FTGL support set ENABLE_FTGL to ON in cmake setup.
Using FTGL in python in EMAN2
Programmers have to create an instance of an EMFTGL object, for instance as a member variable:
1 self.font_renderer = EMFTGL()
2 self.font_renderer.set_face_size(16)
3 self.font_renderer.set_using_display_lists(True)
4 self.font_renderer.set_depth(32) # only applicable if font mode is EXTRUDE
5 self.font_renderer.set_font_mode(FTGLFontMode.TEXTURE) # or EXTRUDE, PIXMAP, BITMAP, POLYGON or OUTLINE
6 #self.font_renderer.set_font_file_name("/usr/share/fonts/dejavu/DejaVuSerif-Bold.ttf")
A platform independent solution to getting a font renderer is available and is the recommended approach
Note that the EMFTGL has default values for all of its parameters and that in general you want to limit the number of times you call the setter functions, because they cause FTGL to regenerate an FTFont class and this is not a trivial expense. However the EMFTGL uses a cache so any FTFonts (which are characterized by face size, depth, display list use, mode, and font file) which have previously been created will automatically be reused (if parameters match).
The EMFTGL cache is not static. This is related to OpenGL contexts and display lists...
Then to render text use a command similar to the following in your paint function:
To get the bounding box of the string use:
1 bbox = self.font_renderer.bounding_box("Important Information")
If you want to rotate the font as though it is centered on the origin you might use
Edit conflict - other version:
1 ---- /!\ '''Edit conflict - your version:''' ----
2 {{{#!python
3
4 ---- /!\ '''End of edit conflict''' ----
5 message = "Important Information"
6 rotation = 45
7 rot_axis = [1,0,0]
8 bbox = self.font_renderer.bounding_box(message)
9
10 glPushMatrix()
11 glTranslate(-(bbox[0]-bbox[3])/2,-(bbox[1]-bbox[4])/2,-(bbox[2]-bbox[5])/2)
12 glRotate(rotation,*rot_axis)
13 glTranslate((bbox[0]-bbox[3])/2,(bbox[1]-bbox[4])/2,(bbox[2]-bbox[5])/2)
14 self.font_renderer.render_string(message)
15 glPopMatrix()
Recommendations
TEXTURE fonts are probably the most versatile types. They are fast, antialiased, and can be transformed just like any OpenGL primitive. See http://ftgl.sourceforge.net/docs/html/ftgl-tutorial.html