|
SUMO - Simulation of Urban MObility
|
00001 /* 00002 * GL2PS, an OpenGL to PostScript Printing Library 00003 * Copyright (C) 1999-2011 Christophe Geuzaine <geuz@geuz.org> 00004 * 00005 * This program is free software; you can redistribute it and/or 00006 * modify it under the terms of either: 00007 * 00008 * a) the GNU Library General Public License as published by the Free 00009 * Software Foundation, either version 2 of the License, or (at your 00010 * option) any later version; or 00011 * 00012 * b) the GL2PS License as published by Christophe Geuzaine, either 00013 * version 2 of the License, or (at your option) any later version. 00014 * 00015 * This program is distributed in the hope that it will be useful, but 00016 * WITHOUT ANY WARRANTY; without even the implied warranty of 00017 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See either 00018 * the GNU Library General Public License or the GL2PS License for 00019 * more details. 00020 * 00021 * You should have received a copy of the GNU Library General Public 00022 * License along with this library in the file named "COPYING.LGPL"; 00023 * if not, write to the Free Software Foundation, Inc., 675 Mass Ave, 00024 * Cambridge, MA 02139, USA. 00025 * 00026 * You should have received a copy of the GL2PS License with this 00027 * library in the file named "COPYING.GL2PS"; if not, I will be glad 00028 * to provide one. 00029 * 00030 * For the latest info about gl2ps and a full list of contributors, 00031 * see http://www.geuz.org/gl2ps/. 00032 * 00033 * Please report all bugs and problems to <gl2ps@geuz.org>. 00034 */ 00035 00036 /* 00037 To compile on Linux: 00038 gcc gl2psTestSimple.c gl2ps.c -lglut -lGL -lGLU -lX11 -lm 00039 00040 To compile on MacOSX: 00041 gcc gl2psTestSimple.c gl2ps.c -framework OpenGL -framework GLUT -framework Cocoa 00042 */ 00043 00044 #ifdef __APPLE__ 00045 # include <GLUT/glut.h> 00046 #else 00047 # include <GL/glut.h> 00048 #endif 00049 00050 #include <string.h> 00051 #include "gl2ps.h" 00052 00053 static void display(void) 00054 { 00055 unsigned int i; 00056 unsigned int N = 50; 00057 const char *help = "Press 's' to save image or 'q' to quit"; 00058 00059 glClearColor(0.3, 0.5, 0.8, 0.); 00060 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 00061 00062 /* draw a smooth-shaded torus */ 00063 glPushMatrix(); 00064 glRotatef(-60., 2., 0., 1.); 00065 glEnable(GL_LIGHTING); 00066 glutSolidTorus(0.3, 0.6, 30, 30); 00067 glDisable(GL_LIGHTING); 00068 glPopMatrix(); 00069 00070 glColor3f(1.,1.,1.); 00071 00072 /* draw a stippled line with many small segments (this tests the 00073 ability of gl2ps to render lines using as few strokes as 00074 possible) */ 00075 glEnable(GL_LINE_STIPPLE); 00076 glLineStipple(1, 0x087F); 00077 gl2psEnable(GL2PS_LINE_STIPPLE); 00078 glBegin(GL_LINE_STRIP); 00079 for(i = 0; i < N; i++) 00080 glVertex3f(-0.75 + 1.5 * (double)i/(double)(N - 1), 0.75, -0.9); 00081 glEnd(); 00082 glDisable(GL_LINE_STIPPLE); 00083 gl2psDisable(GL2PS_LINE_STIPPLE); 00084 00085 /* draw a text string */ 00086 glRasterPos2d(-0.9,-0.9); 00087 gl2psText(help, "Times-Roman", 24); 00088 for (i = 0; i < strlen(help); i++) 00089 glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, help[i]); 00090 00091 glFlush(); 00092 } 00093 00094 static void keyboard(unsigned char key, int x, int y) 00095 { 00096 FILE *fp; 00097 int state = GL2PS_OVERFLOW, buffsize = 0; 00098 00099 (void) x; (void) y; /* not used */ 00100 switch(key){ 00101 case 'q': 00102 exit(0); 00103 break; 00104 case 's': 00105 fp = fopen("out.eps", "wb"); 00106 printf("Writing 'out.eps'... "); 00107 while(state == GL2PS_OVERFLOW){ 00108 buffsize += 1024*1024; 00109 gl2psBeginPage("test", "gl2psTestSimple", NULL, GL2PS_EPS, GL2PS_SIMPLE_SORT, 00110 GL2PS_DRAW_BACKGROUND | GL2PS_USE_CURRENT_VIEWPORT, 00111 GL_RGBA, 0, NULL, 0, 0, 0, buffsize, fp, "out.eps"); 00112 display(); 00113 state = gl2psEndPage(); 00114 } 00115 fclose(fp); 00116 printf("Done!\n"); 00117 break; 00118 } 00119 } 00120 00121 int main(int argc, char **argv) 00122 { 00123 GLfloat pos[4] = {1., 1., -1., 0.}; 00124 00125 glutInit(&argc, argv); 00126 glutInitDisplayMode(GLUT_DEPTH); 00127 glutInitWindowSize(400, 400); 00128 glutInitWindowPosition(100, 100); 00129 glutCreateWindow(argv[0]); 00130 00131 glEnable(GL_DEPTH_TEST); 00132 glDepthFunc(GL_LESS); 00133 glShadeModel(GL_SMOOTH); 00134 glEnable(GL_LIGHT0); 00135 glLightfv(GL_LIGHT0, GL_POSITION, pos); 00136 00137 glutDisplayFunc(display); 00138 glutKeyboardFunc(keyboard); 00139 glutMainLoop(); 00140 return 0; 00141 }