1 /*
2 XBlockOut a 3D Tetris
3
4 Copyright (C) 1992,1993,1994 Thierry EXCOFFIER
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 1, or (at your option)
9 any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19
20 Contact: Thierry.EXCOFFIER@liris.univ-lyon1.fr
21 */
22 #include "opt.h"
23 #include "x.h"
24 #include <stdio.h>
25
26 #if HAVE_STDLIB_H
27 #include <stdlib.h>
28 #endif
29
30
initbuffer(struct opt * opt,struct x * x)31 void initbuffer(struct opt *opt, struct x *x)
32 {
33 if ( opt->verbose ) fprintf(stderr,"Start of buffer initialisation\n") ;
34
35 if ( x->back )
36 {
37 XFreePixmap( x->display,x->back ) ;
38 x->back = 0 ;
39 XFreePixmap( x->display,x->work ) ;
40 x->work = 0 ;
41 }
42
43
44
45 switch( opt->buffering )
46 {
47 case 2 :
48 x->back=XCreatePixmap( x->display,x->root,x->dimx,x->dimy,x->depth ) ;
49 x->work=XCreatePixmap( x->display,x->root,x->dimx,x->dimy,x->depth ) ;
50
51 if ( x->back==0 || x->work==0 )
52 {
53 fprintf(stderr,"Not enough memory for double buffering\n") ;
54 fprintf(stderr,"Try to use single buffering\n") ;
55 fprintf(stderr,"Use option buffering=1 (except for black&white)\n") ;
56 exit(1) ;
57 }
58 break ;
59
60 case 1 :
61 case 5 :
62
63 if ( opt->buffering==1 && opt->verbose )
64 {
65 fprintf(stderr,"Create buffer windows for debugging\n") ;
66 x->work = XCreateSimpleWindow(x->display,x->root,0,0,x->dimx,x->dimy,0,0,0);
67 XMapWindow(x->display,x->work) ;
68 }
69 else {
70 x->work = XCreatePixmap( x->display,x->root,x->dimx,x->dimy,x->depth ) ;
71 }
72 if ( x->work==0 )
73 {
74 fprintf(stderr,"Not enough memory for buffering\n") ;
75 fprintf(stderr,"Try to play without buffering\n") ;
76 fprintf(stderr,"Use option buffering=0\n") ;
77 exit(1) ;
78 }
79 break ;
80 }
81
82 if ( opt->verbose ) fprintf(stderr,"End of buffer initialisation\n") ;
83 }
84