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-2015 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 
71  /* draw three triangles on the same zplane and use polygon offset
72  to order the layers: the grey triangle should be drawn on the
73  middle layer */
74  glEnable(GL_POLYGON_OFFSET_FILL);
75  glPolygonOffset(1.0, 1.0);
77  glColor3f(0.,0.,0.);
78  glBegin(GL_TRIANGLES);
79  glVertex3f(0.6, 0.8, 0);
80  glVertex3f(0.8, 0.8, 0);
81  glVertex3f(0.7, 0.92, 0);
82  glEnd();
83 
84  glPolygonOffset(2.0, 2.0);
86  glColor3f(1.,1.,1.);
87  glBegin(GL_TRIANGLES);
88  glVertex3f(0.7, 0.8, 0);
89  glVertex3f(0.9, 0.8, 0);
90  glVertex3f(0.8, 0.92, 0);
91  glEnd();
92 
93  glPolygonOffset(1.5, 1.5);
95  glColor3f(0.5,0.5,0.5);
96  glBegin(GL_TRIANGLES);
97  glVertex3f(0.65, 0.86, 0);
98  glVertex3f(0.85, 0.86, 0);
99  glVertex3f(0.75, 0.98, 0);
100  glEnd();
101 
102  glDisable(GL_POLYGON_OFFSET_FILL);
104 
105  glColor3f(0.1,0.1,0.1);
106 
107  /* draw a stippled line with many small segments (this tests the
108  ability of gl2ps to render lines using as few strokes as
109  possible) */
110  glEnable(GL_LINE_STIPPLE);
111  glLineStipple(1, 0x087F);
113  glBegin(GL_LINE_STRIP);
114  for(i = 0; i < N; i++)
115  glVertex3f(-0.75 + 1.5 * (double)i/(double)(N - 1), 0.75, -0.9);
116  glEnd();
117  glDisable(GL_LINE_STIPPLE);
119 
120  /* draw a text string */
121  glRasterPos2d(-0.9,-0.9);
122  gl2psText(help, "Times-Roman", 24);
123  for (i = 0; i < strlen(help); i++)
124  glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, help[i]);
125 
126  glFlush();
127 }
128 
129 static void keyboard(unsigned char key, int x, int y)
130 {
131  FILE *fp;
132  int state = GL2PS_OVERFLOW, buffsize = 0;
133 
134  (void) x; (void) y; /* not used */
135  switch(key){
136  case 'q':
137  exit(0);
138  break;
139  case 's':
140  fp = fopen("out.eps", "wb");
141  printf("Writing 'out.eps'... ");
142  while(state == GL2PS_OVERFLOW){
143  buffsize += 1024*1024;
144  gl2psBeginPage("test", "gl2psTestSimple", NULL, GL2PS_EPS, GL2PS_SIMPLE_SORT,
146  GL_RGBA, 0, NULL, 0, 0, 0, buffsize, fp, "out.eps");
147  display();
148  state = gl2psEndPage();
149  }
150  fclose(fp);
151  printf("Done!\n");
152  break;
153  }
154 }
155 
156 int main(int argc, char **argv)
157 {
158  GLfloat pos[4] = {1., 1., -1., 0.};
159 
160  glutInit(&argc, argv);
161  glutInitDisplayMode(GLUT_DEPTH);
162  glutInitWindowSize(400, 400);
163  glutInitWindowPosition(100, 100);
164  glutCreateWindow(argv[0]);
165 
166  glEnable(GL_DEPTH_TEST);
167  glDepthFunc(GL_LESS);
168  glShadeModel(GL_SMOOTH);
169  glEnable(GL_LIGHT0);
170  glLightfv(GL_LIGHT0, GL_POSITION, pos);
171 
172  glutDisplayFunc(display);
173  glutKeyboardFunc(keyboard);
174  glutMainLoop();
175  return 0;
176 }
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:5690
#define GL2PS_DRAW_BACKGROUND
Definition: gl2ps.h:127
GL2PSDLL_API GLint gl2psText(const char *str, const char *fontname, GLshort fontsize)
Definition: gl2ps.c:5921
static void display(void)
#define GL2PS_LINE_STIPPLE
Definition: gl2ps.h:145
static void keyboard(unsigned char key, int x, int y)
#define GL2PS_USE_CURRENT_VIEWPORT
Definition: gl2ps.h:136
GL2PSDLL_API GLint gl2psEndPage(void)
Definition: gl2ps.c:5857
int main(int argc, char **argv)
#define GL2PS_SIMPLE_SORT
Definition: gl2ps.h:111
GL2PSDLL_API GLint gl2psDisable(GLint mode)
Definition: gl2ps.c:6081
#define GL2PS_POLYGON_OFFSET_FILL
Definition: gl2ps.h:143
GL2PSDLL_API GLint gl2psEnable(GLint mode)
Definition: gl2ps.c:6045
#define GL2PS_OVERFLOW
Definition: gl2ps.h:121
#define GL2PS_EPS
Definition: gl2ps.h:102