View Full Version : glyphs & fonts for music notation display

07-16-2009, 09:27 PM

I am trying to make an OpenGL program that can display music notation. Here's an example of music notation to refresh your memory (courtesy of google images):
Currently, I have successfully drawn the horizontal lines (staves) using OpenGL and gotten them to antialias. It probably doesn't sound like a lot, but I am an opengl beginner, and it took me a few hours to get set up.

I now need to add glyphs of various sizes and shapes to draw the actual notation. The glyphs could be the notes themselves (ovals at a slight tilt), or the clefs, or the sharps and flats, or the time signature (4/4). Additionally, I need to use a custom serif font to add in the composer's name at the top, etc. as well as other italic markings in the score (eg the word "sim." on the 6th line from the top).

What is the preferred way to do this sort of 2d drawing? I researched truetype fonts and OpenGL online, but it sounds like that might be impossible or very slow. There are many different glyphs used in music notation (a few hundred). Is a font a bad thing to use in an OpenGL program? As an alternative to a bitmap type font, I was considering drawing a complex glyph (like a trebel clef) with polygons. However, I read online that doing too many polygons could be really slow. What is the best method of drawing glyphs and fonts for my particular application?

As a final note, I am looking for a combination of speed and a crisp, high resolution because I will be updating the screen during a live performance, and musical notation has many tiny graphic nuances that are significant to the performer.

Any answers or advice you have are greatly appreciated.

thank you.

07-16-2009, 10:19 PM
Wow. That is a fairly complex set of texture work. Where to start.
Ultimately you are going to need to rely on some libraries or spend a lot of time writing your own custom "font" code.

Have you checked on sourceforge or elsewhere that someone hasn't already done this work. I am sure they must have to some degree...

If you can find a truetype font that already has the music notation in it I would suggest using that with one of the libraries that supports it. It's not that slow at all.
You can then wrap that in your code which will construct various note formations for you.

The alternative is to construct your own texture atlas with various note glyphs and parts of note glyphs and then write a class to construct the notes from that.. I would think that having component parts and then blending the notes and the bars joining them together with multiple draws would be the best approach.

Good luck with it.. And do check out sourceforge. I am sure this is work that has been done before.

07-16-2009, 10:40 PM
There is a font rendering library FTGL for OGL 3.0.Or you can rely on wgl functions of windows where there are numerous functions to control character features.

or other solution is , if you want to do less work ., edit your music file images as shown by you , then draw this image using glDrawPixel(). I assume that you do not want online editing of your rendered music notation.

Tin Whisker
07-17-2009, 06:56 AM
Just quickly browsing the available notation packages on Linux I came across several apps that seemed to be related...


Don't know what their Windows counterparts are, or if they exist. Hope it helps just the same.

07-17-2009, 07:12 AM
Thanks scratt,

I scoured sourceforge, as well as google, for some musical notation software that uses opengl. I had looked before, but I wanted to look again after reading your reply.

There are very few (none?) mature music notation programs. The free notation software that I found either used a) some sort of a post script library (eg Lilypond) to basically generate a post script file and display it to the user (no interactivity), or b) used a platform-specific graphics toolkit (all of the ABC notation editors, for example) to draw very primitive notation glyphs (a few use gtk). There is 1 project that I found which uses OpenGL to render music notation -- it's a university project called PWGL. The source is not available, but they have a few academic papers where they allude to OpenGL. In these papers, the only details this author supplies are: 1) they use "OpenGL Vector Graphics" and b) "picking" for interacting with the user (http://www.mitpressjournals.org/doi/pdf/10.1162/comj.2009.33.1.19?cookieSet=1). Therefore, at least in the music notation domain specifically, no one has really done this in OpenGL. I would love if someone proves me wrong, but I can't find much of anything online.

I did some research, and the big music notation tools (finale, sibelius, etc.) use true type fonts.

To be clear, when you are suggesting the use of a font, you mean an outline-based / vector font right? I don't think bitmap textures for the notation is going to work, because finale and sibelius for example support zooming in (up to 1600%), as well as printing the score on paper. Given that, wouldn't it be more wise go with vectors? I imagine that 300 or so glyphs in bitmap format at 1024x768px (size when fully zoomed in) would be quite large.

Before I dive into this font loading, etc. -- is there an easy way to render my SVG notation glyphs in OpenGL as vectors? I'd like to see what it looks like before I deal with a font loading library.

What do you think?

i appreciate your time.

07-17-2009, 07:45 AM
Hi awhig,

Thanks for the FTGL reference.

I do want online editing of the rendered notation. My goal is to make the program generate legitimate music notation, not just display pre-made parts; if I understand what you're saying about music file images, then no I don't want a solution where I am simply opening pre-made images and showing them.


07-17-2009, 08:08 AM
Well you could use glyphs, but you'd need to make them of a big enough size that your largest level of zoom would not look pixelated. I think you realize that already.

For screen fonts with glyphs I sometimes have two or three font atlases in different sizes.

But for your application I would suggest that vector fonts would be best.
Luckily as you probably know true type supports that.
It is a very good library and you'll be surprised how fast it is.
FTGL is good.

I remember the first time I integrated it into an SDL app it felt quite convoluted getting all the various libraries together. But actually it was pretty trivial, and the flexibility is certainly worth having.

Your aims are pretty comprehensive, especially with the level of zoom you want to provide etc. so the choice is pretty much made for you. :)

For redraw speed, if / once you start hitting those issues you can look at splitting your sheet music into tiles, or simply three strips per sheet, and only update what changes.. Shift the rest around as texture slabs, which could be rendered in FBOs and only updated when they change...

07-17-2009, 10:20 AM

Thanks for your reply. That pretty much answers my question.

One last thing, is SDL something that you would recommend I learn for this project?

thanks again

07-17-2009, 10:42 AM
No worries.. :)

SDL.. It's cross platform which is good. It is a media layer, but I tend to associate it with games rather than serious desktop apps. I'll probably get shot for saying that.

Without knowing more about what you want to do I wouldn't like to say one way or the other, but anything that has a nice GUI system (which I think SDL has as add-ons) might be a nice way to go.. It certainly plays well with Freetype / Truetype etc.

Others might have better suggestions for you on that. :)