SUMO - Simulation of Urban MObility
gl2psTestSimple.c
Go to the documentation of this file.
1 /*
2  * GL2PS, an OpenGL to PostScript Printing Library
3  * Copyright (C) 1999-2012 Christophe Geuzaine <geuz@geuz.org>
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of either:
7  *
8  * a) the GNU Library General Public License as published by the Free
9  * Software Foundation, either version 2 of the License, or (at your
10  * option) any later version; or
11  *
12  * b) the GL2PS License as published by Christophe Geuzaine, either
13  * version 2 of the License, or (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful, but
16  * WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See either
18  * the GNU Library General Public License or the GL2PS License for
19  * more details.
20  *
21  * You should have received a copy of the GNU Library General Public
22  * License along with this library in the file named "COPYING.LGPL";
23  * if not, write to the Free Software Foundation, Inc., 51 Franklin
24  * Street, Fifth Floor, Boston, MA 02110-1301, USA.
25  *
26  * You should have received a copy of the GL2PS License with this
27  * library in the file named "COPYING.GL2PS"; if not, I will be glad
28  * to provide one.
29  *
30  * For the latest info about gl2ps and a full list of contributors,
31  * see http://www.geuz.org/gl2ps/.
32  *
33  * Please report all bugs and problems to <gl2ps@geuz.org>.
34  */
35 
36 /*
37  To compile on Linux:
38  gcc gl2psTestSimple.c gl2ps.c -lglut -lGL -lGLU -lX11 -lm
39 
40  To compile on MacOSX:
41  gcc gl2psTestSimple.c gl2ps.c -framework OpenGL -framework GLUT -framework Cocoa
42 */
43 
44 #ifdef __APPLE__
45 # include <GLUT/glut.h>
46 #else
47 # include <GL/glut.h>
48 #endif
49 
50 #include <string.h>
51 #include "gl2ps.h"
52 
53 static void display(void)
54 {
55  unsigned int i;
56  unsigned int N = 50;
57  const char *help = "Press 's' to save image or 'q' to quit";
58 
59  glClearColor(0.3, 0.5, 0.8, 0.);
60  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
61 
62  /* draw a smooth-shaded torus */
63  glPushMatrix();
64  glRotatef(-60., 2., 0., 1.);
65  glEnable(GL_LIGHTING);
66  glutSolidTorus(0.3, 0.6, 30, 30);
67  glDisable(GL_LIGHTING);
68  glPopMatrix();
69 
70  glColor3f(1.,1.,1.);
71 
72  /* draw a stippled line with many small segments (this tests the
73  ability of gl2ps to render lines using as few strokes as
74  possible) */
75  glEnable(GL_LINE_STIPPLE);
76  glLineStipple(1, 0x087F);
78  glBegin(GL_LINE_STRIP);
79  for(i = 0; i < N; i++)
80  glVertex3f(-0.75 + 1.5 * (double)i/(double)(N - 1), 0.75, -0.9);
81  glEnd();
82  glDisable(GL_LINE_STIPPLE);
84 
85  /* draw a text string */
86  glRasterPos2d(-0.9,-0.9);
87  gl2psText(help, "Times-Roman", 24);
88  for (i = 0; i < strlen(help); i++)
89  glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, help[i]);
90 
91  glFlush();
92 }
93 
94 static void keyboard(unsigned char key, int x, int y)
95 {
96  FILE *fp;
97  int state = GL2PS_OVERFLOW, buffsize = 0;
98 
99  (void) x; (void) y; /* not used */
100  switch(key){
101  case 'q':
102  exit(0);
103  break;
104  case 's':
105  fp = fopen("out.eps", "wb");
106  printf("Writing 'out.eps'... ");
107  while(state == GL2PS_OVERFLOW){
108  buffsize += 1024*1024;
109  gl2psBeginPage("test", "gl2psTestSimple", NULL, GL2PS_EPS, GL2PS_SIMPLE_SORT,
111  GL_RGBA, 0, NULL, 0, 0, 0, buffsize, fp, "out.eps");
112  display();
113  state = gl2psEndPage();
114  }
115  fclose(fp);
116  printf("Done!\n");
117  break;
118  }
119 }
120 
121 int main(int argc, char **argv)
122 {
123  GLfloat pos[4] = {1., 1., -1., 0.};
124 
125  glutInit(&argc, argv);
126  glutInitDisplayMode(GLUT_DEPTH);
127  glutInitWindowSize(400, 400);
128  glutInitWindowPosition(100, 100);
129  glutCreateWindow(argv[0]);
130 
131  glEnable(GL_DEPTH_TEST);
132  glDepthFunc(GL_LESS);
133  glShadeModel(GL_SMOOTH);
134  glEnable(GL_LIGHT0);
135  glLightfv(GL_LIGHT0, GL_POSITION, pos);
136 
137  glutDisplayFunc(display);
138  glutKeyboardFunc(keyboard);
139  glutMainLoop();
140  return 0;
141 }
GL2PSDLL_API GLint gl2psBeginPage(const char *title, const char *producer, GLint viewport[4], GLint format, GLint sort, GLint options, GLint colormode, GLint colorsize, GL2PSrgba *colormap, GLint nr, GLint ng, GLint nb, GLint buffersize, FILE *stream, const char *filename)
Definition: gl2ps.c:5650
#define GL2PS_DRAW_BACKGROUND
Definition: gl2ps.h:126
GL2PSDLL_API GLint gl2psText(const char *str, const char *fontname, GLshort fontsize)
Definition: gl2ps.c:5881
static void display(void)
#define GL2PS_LINE_STIPPLE
Definition: gl2ps.h:144
static void keyboard(unsigned char key, int x, int y)
#define GL2PS_USE_CURRENT_VIEWPORT
Definition: gl2ps.h:135
GL2PSDLL_API GLint gl2psEndPage(void)
Definition: gl2ps.c:5817
int main(int argc, char **argv)
#define GL2PS_SIMPLE_SORT
Definition: gl2ps.h:110
GL2PSDLL_API GLint gl2psDisable(GLint mode)
Definition: gl2ps.c:6036
GL2PSDLL_API GLint gl2psEnable(GLint mode)
Definition: gl2ps.c:6003
#define GL2PS_OVERFLOW
Definition: gl2ps.h:120
#define GL2PS_EPS
Definition: gl2ps.h:101