File: room.c

package info (click to toggle)
foobillardplus 3.43~svn170%2Bdfsg-5
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 86,620 kB
  • sloc: ansic: 125,581; makefile: 268; xml: 32; sh: 1
file content (374 lines) | stat: -rw-r--r-- 15,115 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
/* room.c
**
**    create the billard-room
**
**    Version foobillard++ started at 12/2010
**    Copyright (C) 2010 - 2013 Holger Schaekel (foobillardplus@go4more.de)
**
**    This program is free software; you can redistribute it and/or modify
**    it under the terms of the GNU General Public License Version 2 as
**    published by the Free Software Foundation;
**
**    This program is distributed in the hope that it will be useful,
**    but WITHOUT ANY WARRANTY; without even the implied warranty of
**    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
**    GNU General Public License for more details.
**
**    You should have received a copy of the GNU General Public License
**    along with this program; if not, write to the Free Software
**    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
**
*/

#include <stdio.h>
#ifdef __APPLE__
 #include <OpenGL/gl.h>
 #include <OpenGL/glu.h>
#else
 #include <GL/gl.h>
 #include <GL/glu.h>
#endif
#include "png_loader.h"
#include "billard.h"

/***********************************************************************
 *           Create equal rects for the floor                          *
 ***********************************************************************/

void my_rect_floor(GLshort a,GLshort b,GLshort c,GLshort d,GLshort e,GLshort f,GLshort g,GLshort h,GLshort i,GLshort j,GLshort k,GLshort l,GLshort m,GLshort n,GLshort o,GLshort p)
{
  GLshort VertexData[] = {c,d,g,h,o,p,k,l};
  GLshort TexData[] = {a,b,e,f,m,n,i,j};
  GLshort NormalData[] = {0,0,1,0,0,1,0,0,1,0,0,1};
  glTexCoordPointer(2,GL_SHORT, 0, TexData);
  glVertexPointer(2, GL_SHORT, 0, VertexData);
  glNormalPointer(GL_SHORT, 0, NormalData);
  glDrawArrays(GL_TRIANGLE_STRIP,0,4);
}

/***********************************************************************
 *           Create equal rects for the walls                          *
 ***********************************************************************/

void my_rect_wall(void)
{
  static const GLfloat VertexData[] = {-5.0,5.0,2.5,5.0,5.0,2.5,-5.0,5.0,0.0,5.0,5.0,0.0};
  static const GLfloat TexData[] = {0.0,0.0,4.0,0.0,0.0,2.0,4.0,2.0};
  glEnableClientState(GL_TEXTURE_COORD_ARRAY);
  glEnableClientState(GL_VERTEX_ARRAY);
  glTexCoordPointer(2,GL_FLOAT, 0, TexData);
  glVertexPointer(3, GL_FLOAT, 0, VertexData);
  glPushMatrix();
  glDrawArrays(GL_TRIANGLE_STRIP,0,4);
  glPopMatrix();
  glDisableClientState(GL_TEXTURE_COORD_ARRAY);
  glDisableClientState(GL_VERTEX_ARRAY);
}

/***********************************************************************
 *           Create equal rects for the strips                         *
 ***********************************************************************/

void my_rect_strip(GLuint texbind)
{
  glBindTexture(GL_TEXTURE_2D,texbind);
  static const GLfloat VertexData[] = {-5.0,4.998,0.08,5.0,4.998,0.08,-5.0,4.998,0.0,5.0,4.998,0.0};
  static const GLfloat TexData[] = {0.0,0.0,1.0,0.0,0.0,1.0,1.0,1.0,};
  glEnableClientState(GL_TEXTURE_COORD_ARRAY);
  glEnableClientState(GL_VERTEX_ARRAY);
  glTexCoordPointer(2,GL_FLOAT, 0, TexData);
  glVertexPointer(3, GL_FLOAT, 0, VertexData);
  glPushMatrix();
  glDrawArrays(GL_TRIANGLE_STRIP,0,4);
  glPopMatrix();
  glDisableClientState(GL_TEXTURE_COORD_ARRAY);
  glDisableClientState(GL_VERTEX_ARRAY);
}


/***********************************************************************
 *           Create -most- rects (cabinet, graffity                    *
 ***********************************************************************/

void my_rect_most(GLfloat a, GLfloat b, GLfloat c, GLfloat d, GLfloat e, GLfloat f, GLfloat g, GLfloat h, GLfloat i, GLfloat j, GLfloat k, GLfloat l)
{
  GLfloat VertexData[] = {a,b,c,d,e,f,j,k,l,g,h,i};
  static const GLshort TexData[] = {0,0,1,0,0,1,1,1};
  glTexCoordPointer(2,GL_SHORT, 0, TexData);
  glVertexPointer(3, GL_FLOAT, 0, VertexData);
  glPushMatrix();
  glDrawArrays(GL_TRIANGLE_STRIP,0,4);
  glPopMatrix();
}

/***********************************************************************
 *           Create the room itself (and the gllist)                   *
 ***********************************************************************/

void create_room(int *floor_obj, int *wall1_2_obj, int *wall3_obj, int *wall4_c_obj, int *carpet_obj)
{

  static GLuint corr1texbind=-1;
  static GLuint corr2texbind=-1;
  static GLuint graffity1texbind=-1;
  static GLuint graffity2texbind=-1;
  static GLuint closewindowtexbind=-1;
  static GLuint doortexbind=-1;
  static GLuint boardtexbind=-1;
  static GLuint ceilingtexbind=-1;
  static GLuint pricetexbind=-1;
  static GLuint floortexbind=-1;
  static GLuint cabinetbacktexbind=-1;
  static GLuint cabinetframetexbind=-1;
  static GLuint cabinetfronttexbind=-1;
  static GLuint stoneframetexbind=-1;
  static GLuint winbig1texbind =-1;
  static GLuint winbacktexbind =-1;
  static GLuint carpettexbind =-1;
  VMfloat balld  = BALL_D;
  VMfloat tableh = TABLE_H;

  if( floortexbind > 0 ) glDeleteTextures( 1, &floortexbind );
  create_png_texbind("floor.png", &floortexbind, 3, GL_RGB);
  if( carpettexbind > 0 ) glDeleteTextures( 1, &carpettexbind );
  create_png_texbind("carpet.png", &carpettexbind, 4, GL_RGBA);

  if( corr1texbind > 0 ) glDeleteTextures( 1, &corr1texbind );
  create_png_texbind("corr1.png", &corr1texbind, 3, GL_RGB);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);

  if( corr2texbind > 0 ) glDeleteTextures( 1, &corr2texbind );
  create_png_texbind("corr2.png", &corr2texbind, 3, GL_RGB);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
  if( stoneframetexbind > 0 ) glDeleteTextures( 1, &stoneframetexbind );
  create_png_texbind("stone-frame.png", &stoneframetexbind, 3, GL_RGB);


  if( cabinetbacktexbind > 0 ) glDeleteTextures( 1, &cabinetbacktexbind );
  create_png_texbind("cabinet-back.png", &cabinetbacktexbind, 3, GL_RGBA);
  if( cabinetframetexbind > 0 ) glDeleteTextures( 1, &cabinetframetexbind );
  create_png_texbind("cabinet-frame.png", &cabinetframetexbind, 3, GL_RGB);
  if( cabinetfronttexbind > 0 ) glDeleteTextures( 1, &cabinetfronttexbind );
  create_png_texbind("cabinet-front.png", &cabinetfronttexbind, 4, GL_RGBA);

  if( graffity1texbind > 0 ) glDeleteTextures( 1, &graffity1texbind );
  create_png_texbind("graffity1.png", &graffity1texbind, 3, GL_RGBA);

  if( graffity2texbind > 0 ) glDeleteTextures( 1, &graffity2texbind );
  create_png_texbind("graffity2.png", &graffity2texbind, 3, GL_RGBA);

  if( closewindowtexbind > 0 ) glDeleteTextures( 1, &closewindowtexbind );
  create_png_texbind("closewindow.png", &closewindowtexbind, 4, GL_RGBA);

  if( doortexbind > 0 ) glDeleteTextures( 1, &doortexbind );
  create_png_texbind("door.png", &doortexbind, 4, GL_RGBA);

  if( winbig1texbind > 0 ) glDeleteTextures( 1, &winbig1texbind );
  create_png_texbind("window-big1.png", &winbig1texbind, 4, GL_RGBA);
  if( winbacktexbind > 0 ) glDeleteTextures( 1, &winbacktexbind );
  create_png_texbind("skyline.png", &winbacktexbind, 3, GL_RGB);

  if( boardtexbind > 0 ) glDeleteTextures( 1, &boardtexbind );
  create_png_texbind("board.png", &boardtexbind, 4, GL_RGBA);

  if( ceilingtexbind > 0 ) glDeleteTextures( 1, &ceilingtexbind );
  create_png_texbind("ceiling.png", &ceilingtexbind, 3, GL_RGB);

  if( pricetexbind > 0 ) glDeleteTextures( 1, &pricetexbind );
  create_png_texbind("price.png", &pricetexbind, 4, GL_RGBA);

// room walls and floor

  // Now the floor. it's ever available and must be called first !!!! in the room-building
  // and direct after the table build

  if(*floor_obj != -1 ) glDeleteLists( *floor_obj, 1 );
  *floor_obj = glGenLists(1);
  glNewList(*floor_obj, GL_COMPILE);
    glDisable(GL_TEXTURE_GEN_S);
    glDisable(GL_TEXTURE_GEN_T);
    glTranslatef(0,0,-tableh-balld/2.0);

    glBindTexture(GL_TEXTURE_2D,floortexbind);
    glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);

    glEnableClientState(GL_TEXTURE_COORD_ARRAY);
    glEnableClientState(GL_VERTEX_ARRAY);
    glPushMatrix();
    my_rect_floor(0,0,0,0,0,1,5,0,1,1,5,-5,1,0,0,-5);
    my_rect_floor(0,0,0,5,0,1,5,5,1,1,5,0,1,0,0,0);
    my_rect_floor(0,1,-5,0,0,0,0,0,1,0,0,-5,1,1,-5,-5);
    my_rect_floor(0,1,-5,5,0,0,0,5,1,0,0,0,1,1,-5,0);
    glPopMatrix();
    glDisableClientState(GL_TEXTURE_COORD_ARRAY);
    glDisableClientState(GL_VERTEX_ARRAY);
  glEndList();

  if(*carpet_obj != -1 ) glDeleteLists( *carpet_obj, 1 );
  *carpet_obj = glGenLists(1);
  glNewList(*carpet_obj, GL_COMPILE);
    glPushMatrix();
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    glEnable(GL_BLEND);
    glBindTexture(GL_TEXTURE_2D,carpettexbind);
    glTranslatef(-1.0,-3.0,0.0);
    static const GLfloat VertexData2[] = {-1.35,1.25,0.001,4.0,1.25,0.001,-1.35,-1.9,0.001,4.0,-1.9,0.001};
    static const GLfloat TexData2[] = {0,0,0,1,1,0,1,1};
    glEnableClientState(GL_TEXTURE_COORD_ARRAY);
    glEnableClientState(GL_VERTEX_ARRAY);
    glTexCoordPointer(2,GL_FLOAT, 0, TexData2);
    glVertexPointer(3, GL_FLOAT, 0, VertexData2);
    glDrawArrays(GL_TRIANGLE_STRIP,0,4);
    glDisableClientState(GL_TEXTURE_COORD_ARRAY);
    glDisableClientState(GL_VERTEX_ARRAY);
    glDisable(GL_BLEND);
    glPopMatrix();
  glEndList();


  if(*wall1_2_obj != -1 ) glDeleteLists( *wall1_2_obj, 1 );
  *wall1_2_obj = glGenLists(1);
  glNewList(*wall1_2_obj, GL_COMPILE);
    glBlendFunc(GL_ONE,GL_ONE);

    // wall 1
    glBindTexture(GL_TEXTURE_2D,corr1texbind);
    my_rect_wall();
    my_rect_strip(cabinetframetexbind); // carpet strip

    glBindTexture(GL_TEXTURE_2D,graffity2texbind);
    glEnable(GL_BLEND);
    glEnableClientState(GL_TEXTURE_COORD_ARRAY);
    glEnableClientState(GL_VERTEX_ARRAY);
    my_rect_most(0.5,4.999,2.3,4.0,4.999,2.3,4.0,4.999,0.5,0.5,4.999,0.5);
    glDisable(GL_BLEND);
    // billiards cabinet
    glBindTexture(GL_TEXTURE_2D,cabinetbacktexbind);
    my_rect_most(-3.6,4.999,2.3,-2.4,4.999,2.3,-2.4,4.999,0.5,-3.6,4.999,0.5);

    glBindTexture(GL_TEXTURE_2D,cabinetframetexbind);
    //left frame
    my_rect_most(-3.6,4.8,2.3,-3.6,4.999,2.3,-3.6,4.999,0.5,-3.6,4.8,0.5);
    //bottom frame
    my_rect_most(-3.6,4.8,0.5,-3.6,4.999,0.5,-2.4,4.999,0.5,-2.4,4.8,0.5);
    //right frame
    my_rect_most(-2.4,4.8,2.3,-2.4,4.999,2.3,-2.4,4.999,0.5,-2.4,4.8,0.5);
    //upper frame
    // ### TODO ### upper frame only useful, if FREEVIEW and CUE_VIEW is ON
    // now, we disable it....... because in other views the frame is disturbing!!!!
    //my_rect_most(-3.6,4.8,2.3,-3.6,4.999,2.3,-2.4,4.999,2.3,-2.4,4.8,2.3);
    //front
    glBindTexture(GL_TEXTURE_2D,cabinetfronttexbind);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    glEnable(GL_BLEND);
    my_rect_most(-3.6,4.8,2.3,-2.4,4.8,2.3,-2.4,4.8,0.5,-3.6,4.8,0.5);
    glDisable(GL_BLEND);
    glBlendFunc(GL_ONE,GL_ONE);
    // wall 2
    glRotatef(90.0,0.0,0.0,1.1);
    glBindTexture(GL_TEXTURE_2D,corr1texbind);
    my_rect_wall();

    glBindTexture(GL_TEXTURE_2D,graffity1texbind);
    glEnable(GL_BLEND);
    glEnableClientState(GL_TEXTURE_COORD_ARRAY);
    glEnableClientState(GL_VERTEX_ARRAY);
    my_rect_most(-4.0,4.999,2.5,4.0,4.999,2.5,4.0,4.999,0.0,-4.0,4.999,0.0);
    glDisable(GL_BLEND);
    my_rect_strip(cabinetframetexbind); // carpet strip
   glEndList();

   if(*wall3_obj != -1 ) glDeleteLists( *wall3_obj, 1 );
   *wall3_obj = glGenLists(1);
   glNewList(*wall3_obj, GL_COMPILE);
    // wall 3
    glBindTexture(GL_TEXTURE_2D,corr2texbind);
    static const GLfloat VertexData[] = {-5.0,5.0,2.5,1.0,5.0,2.5,-5.0,5.0,0.0,1.0,5.0,0.0,
            1.0,5.0,2.5,4.0,5.0,2.5,1.0,5.0,2.3,4.0,5.0,2.3,
            4.0,5.0,2.5,5.0,5.0,2.5,4.0,5.0,0.0,5.0,5.0,0.0,
            1.0,5.0,0.5,4.0,5.0,0.5,1.0,5.0,0.0,4.0,5.0,0.0
    };
    static const GLfloat TexData[] = {0.0,0.0,7.0,0.0,0.0,6.0,7.0,6.0,
            0.0,0.0,4.0,0.0,0.0,0.5,4.0,0.5,
            0.0,0.0,1.0,0.0,0.0,6.0,1.0,6.0,
            0.0,0.0,4.0,0.0,0.0,1.265,4.0,1.265
    };

    glEnableClientState(GL_TEXTURE_COORD_ARRAY);
    glEnableClientState(GL_VERTEX_ARRAY);
    glTexCoordPointer(2,GL_FLOAT, 0, TexData);
    glVertexPointer(3, GL_FLOAT, 0, VertexData);
    glPushMatrix();
    glDrawArrays(GL_TRIANGLE_STRIP,0,16);
    glPopMatrix();
    glDisableClientState(GL_TEXTURE_COORD_ARRAY);
    glDisableClientState(GL_VERTEX_ARRAY);
    // frame around the stone off the big window
    glBindTexture(GL_TEXTURE_2D,stoneframetexbind);
    //upper frame
    glEnableClientState(GL_TEXTURE_COORD_ARRAY);
    glEnableClientState(GL_VERTEX_ARRAY);
    my_rect_most(1.0,5.0,2.3,4.0,5.0,2.3,4.0,5.2,2.3,1.0,5.2,2.3);
    //left frame
    my_rect_most(1.0,5.0,2.3,1.0,5.2,2.3,1.0,5.2,0.5,1.0,5.0,0.5);
    //bottom frame
    //glTexCoord2s(0,0);
    my_rect_most(1.0,5.2,0.5,4.0,5.2,0.5,4.0,5.0,0.5,1.0,5.0,0.5);
    // right frame
    my_rect_most(4.0,5.0,0.5,4.0,5.2,0.5,4.0,5.2,2.3,4.0,5.0,2.3);

    // skyline behind window
    glBindTexture(GL_TEXTURE_2D,winbacktexbind);
    my_rect_most(1.0,5.6,2.3,4.5,5.6,2.3,4.5,5.6,0.5,1.0,5.6,0.5);
    // chalk board
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    glEnable(GL_BLEND);
    glBindTexture(GL_TEXTURE_2D,boardtexbind);
    my_rect_most(-2.0,4.999,2.0,0.0,4.999,2.0,0.0,4.999,0.7,-2.0,4.999,0.7);
    // big dark wood window
    glBindTexture(GL_TEXTURE_2D,winbig1texbind);
    my_rect_most(1.0,5.2,2.3,4.0,5.2,2.3,4.0,5.2,0.5,1.0,5.2,0.5);
    glDisable(GL_BLEND);
    my_rect_strip(cabinetframetexbind); // carpet strip
   glEndList();

   if(*wall4_c_obj != -1 ) glDeleteLists( *wall4_c_obj, 1 );
   *wall4_c_obj = glGenLists(1);
   glNewList(*wall4_c_obj, GL_COMPILE);
    // wall 4
    glRotatef(90.0,0.0,0.0,1.1);
    glBindTexture(GL_TEXTURE_2D,corr1texbind);
    my_rect_wall();
    // price list
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    glBindTexture(GL_TEXTURE_2D,pricetexbind);
    glEnable(GL_BLEND);
    glEnableClientState(GL_TEXTURE_COORD_ARRAY);
    glEnableClientState(GL_VERTEX_ARRAY);
    my_rect_most(3.0,4.999,2.3,4.0,4.999,2.3,4.0,4.999,0.7,3.0,4.999,0.7);
    my_rect_strip(cabinetframetexbind); // carpet strip
    // closed window
    glBindTexture(GL_TEXTURE_2D,closewindowtexbind);
    glEnableClientState(GL_TEXTURE_COORD_ARRAY);
    glEnableClientState(GL_VERTEX_ARRAY);
    my_rect_most(0.0,4.999,2.3,3.0,4.999,2.3,3.0,4.999,0.7,0.0,4.999,0.7);
    // door
    glBindTexture(GL_TEXTURE_2D,doortexbind);
    my_rect_most(-2.0,4.997,2.3,-1.0,4.997,2.3,-1.0,4.997,0.0,-2.0,4.997,0.0);
    glDisable(GL_BLEND);
    // ceiling
    glBindTexture(GL_TEXTURE_2D,ceilingtexbind);
    static const GLfloat VertexData1[] = {-5.0,-5.0,2.5,5.0,-5.0,2.5,-5.0,5.0,2.5,5.0,5.0,2.5};
    static const GLshort TexData1[] = {0,0,8,0,0,8,8,8};

    glTexCoordPointer(2,GL_SHORT, 0, TexData1);
    glVertexPointer(3, GL_FLOAT, 0, VertexData1);
    glPushMatrix();
    glDrawArrays(GL_TRIANGLE_STRIP,0,4);
    glPopMatrix();
    glDisableClientState(GL_TEXTURE_COORD_ARRAY);
    glDisableClientState(GL_VERTEX_ARRAY);
   glEndList();
}