CMU Graphics Library

     When I was a freshman in high school, my computer science teacher told us to find the "CMU Graphics Package" and write a simple program. A couple weeks later he had us write Tetris. That's all the instruction we needed: this graphics package is that simple (though there was a little more documentation back then). I'm quite sure that old version had a memory leak, because my tetris program had one and I had not yet learned about the "new" operator. I think this is a slightly later version, so it shouldn't have the memory leak. If someone finds that it does - please let me know! For any beginners out there, don't be scared - a memory leak just means that the program will use up more and more RAM as it runs, until your computer runs slowly. If you close the program everything will go back to normal - no harm done. Memory leaks are bad because they make your program unusable, but they don't hurt your computer like a virus (though they do sound scary).

     So what is this graphics package? It's a simple 2D package that lets you make windows, change the title, draw image files to the window, draw shapes and strings, get keyboard and mouse input, and a few other nifty things. I have provided two projects below. One includes the console window, the other does not. Both projects implement a simple program that shows how to make a window and execute some simple commands. The graphics package does allow you to use double buffering (described in this project). The sample projects also show how double buffering works and its benefits.

     This graphics library was originally created by a group at CMU. The projects below use an older version of their library, which I have modified to work with Visual C++ 9.0 (there were some minor bugs in the switch that would cause it to crash).

     So why do I use the old version? Because it's the best. As the CMU graphics library became more and more powerful, it began looking more and more like OpenGL. If you're not familiar with OpenGL, it's how you should do graphics for anything seriuos (Google "NeHe" for a good tutorial). However, OpenGL takes a while to learn, and I find it quite annoying to work with - especially if you just want to do something simple and don't need all the fancy options that come with OpenGL.

     So, this version is from back when there weren't too many features, so it was very simple to use the graphics package. This is also one of the few graphics libraries I have found that allow you to keep control of your program's flow, rather than forcing you to have an update loop for the window. This lets you draw to the window when you want (e.g. run 10 minutes of computation *then* display the results). In other graphics libraries, your computational code would be tucked away inside the loop for the graphics. With this library, your computational code can be written just as you would otherwise, and the graphics code gets tucked into your computational code (it's like using the console: you can print to it and read from it whenever you choose - you rule it, not vice versa). This makes it much easier to create a very quick application.

     I have used this library to do everything from pong and a basic RTS game, to displaying the frequency intensities in songs as they play, to displaying simulations of a human arm for my research, to making custom programs to plot data (a 3d function viewed as a heat map with various trajectories overlaid).

Enjoy!

Graphics Project (with console, 209 KB)
Graphics Project (without console, 209 KB)
Take me home
Created: 6-24-2009. Last Modified: 6-24-2009. © Philip S. Thomas