/* gif_to_gl.c uses gifread to input a .gif file, needs gif.h */ #include static char filename[] = "smlogo.gif"; static GLubyte rgbpix[3*39*44]; /* size bigger than smlogo.gif */ static width = 39; /* also read in */ static height = 44; static alpha = -1; static char filename2[] = "line.gif"; static GLubyte rgbpix2[4*100*50]; /* size for line.gif */ static width2 = 100; /* also read in */ static height2 = 50; static alpha2 = 255; void display(void) { char *p; GLubyte pixels[3]; int x=100, y=100; /* clear window */ glClear(GL_COLOR_BUFFER_BIT); glLoadIdentity (); glColor3f(0.0, 0.0, 0.0); /* draw .gif files */ glPixelStorei(GL_UNPACK_ALIGNMENT, 1); glRasterPos2f(-.75, -.75); glDrawPixels(width, height, GL_RGB, GL_UNSIGNED_BYTE, rgbpix); glRasterPos2f(0.0, 0.0); glDrawPixels(width2, height2, GL_RGBA, GL_UNSIGNED_BYTE, rgbpix2); /* 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); glLoadIdentity (); glTranslatef(0.1, 0.6, 0.0); glScalef(0.0015, 0.0015, 0.0); for(p=filename2; *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_gifread calling gifread on file %s\n", filename); status = gifread("smlogo.gif", alpha, &width, &height, rgbpix); printf("gifread returned status=%d, width=%d, height=%d, alpha=%d \n", status, width, height, alpha); status = gifread("line.gif", alpha2, &width2, &height2, rgbpix2); printf("gifread returned status=%d, width2=%d, height2=%d, alpha2=%d \n", status, width2, height2, alpha2); /* set clear color to green */ glClearColor (0.0, 1.0, 0.0, 0.0); /* set fill color to black */ glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluOrtho2D(-1.0, 1.0, -1.0, 1.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glViewport(0,0,200,200); } int main(int argc, char* argv[]) { glutInit(&argc,argv); glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB); glutInitWindowSize(200,200); glutInitWindowPosition(100,100); glutCreateWindow(argv[0]); glutReshapeFunc(myreshape); glutDisplayFunc(display); init(); glutMainLoop(); return 0; }