#include #include #include #include id_type view; GLuint texture; void recreate_text(char const *message) { glDeleteTextures(1, &texture); view = ConvenienceCreateNSTextView( 1024, 512, "Apple Chancery", 24.0f, 0, message); glGenTextures(1, &texture); glBindTexture(GL_TEXTURE_2D, texture); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); TexImageNSView(GL_TEXTURE_2D, view); } char const *messages[] = { "The limerick is furtive and mean\n" "You must keep her in close quarantine\n" "Or she sneaks to the slums\n" "And promptly becomes\n" "Disorderly, drunk and obscene.\n", "A bather whose clothing was strewed,\n" "By winds that left her quite nude,\n" "Saw a man come along,\n" "And unless we are wrong,\n" "You expected this line to be lewd.\n", "There was an old woman from Hyde\n" "Who ate rotten apples and died.\n" "The apples fermented\n" "Inside the lamented\n" "Making cider inside her inside.\n", "Archimedes, the well known truth-seeker,\n" "Jumping out of his bath, cried \"Eureka!\"\n" "He ran half a mile,\n" "Wearing only a smile,\n" "And became the world's very first streaker.\n", }; void display() { static int lastUpdateTime = -1; if (lastUpdateTime == -1) lastUpdateTime = glutGet(GLUT_ELAPSED_TIME); int now = glutGet(GLUT_ELAPSED_TIME); int delta = now - lastUpdateTime; if (delta > 5000) { lastUpdateTime = now; recreate_text(messages[rand() % (sizeof(messages)/sizeof(messages[0]))]); } glClearColor(0.25, 0.0, 0.25, 0.0); glClear(GL_COLOR_BUFFER_BIT); glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_BLEND); glBindTexture(GL_TEXTURE_2D, texture); glEnable(GL_TEXTURE_2D); glBegin(GL_QUADS); glTexCoord2f(0.0f, 1.0f); glVertex2f(-1.0f, -1.0f); glTexCoord2f(1.0f, 1.0f); glVertex2f( 1.0f, -1.0f); glTexCoord2f(1.0f, 0.0f); glVertex2f( 1.0f, 1.0f); glTexCoord2f(0.0f, 0.0f); glVertex2f(-1.0f, 1.0f); glEnd(); glutSwapBuffers(); glutReportErrors(); } void reshape(int w, int h) { glViewport(0, 0, w, h); } int main(int argc, char **argv) { srand(time(NULL)); glutInit(&argc, argv); glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE); glutInitWindowSize(1024, 512); glutCreateWindow("Hi"); glutDisplayFunc(display); glutReshapeFunc(reshape); glutIdleFunc(glutPostRedisplay); recreate_text("Hello world!\n\nThis is a test!\n"); glutMainLoop(); return 0; }