CP2060 - Lecture 19 - MD2 Making & Displaying Text in OpenGL

 

Bitmap Text

Text is obviously quite useful for graphics applications - instruction screens, timers, popup menus, etc.

There are more advanced ways of displaying text in OpenGL, but for now, we see that GLUT offers a painless way to display text using:

void glutBitmapCharacter(void *font, int character);

The fonts available are bitmap fonts such as:

GLUT_BITMAP_HELVETICA_12 and
GLUT_BITMAP_TIMES_ROMAN_24

By stepping through an array of characters (until you hit the null character), you can display text strings on the screen.

void Print(void *font, char *theText)
{
  while (theText[i] != '\0')
  {
    glutBitmapCharacter( font, c );
    i++;
  }
}

Use glRasterPos3f(x,y,z); to set the location of where the text will appear.

The Sample Code uses the 3D scene from Figure 5.63 in the text, so there's lighting and material properties involved. To set the colour of your text, you can use:

GLfloat mat_emission[] = {0.0f, 1.0f, 0.0f};
glMaterialfv(GL_FRONT,GL_EMISSION, mat_emission);

This operates just like the GL_AMBIENT, GL_DIFFUSE, etc. except it's the emission colour of the object, meaning the colour emitted by the object (glow).

 

Using QME to Create MD2 Models

You are required to create MD2 files for your major project from Inspire 3D objects. Here's a quick how-to.

QME Screen Shot

There's help for using QME here.

The left panel shows the frames available (in two scenes here), with the middle view showing the current frame. Clicking the green play button will play the frames of one scene repeatedly.

QME - Zoom in/outTo create an MD2 from your Inspire 3D objects, choose File > Import Objects and select your Inspire model (.LWO) file. It may appear very small in the view window, so you can adjust the zoom using the zoom drop-down button on the toolbar. You may have to resize your program window to see the button.

To add more frames, right-click on the scene (which you can rename by the usual methods), and choose Import Frames. You need to import the same model in a different position. You can't have multiple frames of different objects - they need to have the same number of triangles. That's why using one boned object in Inspire and saving the transformed object from Layout is probably going to be the easiest way to make the Inspire frames.

Importing frames normally makes a separate scene for each frame. You can simply drag frames from one scene to the other and drag them around to set the correct order. Once you have the frames in place, rename the scene and it should logically name the frames after the scene with numbers. (If pressing Enter doesn't make the program accept your name change, you can simply click in an empty area of the workspace).

You can view and edit the properties of your model by choosing View > Model Properties. Check the number of triangles is < 4096.

QME Properties

When you have finished the model, you save it as an MD2 file (not MDO or MDL). This should make a .md2 file and a skin (.pcx).

NEW! Getting QME skins to work with the model loading code! (18/10 & updated 24/10)

Painting the skin can be done in QME using the painting tools or in an external image editor. If you want better detail in your QME skin (and you probably do), then you can resize the skin by setting the skin size in the model properties panel (see screenshot above).

OK, so it seems that the MD2 loading code we have can't open the pcx file produced by QME. We can convert it to a format that we can use, however:

  • In QME, select the skins button for the left pane (see image below), then right-click on the skin name (in the left pane) and choose Export. This will save it as an 8-bit bitmap file.

Export bmp skin in QME

  • Then you need to convert the 8-bit file to a 24-bit bitmap image, so open it in Windows Paint and choose Save As (24-bit bmp).
  • But! - For some reason the skin will load upside-down (?), so you need to Flip it vertically in Paint before you save it (don't rotate it, flip it).

That should get you usable skins out of QME. All you need to do is draw them in QME (covered in lecture), and maybe touch them up in Paint or some other program.

Your MD2 file is then ready to load into your OpenGL programs using the code provided in class.

 

 

 

 Announcements

Lecture notes are provided as a guide of the content of lectures for pre-reading, revision and for students who cannot attend lectures. While almost every effort is made to make the online notes as complete as possible, there is always material discussed in lectures that is not in the notes.
You should not rely on these notes only!
If you miss a lecture and you do not understand something in the notes, you should consult (in this order) other students, the tutors, or the lecturer to try to work it out.

You are expected to read these lecture notes as well as attending lectures, as vital information is contained in both.

 

 Subject Coordinator: Lindsay {w} | {e}.

Last Update: October 25, 2001