#include #include #include #include using namespace std; GLfloat Text_Scale; GLfloat Ytrans; string Text = "Episode IV\nA NEW HOPE\n\nIt is a period of civil war.\nRebel spaceships, striking\nfrom a hidden base, have won\ntheir first victory against\nthe evil Galactic Empire.\n\nDuring the battle, Rebel\nspies managed to steal secret\nplans to the Empire's\nultimate weapon, the DEATH\nSTAR, an armored space\nstation with enough power to\ndestroy an entire planet.\n\nPursued by the Empire's\nsinister agents, Princess\nLeia races home aboard her\nstarship, custodian of the\nstolen plans that can save\nher people and restore\nfreedom to the galaxy....\n" ; void DisplayString(void * font, string s) { int i; string remaining; string line; int pos; GLfloat ypos; GLfloat dy; GLfloat width; pos = s.find('\n'); ypos = 0; dy = glutStrokeHeight(font) * 1.1; width = 0; while ( pos != string::npos ) { glPushMatrix(); line = s.substr(0,pos); s = s.substr(pos+1, s.size()); // run through the string and calculate the width width = 0; for(i=0; i < line.size(); i++) { width += glutStrokeWidth(font, line[i]); } glTranslatef(-width/2, ypos, 0); for(i=0; i < line.size(); i++) { glutStrokeCharacter(font, line[i]); } ypos = ypos - dy; pos = s.find('\n'); glPopMatrix(); } return; } void display() { glClear(GL_COLOR_BUFFER_BIT); glLoadIdentity(); glTranslatef(0,0,-3.0); glColor3f(1.0,0.84,0); glScalef(Text_Scale,Text_Scale,Text_Scale); glRotatef(-45,1,0,0); glTranslatef(0,Ytrans, 0); DisplayString(GLUT_STROKE_ROMAN, Text); glFlush(); return; } void reset() { Text_Scale = 0.001; Ytrans = -2200; return; } void setup() { reset(); glClearColor(0.0,0.0, 0.0, 0.0); glLineWidth(2.0); return; } void resize(int w, int h) { glViewport(0, 0, w, h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glFrustum(-1.0, 1.0, -1.0, 1.0, 1, 20.0); //glOrtho(-1.5, 1.5, -1.5, 1.5, -1.5, 1.5); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); return; } void idle() { Ytrans += 0.5; glutPostRedisplay(); return; } void keypress (unsigned char key, int x, int y) { switch(key) { case 'g': glutIdleFunc(idle); break; case 's': glutIdleFunc(NULL); break; case 'r': reset(); break; case 'T': Text_Scale *= 1.1; break; case 't': Text_Scale *= 0.9; break; case 'q': exit(0); } glutPostRedisplay(); return; } int main(int argc, char * argv[]) { glutInit(&argc, argv); glutInitContextVersion(3, 0); glutInitContextProfile(GLUT_COMPATIBILITY_PROFILE); glutInitDisplayMode(GLUT_SINGLE | GLUT_RGBA); glutInitWindowSize(500, 500); glutCreateWindow("A Demo"); glutDisplayFunc(display); glutReshapeFunc(resize); glutKeyboardFunc(keypress); glutIdleFunc(idle); glewExperimental = GL_TRUE; glewInit(); setup(); glutMainLoop(); }