132001f49Smrg/* 232001f49Smrg * Copyright (c) 1993-1997, Silicon Graphics, Inc. 332001f49Smrg * ALL RIGHTS RESERVED 432001f49Smrg * Permission to use, copy, modify, and distribute this software for 532001f49Smrg * any purpose and without fee is hereby granted, provided that the above 632001f49Smrg * copyright notice appear in all copies and that both the copyright notice 732001f49Smrg * and this permission notice appear in supporting documentation, and that 832001f49Smrg * the name of Silicon Graphics, Inc. not be used in advertising 932001f49Smrg * or publicity pertaining to distribution of the software without specific, 1032001f49Smrg * written prior permission. 1132001f49Smrg * 1232001f49Smrg * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS" 1332001f49Smrg * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE, 1432001f49Smrg * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR 1532001f49Smrg * FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON 1632001f49Smrg * GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT, 1732001f49Smrg * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY 1832001f49Smrg * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION, 1932001f49Smrg * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF 2032001f49Smrg * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN 2132001f49Smrg * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON 2232001f49Smrg * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE 2332001f49Smrg * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE. 2432001f49Smrg * 2532001f49Smrg * US Government Users Restricted Rights 2632001f49Smrg * Use, duplication, or disclosure by the Government is subject to 2732001f49Smrg * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph 2832001f49Smrg * (c)(1)(ii) of the Rights in Technical Data and Computer Software 2932001f49Smrg * clause at DFARS 252.227-7013 and/or in similar or successor 3032001f49Smrg * clauses in the FAR or the DOD or NASA FAR Supplement. 3132001f49Smrg * Unpublished-- rights reserved under the copyright laws of the 3232001f49Smrg * United States. Contractor/manufacturer is Silicon Graphics, 3332001f49Smrg * Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311. 3432001f49Smrg * 3532001f49Smrg * OpenGL(R) is a registered trademark of Silicon Graphics, Inc. 3632001f49Smrg */ 3732001f49Smrg 3832001f49Smrg/* 3932001f49Smrg * font.c 4032001f49Smrg * 4132001f49Smrg * Draws some text in a bitmapped font. Uses glBitmap() 4232001f49Smrg * and other pixel routines. Also demonstrates use of 4332001f49Smrg * display lists. 4432001f49Smrg */ 4532001f49Smrg#include "glut_wrap.h" 4632001f49Smrg#include <stdlib.h> 4732001f49Smrg#include <string.h> 4832001f49Smrg 4932001f49SmrgGLubyte space[] = 5032001f49Smrg{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; 5132001f49Smrg 5232001f49SmrgGLubyte letters[][13] = { 5332001f49Smrg{0x00, 0x00, 0xc3, 0xc3, 0xc3, 0xc3, 0xff, 0xc3, 0xc3, 0xc3, 0x66, 0x3c, 0x18}, 5432001f49Smrg{0x00, 0x00, 0xfe, 0xc7, 0xc3, 0xc3, 0xc7, 0xfe, 0xc7, 0xc3, 0xc3, 0xc7, 0xfe}, 5532001f49Smrg{0x00, 0x00, 0x7e, 0xe7, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xe7, 0x7e}, 5632001f49Smrg{0x00, 0x00, 0xfc, 0xce, 0xc7, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3, 0xc7, 0xce, 0xfc}, 5732001f49Smrg{0x00, 0x00, 0xff, 0xc0, 0xc0, 0xc0, 0xc0, 0xfc, 0xc0, 0xc0, 0xc0, 0xc0, 0xff}, 5832001f49Smrg{0x00, 0x00, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xfc, 0xc0, 0xc0, 0xc0, 0xff}, 5932001f49Smrg{0x00, 0x00, 0x7e, 0xe7, 0xc3, 0xc3, 0xcf, 0xc0, 0xc0, 0xc0, 0xc0, 0xe7, 0x7e}, 6032001f49Smrg{0x00, 0x00, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3, 0xff, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3}, 6132001f49Smrg{0x00, 0x00, 0x7e, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x7e}, 6232001f49Smrg{0x00, 0x00, 0x7c, 0xee, 0xc6, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06}, 6332001f49Smrg{0x00, 0x00, 0xc3, 0xc6, 0xcc, 0xd8, 0xf0, 0xe0, 0xf0, 0xd8, 0xcc, 0xc6, 0xc3}, 6432001f49Smrg{0x00, 0x00, 0xff, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0}, 6532001f49Smrg{0x00, 0x00, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3, 0xdb, 0xff, 0xff, 0xe7, 0xc3}, 6632001f49Smrg{0x00, 0x00, 0xc7, 0xc7, 0xcf, 0xcf, 0xdf, 0xdb, 0xfb, 0xf3, 0xf3, 0xe3, 0xe3}, 6732001f49Smrg{0x00, 0x00, 0x7e, 0xe7, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3, 0xe7, 0x7e}, 6832001f49Smrg{0x00, 0x00, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xfe, 0xc7, 0xc3, 0xc3, 0xc7, 0xfe}, 6932001f49Smrg{0x00, 0x00, 0x3f, 0x6e, 0xdf, 0xdb, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3, 0x66, 0x3c}, 7032001f49Smrg{0x00, 0x00, 0xc3, 0xc6, 0xcc, 0xd8, 0xf0, 0xfe, 0xc7, 0xc3, 0xc3, 0xc7, 0xfe}, 7132001f49Smrg{0x00, 0x00, 0x7e, 0xe7, 0x03, 0x03, 0x07, 0x7e, 0xe0, 0xc0, 0xc0, 0xe7, 0x7e}, 7232001f49Smrg{0x00, 0x00, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0xff}, 7332001f49Smrg{0x00, 0x00, 0x7e, 0xe7, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3}, 7432001f49Smrg{0x00, 0x00, 0x18, 0x3c, 0x3c, 0x66, 0x66, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3}, 7532001f49Smrg{0x00, 0x00, 0xc3, 0xe7, 0xff, 0xff, 0xdb, 0xdb, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3}, 7632001f49Smrg{0x00, 0x00, 0xc3, 0x66, 0x66, 0x3c, 0x3c, 0x18, 0x3c, 0x3c, 0x66, 0x66, 0xc3}, 7732001f49Smrg{0x00, 0x00, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x3c, 0x3c, 0x66, 0x66, 0xc3}, 7832001f49Smrg{0x00, 0x00, 0xff, 0xc0, 0xc0, 0x60, 0x30, 0x7e, 0x0c, 0x06, 0x03, 0x03, 0xff} 7932001f49Smrg}; 8032001f49Smrg 8132001f49SmrgGLuint fontOffset; 8232001f49Smrg 8332001f49Smrgstatic void makeRasterFont(void) 8432001f49Smrg{ 8532001f49Smrg GLuint i, j; 8632001f49Smrg glPixelStorei(GL_UNPACK_ALIGNMENT, 1); 8732001f49Smrg 8832001f49Smrg fontOffset = glGenLists (128); 8932001f49Smrg for (i = 0,j = 'A'; i < 26; i++,j++) { 9032001f49Smrg glNewList(fontOffset + j, GL_COMPILE); 9132001f49Smrg glBitmap(8, 13, 0.0, 2.0, 10.0, 0.0, letters[i]); 9232001f49Smrg glEndList(); 9332001f49Smrg } 9432001f49Smrg glNewList(fontOffset + ' ', GL_COMPILE); 9532001f49Smrg glBitmap(8, 13, 0.0, 2.0, 10.0, 0.0, space); 9632001f49Smrg glEndList(); 9732001f49Smrg} 9832001f49Smrg 9932001f49Smrgstatic void init(void) 10032001f49Smrg{ 10132001f49Smrg glShadeModel (GL_FLAT); 10232001f49Smrg makeRasterFont(); 10332001f49Smrg} 10432001f49Smrg 10532001f49Smrgstatic void printString(char *s) 10632001f49Smrg{ 10732001f49Smrg glPushAttrib (GL_LIST_BIT); 10832001f49Smrg glListBase(fontOffset); 10932001f49Smrg glCallLists((GLsizei) strlen(s), GL_UNSIGNED_BYTE, (GLubyte *) s); 11032001f49Smrg glPopAttrib (); 11132001f49Smrg} 11232001f49Smrg 11332001f49Smrg/* Everything above this line could be in a library 11432001f49Smrg * that defines a font. To make it work, you've got 11532001f49Smrg * to call makeRasterFont() before you start making 11632001f49Smrg * calls to printString(). 11732001f49Smrg */ 11832001f49Smrgstatic void display(void) 11932001f49Smrg{ 12032001f49Smrg GLfloat white[3] = { 1.0, 1.0, 1.0 }; 12132001f49Smrg 12232001f49Smrg glClear(GL_COLOR_BUFFER_BIT); 12332001f49Smrg glColor3fv(white); 12432001f49Smrg 12532001f49Smrg glRasterPos2i(20, 60); 12632001f49Smrg printString("THE QUICK BROWN FOX JUMPS"); 12732001f49Smrg glRasterPos2i(20, 40); 12832001f49Smrg printString("OVER A LAZY DOG"); 12932001f49Smrg glFlush (); 13032001f49Smrg} 13132001f49Smrg 13232001f49Smrgstatic void reshape(int w, int h) 13332001f49Smrg{ 13432001f49Smrg glViewport(0, 0, (GLsizei) w, (GLsizei) h); 13532001f49Smrg glMatrixMode(GL_PROJECTION); 13632001f49Smrg glLoadIdentity(); 13732001f49Smrg glOrtho (0.0, w, 0.0, h, -1.0, 1.0); 13832001f49Smrg glMatrixMode(GL_MODELVIEW); 13932001f49Smrg} 14032001f49Smrg 14132001f49Smrg/* ARGSUSED1 */ 14232001f49Smrgstatic void keyboard(unsigned char key, int x, int y) 14332001f49Smrg{ 14432001f49Smrg switch (key) { 14532001f49Smrg case 27: 14632001f49Smrg exit(0); 14732001f49Smrg } 14832001f49Smrg} 14932001f49Smrg 15032001f49Smrg/* Main Loop 15132001f49Smrg * Open window with initial window size, title bar, 15232001f49Smrg * RGBA display mode, and handle input events. 15332001f49Smrg */ 15432001f49Smrgint main(int argc, char** argv) 15532001f49Smrg{ 15632001f49Smrg glutInit(&argc, argv); 15732001f49Smrg glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); 15832001f49Smrg glutInitWindowSize(300, 100); 15932001f49Smrg glutInitWindowPosition (100, 100); 16032001f49Smrg glutCreateWindow(argv[0]); 16132001f49Smrg init(); 16232001f49Smrg glutReshapeFunc(reshape); 16332001f49Smrg glutKeyboardFunc(keyboard); 16432001f49Smrg glutDisplayFunc(display); 16532001f49Smrg glutMainLoop(); 16632001f49Smrg return 0; 16732001f49Smrg} 168