SUMO - Simulation of Urban MObility
gl2psTest.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 gl2psTest.c gl2ps.c -lglut -lGL -lGLU -lX11 -lm
39 
40  To compile on MacOSX:
41  gcc gl2psTest.c gl2ps.c -framework OpenGL -framework GLUT -framework Cocoa
42 
43  (To enable file compression you must add "-DHAVE_ZLIB -lz" to the
44  commands above. To enable embedded bitmaps in SVG files you must
45  add "-DHAVE_LIBPNG -DHAVE_ZLIB -lpng -lz".)
46 */
47 
48 #ifdef _MSC_VER /* MSVC Compiler */
49 #pragma comment(linker, "/entry:\"mainCRTStartup\"")
50 #endif
51 
52 #include "gl2ps.h"
53 
54 #include <string.h>
55 #ifdef __APPLE__
56 # include <GLUT/glut.h>
57 #else
58 # include <GL/glut.h>
59 #endif
60 
61 static const char *format_string = "Postscript";
62 static float rotation = -58.;
63 static GLsizei window_w = 0;
64 static GLsizei window_h = 0;
65 static GLboolean display_multi = GL_TRUE;
66 static GLboolean blend = GL_FALSE;
67 static GLboolean teapot = GL_FALSE;
68 static const char *pixmap[] = {
69  "****************************************************************",
70  "*..............................................................*",
71  "*..................++++++++++++++++++++++++++..................*",
72  "*.............+++++++++++++++++++++++++++++++++++++............*",
73  "*.......++++++++++++aaaaaaaaaaaaaaaaaaaaaaaa++++++++++++.......*",
74  "*.......++++++aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa++++++.......*",
75  "*.......++aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa++.......*",
76  "*.......++aaaa++++aa+aaaaaaaa++++aaa++++++aaa+++++aaaa++.......*",
77  "*.......++aaa+aaaa+a+aaaaaaa+aaaa+aa+aaaaa+a+aaaaa+aaa++.......*",
78  "*.......++aa+aaaaaaa+aaaaaaaaaaa+aaa+aaaaa+a+aaaaaaaaa++.......*",
79  "*.......++aa+aaa+++a+aaaaaaaaaa+aaaa++++++aaa+++++aaaa++.......*",
80  "*.......++aa+aaaaa+a+aaaaaaaaa+aaaaa+aaaaaaaaaaaaa+aaa++.......*",
81  "*.......++aaa+aaaa+a+aaaaaaaa+aaaaaa+aaaaaaa+aaaaa+aaa++.......*",
82  "*.......++aaaa+++++a++++++aa++++++aa+aaaaaaaa+++++aaaa++.......*",
83  "*.......++aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa++.......*",
84  "*.......++aaaaaaaaa++++++++++++++++++++++++++aaaaaaaaa++.......*",
85  "*.......++aaa+++++++@@@@@@@@@@@+++++++++++++++++++aaaa++.......*",
86  "*.......++++++@@+@@@+@@@++@@@@@+++++++++++++++++++++++++.......*",
87  "*.......++@@@@@+@@@+@@@+@@@@+@@+++++++++++++++++++++++++.......*",
88  "*.......++@@@@+@@@+@@+++++++@@@+++++++++++++++++++++++++.......*",
89  "*.......++@@@@+++++++@@@@@@++@@++#####################++.......*",
90  "*.......++@+++++@@@@@@@@@@@@@@@++#####################++.......*",
91  "*.......++@+++@@@@@@@@@@@@@@@@@++#####################++.......*",
92  "*.......++@++@@@@@@@+@@+@@@@@@@++#####################++.......*",
93  "*.......++@@@@@+@@@+@@+@@@@@@@@++#####################++.......*",
94  "*.......++@@@@+@@@+@@+@@++++++++++++++++++++++++++++++++.......*",
95  "*.......++@@@@+@+++++++++@++++@+@+@+++++++++++++++++++++.......*",
96  "*.......++@@@@+++@@@@@@@+@++@+++@+@+@+@+++++++++++++++++.......*",
97  "*.......++@++++@@@@@@@@@@+@+++@+@+@+++++++++++++++++++++.......*",
98  "*.......++@+++@@@@@@@@@@+@@@@@@@@@@@@@@+++++++++++++++++.......*",
99  "*.......++@++@@@@@@+@@+@+@@@+++@@@@@@@@+++++++++++++++++.......*",
100  "*.......++@@@@@+@@+@@+@@+@@+++++@@@@@@@+##############++.......*",
101  "*.......++@@@@+@@+@@+@@++@@+@+++@@@@@+@+##############++.......*",
102  "*.......++@@@@+@+++++++@+@@@@+++@@@@++@+##############++.......*",
103  "*.......++@++++++@@@@@@++@@@@+++@@@@++@+##############++.......*",
104  "*.......++@+++@@@@@@@@@@+@@@+++++@@@+@@+##############++.......*",
105  "*.......++@++@@@@@@@@@@@+@+++++++++++@@+##############++.......*",
106  "*.......+++++++++++++++++@+@+++++++++@@+++++++++++++++++.......*",
107  "*.......+++++++++++++++++@+@+@@@@++++@@+@@@@@@@@@@@@@@++.......*",
108  "*.......+++++++++++++++++@@@+@@@@@+@+@@+@@@+@@+@@@@@@@++.......*",
109  "*........++++++++++++++++@@@@+@@@++@++@+@@+@@+@@@+@@@++........*",
110  "*........++++++++++++++++@@@@@@@@+@@+@@+@+@@+@@@+@@@@++........*",
111  "*........+++++++++++++++++@@@@@@+@@+@@+@++++++++++@@@++........*",
112  "*.........++##############+@@@@@@@@@@++++@@@@@@@@++@++.........*",
113  "*.........++###############+@@@@@@@@++++@@@@@@@@@@@@++.........*",
114  "*..........++###############++++++++@@@@@@@+@@+@@@@++..........*",
115  "*..........++##################++@@@@@+@@@+@@+@@+@@++..........*",
116  "*...........++#################++@@@@+@@@+@@+@@+@@++...........*",
117  "*...........++#################++@@@+@@++++++++@@@++...........*",
118  "*............++++++++++++++++++++@@@++++@@@@@@++@++............*",
119  "*.............+++++++++++++++++++@@+++@@@@@@@@@@@+.............*",
120  "*.............+++++++++++++++++++@+++@@@@@@@@@@@++.............*",
121  "*..............++++++++++++++++++@++@@@@+@@@@@@++..............*",
122  "*...............+++++++++++++++++@@@+@@+@@+@@@++...............*",
123  "*................++++++++++++++++@@+@@+@@+@@@++................*",
124  "*.................++###########++@@+++++++@@++.................*",
125  "*..................++##########++@+++@@@@+@++..................*",
126  "*...................++#########++@++@@@@@@++...................*",
127  "*....................+++#######++@++@@@@+++....................*",
128  "*.....................++++#####++@@@@@++++.....................*",
129  "*.......................++++###++@@@++++.......................*",
130  "*.........................++++#++@++++.........................*",
131  "*...........................++++++++...........................*",
132  "*.............................++++.............................*",
133  "*..............................................................*",
134  "****************************************************************"};
135 
136 void triangles()
137 {
138  /* two intersecting triangles */
139  glBegin(GL_TRIANGLES);
140 
141  glColor3f(1., 0., 0.);
142  glVertex3f(-1., 0.9, 0.);
143  glColor4f(1., 1., 0., 0.1);
144  glVertex3f(-1., 0., 0.);
145  glColor4f(1., 0., 1., 1.0);
146  glVertex3f(1., 0., 0.2);
147 
148  glColor3f(0., 1., 0.);
149  glVertex3f(1., 0., 0.);
150  glColor3f(0., 1., 1.);
151  glVertex3f(1., 0.5, 0.);
152  glColor3f(0., 1., 1.);
153  glVertex3f(-1., 0.5, 0.1);
154 
155  glEnd();
156 }
157 
158 void extras()
159 {
160  glColor3f(1., 0., 0.);
161 
162  glPointSize(1.);
163  gl2psPointSize(1.);
164  glBegin(GL_POINTS);
165  glVertex3f(-1., 1.0, 0.);
166  glEnd();
167 
168  glPointSize(3.);
169  gl2psPointSize(3.);
170  glBegin(GL_POINTS);
171  glVertex3f(-0.8, 1.0, 0.);
172  glEnd();
173 
174  glPointSize(5.);
175  gl2psPointSize(5.);
176  glBegin(GL_POINTS);
177  glVertex3f(-0.6, 1.0, 0.);
178  glEnd();
179 
180  glPointSize(7.);
181  gl2psPointSize(7.);
182  glBegin(GL_POINTS);
183  glVertex3f(-0.4, 1.0, 0.);
184  glEnd();
185 
186  glLineWidth(1.);
187  gl2psLineWidth(1.);
188  glBegin(GL_LINES);
189  glVertex3f(-0.2, 1.05, 0.);
190  glVertex3f(0.2, 1.05, 0.);
191  glEnd();
192 
193  glEnable(GL_LINE_STIPPLE);
194  glLineStipple(1, 0x087F);
196  glBegin(GL_LINES);
197  glVertex3f(-0.2, 0.95, 0.);
198  glVertex3f(0.2, 0.95, 0.);
199  glEnd();
200  glDisable(GL_LINE_STIPPLE);
202 
203  glLineWidth(3.);
204  gl2psLineWidth(3.);
205  glBegin(GL_LINES);
206  glVertex3f(0.4, 1.05, 0.);
207  glVertex3f(0.8, 1.05, 0.);
208  glEnd();
209 
210  glEnable(GL_LINE_STIPPLE);
211  glLineStipple(2, 0x0F0F);
212  /* glLineStipple(1, 0xAAAA); */
214  glBegin(GL_LINES);
215  glVertex3f(0.4, 0.95, 0.);
216  glVertex3f(0.8, 0.95, 0.);
217  glEnd();
218  glDisable(GL_LINE_STIPPLE);
220 
221  glPointSize(1);
222  gl2psPointSize(1);
223  glLineWidth(1);
224  gl2psLineWidth(1);
225 }
226 
227 void objects()
228 {
229  glPushMatrix();
230  glEnable(GL_LIGHTING);
231  glRotatef(rotation, 2., 0., 1.);
232  glColor4d(0.2, 0.2, 0.9, 0.2);
233  if(teapot == GL_TRUE){
234  glutSolidTeapot(0.7);
235  }
236  else{
237  glutSolidTorus(0.3, 0.6, 20, 20);
238  }
239  glDisable(GL_LIGHTING);
240  glPopMatrix();
241 }
242 
243 void printstring(const char *string, float angle)
244 {
245  unsigned int i;
246  const char *fonts[] =
247  { "Times-Roman", "Times-Bold", "Times-Italic", "Times-BoldItalic",
248  "Helvetica", "Helvetica-Bold", "Helvetica-Oblique", "Helvetica-BoldOblique",
249  "Courier", "Courier-Bold", "Courier-Oblique", "Courier-BoldOblique",
250  "Symbol", "ZapfDingbats" };
251 
252  /* call gl2psText before the glut function since glutBitmapCharacter
253  changes the raster position... */
254  gl2psTextOpt(string, fonts[4], 12, GL2PS_TEXT_BL, angle);
255 
256  for (i = 0; i < strlen(string); i++)
257  glutBitmapCharacter(GLUT_BITMAP_HELVETICA_12, string[i]);
258 }
259 
260 void text()
261 {
262  double x = -1.25, y = -0.33, dy = 0.13;
263 
264  glColor3f(1., 1., 0.);
265 
266  glRasterPos2d(x, y);
267  printstring("Press:", 0.);
268  y -= dy;
269  glRasterPos2d(x, y);
270  printstring(" p: to change the print format (PS, EPS, PDF, ...)", 0.);
271  y -= dy;
272  glRasterPos2d(x, y);
273  printstring(" s: to save the images", 0.);
274  y -= dy;
275  glRasterPos2d(x, y);
276  printstring(" t: to alternate between teapot and torus", 0.);
277  y -= dy;
278  glRasterPos2d(x, y);
279  printstring(" v: to alternate between single and multiple viewport modes", 0.);
280  y -= dy;
281  glRasterPos2d(x, y);
282  printstring(" b: to change the blending mode (transparency)", 0.);
283  y -= dy;
284  glRasterPos2d(x, y);
285  printstring(" q: to quit", 0.);
286  y -= dy;
287  glRasterPos2d(x, y);
288  printstring("Click and move the mouse to rotate the objects", 0.);
289 
290  glRasterPos2d(0, 0.75);
291  printstring("rotated!", 45.);
292 
293  glRasterPos2d(x, 1.15);
295 
296  gl2psSpecial(GL2PS_TEX, "% This should only be printed in LaTeX output!");
297 }
298 
299 void cube()
300 {
301  glColor3d (0.0,1.0,0.);
302  glBegin(GL_POLYGON);
303  glVertex3d( 0.5,-0.5,-0.5);
304  glColor4d (0.0,1.0,0.,0.2);
305  glVertex3d( 0.5, 0.5,-0.5);
306  glVertex3d(-0.5, 0.5,-0.5);
307  glColor4d (0.0,1.0,0.,1);
308  glVertex3d(-0.5,-0.5,-0.5);
309  glEnd();
310 
311  glColor3d (1.0,0.0,0.);
312  glBegin(GL_POLYGON);
313  glColor4d (1.0,0.0,0.,0.1);
314  glVertex3d( 0.5,-0.5,0.5);
315  glColor4d (1.0,0.5,1.,0.9);
316  glVertex3d( 0.5, 0.5,0.5);
317  glVertex3d(-0.5, 0.5,0.5);
318  glColor4d (1.0,0.5,1.,0.1);
319  glVertex3d(-0.5,-0.5,0.5);
320  glEnd();
321  glLineWidth(4.0);
322  glColor3d (1.0,1.0,0.);
323  glBegin(GL_LINES);
324  glVertex3d( 0.5,-0.5, 0.5);
325  glVertex3d( 0.5,-0.5,-0.5);
326  glVertex3d( 0.5, 0.5, 0.5);
327  glVertex3d( 0.5, 0.5,-0.5);
328  glVertex3d(-0.5, 0.5, 0.5);
329  glVertex3d(-0.5, 0.5,-0.5);
330  glVertex3d(-0.5,-0.5, 0.5);
331  glVertex3d(-0.5,-0.5,-0.5);
332  glEnd();
333 }
334 
335 void image(float x, float y, GLboolean opaque)
336 {
337  int w = 64, h = 66, row, col, pos = 0;
338  float *pixels, r = 0., g = 0., b = 0.;
339 
340  /* Fill a pixmap (each pixel contains three floats defining an RGB
341  color) */
342  pixels = (opaque == GL_TRUE)
343  ? (float*)malloc(3 * w * h * sizeof(float))
344  : (float*)malloc(4 * w * h * sizeof(float));
345 
346  for(row = h-1; row >= 0; row--){
347  for(col = 0; col < w; col++){
348  switch(pixmap[row][col]){
349  case '.' : r = 255.; g = 255.; b = 255.; break;
350  case '+' : r = 0. ; g = 0. ; b = 0. ; break;
351  case '@' : r = 255.; g = 209.; b = 0. ; break;
352  case '#' : r = 255.; g = 0. ; b = 0. ; break;
353  case 'a' : r = 255.; g = 209.; b = 0. ; break;
354  case '*' : r = 0.; g = 0. ; b = 20. ; break;
355  }
356  r /= 255.; g /= 255.; b /= 255.;
357  pixels[pos] = r; pos++;
358  pixels[pos] = g; pos++;
359  pixels[pos] = b; pos++;
360 
361  if(opaque)
362  continue;
363 
364  switch(pixmap[row][col]){
365  case '.' : pixels[pos] = col / (float)w ; break;
366  case 'a' : pixels[pos] = 1 - col / ((float)w - 7) ; break;
367  default : pixels[pos] = 1. ; break;
368  }
369  pos++;
370  }
371  }
372 
373  glRasterPos2f(x, y);
374 
375  /* call gl2psDrawPixels first since glDrawPixels can change the
376  raster position */
377  if(opaque){
378  gl2psDrawPixels((GLsizei)w, (GLsizei)h, 0, 0, GL_RGB, GL_FLOAT, pixels);
379  glDrawPixels((GLsizei)w, (GLsizei)h, GL_RGB, GL_FLOAT, pixels);
380  }
381  else{
382  gl2psDrawPixels((GLsizei)w, (GLsizei)h, 0, 0, GL_RGBA, GL_FLOAT, pixels);
383  glDrawPixels((GLsizei)w, (GLsizei)h, GL_RGBA, GL_FLOAT, pixels);
384  }
385  free(pixels);
386 }
387 
388 /* A simple drawing function, using the default viewport */
390 {
391  glScissor(0, 0, window_w, window_h);
392  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
393  triangles();
394  extras();
395  objects();
396  text();
397  glFlush();
398 }
399 
400 /* A more complex drawing function, using 2 separate viewports */
402 {
403  GLint viewport[4];
404 
405  glScissor(0, 0, window_w, window_h);
406  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
407 
408  /* First viewport with triangles, teapot or torus, etc. */
409  glViewport((GLint)(window_w * 0.05), (GLint)(window_h * 0.525),
410  (GLsizei)(window_w * 0.9), (GLsizei)(window_h * 0.45));
411  glScissor((GLint)(window_w * 0.05), (GLint)(window_h * 0.525),
412  (GLsizei)(window_w * 0.9), (GLsizei)(window_h * 0.45));
413  glClearColor(0.2, 0.2, 0.2, 0.);
414  glGetIntegerv(GL_VIEWPORT, viewport);
415 
416  gl2psBeginViewport(viewport);
417 
418  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
419  glMatrixMode(GL_PROJECTION);
420  glLoadIdentity();
421  glOrtho(-1.3,1.3, -1.3,1.3, -1.3,1.3);
422  glMatrixMode(GL_MODELVIEW);
423 
424  objects();
425  triangles();
426  extras();
427  text();
428 
430 
431  /* Second viewport with cube, image, etc. */
432  glViewport((GLint)(window_w * 0.05), (GLint)(window_h * 0.025),
433  (GLsizei)(window_w * 0.9), (GLsizei)(window_h * 0.45));
434  glScissor((GLint)(window_w * 0.05), (GLint)(window_h * 0.025),
435  (GLsizei)(window_w * 0.9), (GLsizei)(window_h * 0.45));
436  glClearColor(0.8, 0.8, 0.8, 0.);
437  glGetIntegerv(GL_VIEWPORT, viewport);
438 
439  gl2psBeginViewport(viewport);
440 
441  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
442  glMatrixMode(GL_PROJECTION);
443  glLoadIdentity();
444  glOrtho(-1.3,1.3, -1.3,1.3, -1.3,1.3);
445  glMatrixMode(GL_MODELVIEW);
446 
447  glPushMatrix();
448  glRotatef(rotation, 1., 1., 1.);
449  image(-0.8, -0.3, GL_TRUE);
450  cube();
451  extras();
452  image(-0.8, 0.4, GL_FALSE);
453  glPopMatrix();
454 
456 
457  glClearColor(0.5, 0.5, 0.5, 0.);
458  glFlush();
459 }
460 
461 void display()
462 {
463  GLfloat spec[4] = {0.6, 0.6, 0.6, 1.0};
464  glEnable(GL_DEPTH_TEST);
465  glDepthFunc(GL_LESS);
466  glShadeModel(GL_SMOOTH);
467  glEnable(GL_LIGHT0);
468  glEnable(GL_SCISSOR_TEST);
469  glEnable(GL_COLOR_MATERIAL);
470  glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
471  glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, spec);
472  glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 60);
473  if(blend){
474  glEnable(GL_BLEND);
475  glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
476  }
477  else{
478  glDisable(GL_BLEND);
479  }
480  if(display_multi == GL_TRUE){
481  draw_multi();
482  }
483  else{
484  draw_single();
485  }
486 }
487 
488 void reshape(int w, int h)
489 {
490  window_w = w;
491  window_h = h;
492 
493  glViewport(0, 0, (GLsizei)window_w, (GLsizei)window_h);
494  glMatrixMode(GL_PROJECTION);
495  glLoadIdentity();
496  glOrtho(-1.3,1.3, -1.3,1.3, -1.3,1.3);
497  glMatrixMode(GL_MODELVIEW);
498 
499  glClearColor(0.5, 0.5, 0.5, 0.);
500  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
501 }
502 
503 void writefile(int format, int sort, int options, int nbcol,
504  const char *filename, const char *extension)
505 {
506  FILE *fp;
507  char file[256];
508  int state = GL2PS_OVERFLOW, buffsize = 0;
509  GLint viewport[4];
510 
511  strcpy(file, filename);
512  strcat(file, ".");
513  strcat(file, extension);
514 
515  viewport[0] = 0;
516  viewport[1] = 0;
517  viewport[2] = window_w;
518  viewport[3] = window_h;
519 
520  fp = fopen(file, "wb");
521 
522  if(!fp){
523  printf("Unable to open file %s for writing\n", file);
524  exit(1);
525  }
526 
527  printf("Saving image to file %s... ", file);
528  fflush(stdout);
529 
530  while(state == GL2PS_OVERFLOW){
531  buffsize += 1024*1024;
532  gl2psBeginPage(file, "gl2psTest", viewport, format, sort, options,
533  GL_RGBA, 0, NULL, nbcol, nbcol, nbcol,
534  buffsize, fp, file);
535  display();
536  state = gl2psEndPage();
537  }
538 
539  fclose(fp);
540 
541  printf("Done!\n");
542  fflush(stdout);
543 }
544 
545 void keyboard(unsigned char key, int x, int y)
546 {
547  int opt;
548  char ext[32];
549  static int format = GL2PS_PS;
550 
551  switch(key){
552  case 27:
553  case 'q':
554  exit(0);
555  break;
556  case 't':
557  teapot = (teapot) ? GL_FALSE : GL_TRUE;
558  display();
559  break;
560  case 'p':
561  if (format == GL2PS_PS) format = GL2PS_EPS;
562  else if(format == GL2PS_EPS) format = GL2PS_TEX;
563  else if(format == GL2PS_TEX) format = GL2PS_PDF;
564  else if(format == GL2PS_PDF) format = GL2PS_SVG;
565  else if(format == GL2PS_SVG) format = GL2PS_PGF;
566  else format = GL2PS_PS;
568  display();
569  break;
570  case 'b':
571  blend = !blend;
572  display();
573  break;
574  case 'v':
575  display_multi = display_multi ? GL_FALSE : GL_TRUE;
577  display();
578  break;
579  case 's':
580  strcpy(ext, gl2psGetFileExtension(format));
581 
582  opt = GL2PS_DRAW_BACKGROUND;
583  writefile(format, GL2PS_SIMPLE_SORT, opt, 0, "outSimple", ext);
584 
586  writefile(format, GL2PS_SIMPLE_SORT, opt, 0, "outSimpleCulled", ext);
587 
589  writefile(format, GL2PS_SIMPLE_SORT, opt, 2, "outSimpleShading2", ext);
590  writefile(format, GL2PS_SIMPLE_SORT, opt, 8, "outSimpleShading8", ext);
591  writefile(format, GL2PS_SIMPLE_SORT, opt, 16, "outSimpleShading16", ext);
592 
593  opt = GL2PS_NO_TEXT;
594  writefile(format, GL2PS_SIMPLE_SORT, opt, 0, "outSimpleNoText", ext);
595 
597  writefile(format, GL2PS_BSP_SORT, opt, 0, "outBsp", ext);
598 
600  writefile(format, GL2PS_BSP_SORT, opt, 0, "outBspCulled", ext);
601 
602 #ifdef GL2PS_HAVE_ZLIB
604  if(format == GL2PS_PS || format == GL2PS_EPS) strcat(ext, ".gz");
605  else if(format == GL2PS_SVG) strcat(ext, "z");
606  writefile(format, GL2PS_BSP_SORT, opt, 0, "outBspCulledCompressed", ext);
607 #endif
608 
609  printf("GL2PS %d.%d.%d%s done with all images\n", GL2PS_MAJOR_VERSION,
611  break;
612  }
613 }
614 
615 void motion(int x, int y)
616 {
617  rotation += 10.;
618  display();
619 }
620 
621 int main(int argc, char **argv)
622 {
623  glutInit(&argc, argv);
624  glutInitDisplayMode(GLUT_SINGLE | GLUT_DEPTH);
625  glutInitWindowSize(400, 600);
626  glutInitWindowPosition(100, 100);
627  glutCreateWindow(argv[0]);
628  glutDisplayFunc(display);
629  glutReshapeFunc(reshape);
630  glutKeyboardFunc(keyboard);
631  glutMotionFunc(motion);
632  glutMainLoop();
633  return 0;
634 }
#define GL2PS_PS
Definition: gl2ps.h:101
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
void draw_multi()
Definition: gl2psTest.c:401
static const char * pixmap[]
Definition: gl2psTest.c:68
static GLsizei window_w
Definition: gl2psTest.c:63
void objects()
Definition: gl2psTest.c:227
GL2PSDLL_API GLint gl2psBeginViewport(GLint viewport[4])
Definition: gl2ps.c:5884
#define GL2PS_DRAW_BACKGROUND
Definition: gl2ps.h:127
void motion(int x, int y)
Definition: gl2psTest.c:615
#define GL2PS_EXTRA_VERSION
Definition: gl2ps.h:91
static GLsizei window_h
Definition: gl2psTest.c:64
void image(float x, float y, GLboolean opaque)
Definition: gl2psTest.c:335
#define GL2PS_MAJOR_VERSION
Definition: gl2ps.h:88
#define GL2PS_OCCLUSION_CULL
Definition: gl2ps.h:131
void draw_single()
Definition: gl2psTest.c:389
#define GL2PS_LINE_STIPPLE
Definition: gl2ps.h:145
#define GL2PS_TEXT_BL
Definition: gl2ps.h:158
void reshape(int w, int h)
Definition: gl2psTest.c:488
int main(int argc, char **argv)
Definition: gl2psTest.c:621
void printstring(const char *string, float angle)
Definition: gl2psTest.c:243
void cube()
Definition: gl2psTest.c:299
#define GL2PS_PGF
Definition: gl2ps.h:106
GL2PSDLL_API GLint gl2psSpecial(GLint format, const char *str)
Definition: gl2ps.c:5927
void keyboard(unsigned char key, int x, int y)
Definition: gl2psTest.c:545
#define GL2PS_PATCH_VERSION
Definition: gl2ps.h:90
GL2PSDLL_API GLint gl2psEndPage(void)
Definition: gl2ps.c:5857
#define GL2PS_COMPRESS
Definition: gl2ps.h:137
GL2PSDLL_API const char * gl2psGetFileExtension(GLint format)
Definition: gl2ps.c:6162
#define GL2PS_TIGHT_BOUNDING_BOX
Definition: gl2ps.h:139
#define GL2PS_BSP_SORT
Definition: gl2ps.h:112
static float rotation
Definition: gl2psTest.c:62
void triangles()
Definition: gl2psTest.c:136
void display()
Definition: gl2psTest.c:461
#define GL2PS_TEX
Definition: gl2ps.h:103
#define GL2PS_MINOR_VERSION
Definition: gl2ps.h:89
#define GL2PS_SIMPLE_SORT
Definition: gl2ps.h:111
GL2PSDLL_API GLint gl2psPointSize(GLfloat value)
Definition: gl2ps.c:6106
static GLboolean blend
Definition: gl2psTest.c:66
#define GL2PS_PDF
Definition: gl2ps.h:104
GL2PSDLL_API const char * gl2psGetFormatDescription(GLint format)
Definition: gl2ps.c:6170
#define GL2PS_NO_TEXT
Definition: gl2ps.h:132
GL2PSDLL_API GLint gl2psDisable(GLint mode)
Definition: gl2ps.c:6081
GL2PSDLL_API GLint gl2psDrawPixels(GLsizei width, GLsizei height, GLint xorig, GLint yorig, GLenum format, GLenum type, const void *pixels)
Definition: gl2ps.c:5932
static GLboolean display_multi
Definition: gl2psTest.c:65
void writefile(int format, int sort, int options, int nbcol, const char *filename, const char *extension)
Definition: gl2psTest.c:503
#define GL2PS_SVG
Definition: gl2ps.h:105
#define GL2PS_BEST_ROOT
Definition: gl2ps.h:130
void text()
Definition: gl2psTest.c:260
void extras()
Definition: gl2psTest.c:158
GL2PSDLL_API GLint gl2psEnable(GLint mode)
Definition: gl2ps.c:6045
GL2PSDLL_API GLint gl2psTextOpt(const char *str, const char *fontname, GLshort fontsize, GLint alignment, GLfloat angle)
Definition: gl2ps.c:5915
static GLboolean teapot
Definition: gl2psTest.c:67
GL2PSDLL_API GLint gl2psLineWidth(GLfloat value)
Definition: gl2ps.c:6116
#define GL2PS_OVERFLOW
Definition: gl2ps.h:121
#define GL2PS_NO_PS3_SHADING
Definition: gl2ps.h:134
static const char * format_string
Definition: gl2psTest.c:61
GL2PSDLL_API GLint gl2psEndViewport(void)
Definition: gl2ps.c:5893
#define GL2PS_EPS
Definition: gl2ps.h:102