/* show_xbm.c uses xbmread to input a .xbm file, needs xbm.h */ #include static char filename[80]; static GLubyte rgbpix[4*100*100]; /* size bigger than smlogo.xbm */ static int width = 71; /* also read in */ static int height = 96; static int RGBA = 0xFF000000; /* check if black, alpha =1.0*/ static int RGBA_back = 0xFFFFFFFF; /* white background */ void display(void) { char *p; /* clear window */ glClear(GL_COLOR_BUFFER_BIT); glLoadIdentity (); glColor3f(0.0, 0.0, 0.0); /* draw .xbm files */ glPixelStorei(GL_UNPACK_ALIGNMENT, 1); glRasterPos2f(0.0, 0.0); glDrawPixels(width, height, GL_RGBA, GL_UNSIGNED_BYTE, rgbpix); /* draw text */ glEnable(GL_LINE_SMOOTH); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_BLEND); glLoadIdentity (); glTranslatef(-0.2, -0.6, 0.0); glScalef(0.0015, 0.0015, 0.0); for(p=filename; *p; p++) glutStrokeCharacter(GLUT_STROKE_ROMAN, *p); glFlush(); } void myreshape(int h, int w) { glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluOrtho2D(-1.0, 1.0, -1.0, 1.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glViewport(0,0,h,w); } void init() { int status, i, j, k; printf("test_xbmread calling xbmread on file %s\n", filename); status = xbmread(filename, RGBA, RGBA_back, &width, &height, rgbpix); printf("xbmread returned status=%d, width=%d, height=%d, RGBA=%X, RGBA_back=%X \n", status, width, height, RGBA, RGBA_back); /* set clear color to yellow */ glClearColor (0.0, 1.0, 1.0, 0.0); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluOrtho2D(-1.0, 1.0, -1.0, 1.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glViewport(0,0,300,300); } int main(int argc, char* argv[]) { glutInit(&argc,argv); glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB); glutInitWindowSize(300,300); glutInitWindowPosition(100,100); glutCreateWindow(argv[0]); glutReshapeFunc(myreshape); glutDisplayFunc(display); strcpy(filename, argv[1]); init(); glutMainLoop(); return 0; }