Lighthouse3d.com >> GLUT Tutorial >> Extras >> The Code So Far V
该代码与位图字体的代码类似.区别是用了笔划字体来显示每个雪人上的数字,然后雪人是用正交投影来显示,还有一段用位图字体显示的文本.后面包含了每秒帧数的文本不受镜头移动的影响,它一直停留在屏幕的相同位置.
字体菜单也改成了用笔划字体代替位图字体.
#include <stdio.h> #include <stdlib.h> #include <math.h> #ifdef __APPLE__ #include <GLUT/glut.h> #else #include <GL/glut.h> #endif // angle of rotation for the camera direction float angle = 0.0f; // actual vector representing the camera's direction float lx=0.0f,lz=-1.0f; // XZ position of the camera float x=0.0f, z=5.0f; // the key states. These variables will be zero //when no key is being presses float deltaAngle = 0.0f; float deltaMove = 0; int xOrigin = -1; // Constant definitions for Menus #define RED 1 #define GREEN 2 #define BLUE 3 #define ORANGE 4 #define FILL 1 #define LINE 2 // Pop up menu identifiers int fillMenu, fontMenu, mainMenu, colorMenu; // color for the nose float red = 1.0f, blue=0.5f, green=0.5f; // scale of snowman float scale = 1.0f; // menu status int menuFlag = 0; // default font void *font = GLUT_STROKE_ROMAN; // width and height of the window int h,w; // variables to compute frames per second int frame; long time, timebase; char s[50]; void changeSize(int ww, int hh) { h = hh; w = ww; // Prevent a divide by zero, when window is too short // (you cant make a window of zero width). if (h == 0) h = 1; float ratio = w * 1.0 / h; // Use the Projection Matrix glMatrixMode(GL_PROJECTION); // Reset Matrix glLoadIdentity(); // Set the viewport to be the entire window glViewport(0, 0, w, h); // Set the correct perspective. gluPerspective(45.0f, ratio, 0.1f, 100.0f); // Get Back to the Modelview glMatrixMode(GL_MODELVIEW); } void drawSnowMan() { glScalef(scale, scale, scale); glColor3f(1.0f, 1.0f, 1.0f); // Draw Body glTranslatef(0.0f ,0.75f, 0.0f); glutSolidSphere(0.75f,20,20); // Draw Head glTranslatef(0.0f, 1.0f, 0.0f); glutSolidSphere(0.25f,20,20); // Draw Eyes glPushMatrix(); glColor3f(0.0f,0.0f,0.0f); glTranslatef(0.05f, 0.10f, 0.18f); glutSolidSphere(0.05f,10,10); glTranslatef(-0.1f, 0.0f, 0.0f); glutSolidSphere(0.05f,10,10); glPopMatrix(); // Draw Nose glColor3f(red, green, blue); glRotatef(0.0f,1.0f, 0.0f, 0.0f); glutSolidCone(0.08f,0.5f,10,2); glColor3f(1.0f, 1.0f, 1.0f); } void renderBitmapString( float x, float y, float z, void *font, char *string) { char *c; glRasterPos3f(x, y,z); for (c=string; *c != '