~ubuntu-branches/ubuntu/utopic/lebiniou/utopic

« back to all changes in this revision

Viewing changes to plugins/stable/main/GLCube/GLCube.c

  • Committer: Package Import Robot
  • Author(s): Olivier Girondel
  • Date: 2012-04-22 22:07:40 UTC
  • mfrom: (6.1.7 sid)
  • Revision ID: package-import@ubuntu.com-20120422220740-xncgwhc3g71nopnu
Tags: 3.18-1
* New upstream release 3.18.
* Support older libswscale.
* Add missing Build-Depends: libfreetype6-dev, libasound2-dev,
  libpulse-dev. (Closes: #669437)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *  Copyright 1994-2012 Olivier Girondel
 
3
 *
 
4
 *  This file is part of lebiniou.
 
5
 *
 
6
 *  lebiniou 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 2 of the License, or
 
9
 *  (at your option) any later version.
 
10
 *
 
11
 *  lebiniou 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 lebiniou. If not, see <http://www.gnu.org/licenses/>.
 
18
 */
 
19
 
 
20
#include "context.h"
 
21
 
 
22
 
 
23
u_long id = 1328382269;
 
24
 
 
25
u_long options = BE_GFX;
 
26
u_long mode = OVERLAY;
 
27
 
 
28
char dname[] = "GLCube";
 
29
char desc[] = "OpenGL cube";
 
30
 
 
31
static u_char faces[6];
 
32
#ifdef WITH_WEBCAM
 
33
extern int webcams;
 
34
#endif
 
35
 
 
36
#define NORMAL(X) do {                          \
 
37
    glEnable(GL_COLOR_LOGIC_OP);                \
 
38
    glLogicOp(GL_COPY);                         \
 
39
    glBegin(GL_QUADS);                          \
 
40
    X;                                          \
 
41
    glDisable(GL_COLOR_LOGIC_OP);               \
 
42
    glEnd();                                    \
 
43
  } while(0)
 
44
#define INVERT(X) do {                          \
 
45
    glEnable(GL_COLOR_LOGIC_OP);                \
 
46
    glLogicOp(GL_COPY_INVERTED);                \
 
47
    glBegin(GL_QUADS);                          \
 
48
    X;                                          \
 
49
    glDisable(GL_COLOR_LOGIC_OP);               \
 
50
    glEnd();                                    \
 
51
  } while(0)
 
52
 
 
53
 
 
54
/* many things shamefully backported from the EC_cube project */
 
55
#define ZERO 0.0
 
56
#define ONE  1.0
 
57
 
 
58
static float CUBE[8][3] =
 
59
  {{ ONE,  ONE, -ONE},   // 1
 
60
   { ONE, -ONE, -ONE},   // 2
 
61
   {-ONE, -ONE, -ONE},
 
62
   {-ONE,  ONE, -ONE},   // 4
 
63
   {-ONE,  ONE,  ONE},
 
64
   { ONE,  ONE,  ONE},   // 6
 
65
   { ONE, -ONE,  ONE},
 
66
   {-ONE, -ONE,  ONE}};
 
67
 
 
68
#define CE(x) glVertex3fv(CUBE[x-1])
 
69
 
 
70
#define coucou(X) face(ctx, X)
 
71
 
 
72
 
 
73
void
 
74
create(__attribute__ ((unused)) Context_t *ctx)
 
75
{
 
76
  int e, v;
 
77
  const float ar = WIDTH / (float)HEIGHT;
 
78
 
 
79
  /* scale the cube */
 
80
  for (e = 0; e < 8; e++)
 
81
    for (v = 0; v < 3; v++)
 
82
      if (v != 1)
 
83
        CUBE[e][v] *= ar;
 
84
      else
 
85
        CUBE[e][v] *= 1.15; /* FIXME empirical tuning */
 
86
}
 
87
 
 
88
 
 
89
void
 
90
destroy(__attribute__ ((unused)) Context_t *ctx)
 
91
{
 
92
}
 
93
 
 
94
 
 
95
static void
 
96
cube()
 
97
{
 
98
  glDisable(GL_TEXTURE_2D);
 
99
  glColor3f(1, 1, 1);
 
100
  glLineWidth(2);
 
101
  glBegin(GL_LINES);
 
102
  CE(1); CE(2); CE(2); CE(3); CE(3); CE(4);
 
103
  CE(4); CE(5); CE(5); CE(8); CE(8); CE(3);
 
104
  CE(1); CE(6); CE(6); CE(7); CE(7); CE(2);
 
105
  CE(6); CE(5); CE(5); CE(8); CE(8); CE(7);
 
106
  CE(6); CE(1); CE(1); CE(4); CE(4); CE(5);
 
107
  CE(7); CE(2); CE(3); CE(8);
 
108
  glEnd();
 
109
}
 
110
 
 
111
 
 
112
static inline void t1() {
 
113
  glTexCoord2f(ZERO, ZERO);
 
114
}
 
115
static inline void t2() {
 
116
  glTexCoord2f(ZERO, ONE);
 
117
}
 
118
static inline void t3() {
 
119
  glTexCoord2f(ONE, ONE);
 
120
}
 
121
static inline void t4() {
 
122
  glTexCoord2f(ONE, ZERO);
 
123
}
 
124
 
 
125
 
 
126
void
 
127
get_texture(Context_t *ctx, const u_char face, const u_char rgba)
 
128
{
 
129
  if (rgba)
 
130
    Context_make_GL_RGBA_texture(ctx, face);
 
131
  else {
 
132
#ifdef WITH_WEBCAM
 
133
    Context_make_GL_gray_texture(ctx, face);
 
134
#else
 
135
    Context_make_GL_RGBA_texture(ctx, face);
 
136
#endif
 
137
  }
 
138
}
 
139
 
 
140
 
 
141
static void
 
142
face(__attribute__ ((unused)) Context_t *ctx, const char f)
 
143
{
 
144
  switch (f) {
 
145
  case 0: // front face
 
146
    get_texture(ctx, ACTIVE_BUFFER, 1);
 
147
    NORMAL(
 
148
           t1(); CE(8);
 
149
           t2(); CE(5);
 
150
           t3(); CE(6);
 
151
           t4(); CE(7));
 
152
    break;
 
153
 
 
154
  case 1: // back face
 
155
    get_texture(ctx, ACTIVE_BUFFER, 1);
 
156
    INVERT(
 
157
           t4(); CE(2);
 
158
           t3(); CE(1);
 
159
           t2(); CE(4);
 
160
           t1(); CE(3));
 
161
    break;
 
162
 
 
163
  case 2: // left face
 
164
#ifdef WITH_WEBCAM
 
165
    get_texture(ctx, (webcams >= 2) ? 1 : 0, 0);
 
166
#else
 
167
    get_texture(ctx, 0, 0);
 
168
#endif
 
169
    NORMAL(
 
170
           t4(); CE(3);
 
171
           t3(); CE(4);
 
172
           t2(); CE(5);
 
173
           t1(); CE(8));
 
174
    break;
 
175
 
 
176
  case 3: // right face
 
177
    get_texture(ctx, 0, 0);
 
178
    if (
 
179
#ifdef WITH_WEBCAM
 
180
        webcams > 1
 
181
#else
 
182
        1
 
183
#endif
 
184
        ) {
 
185
      if (1)
 
186
        NORMAL(
 
187
               t1(); CE(7);
 
188
               t2(); CE(6);
 
189
               t3(); CE(1);
 
190
               t4(); CE(2));
 
191
    } else {
 
192
      INVERT(
 
193
             t1(); CE(7);
 
194
             t2(); CE(6);
 
195
             t3(); CE(1);
 
196
             t4(); CE(2));
 
197
    }
 
198
    break;
 
199
 
 
200
  case 4: // up face
 
201
    NORMAL({}); break;
 
202
    t1(); CE(5);
 
203
    t2(); CE(4);
 
204
    t3(); CE(1);
 
205
    t4(); CE(6);
 
206
    break;
 
207
 
 
208
#if 0
 
209
  case 5: // bottom face
 
210
    t1(); CE(3);
 
211
    t2(); CE(8);
 
212
    t3(); CE(7);
 
213
    t4(); CE(2);
 
214
    break;
 
215
#endif
 
216
  }
 
217
}
 
218
 
 
219
 
 
220
void
 
221
textures(Context_t *ctx)
 
222
{
 
223
  char ibou; /* :) */
 
224
 
 
225
  for (ibou = 0; ibou < 6; ibou++)
 
226
    coucou(ibou); /* :) again */
 
227
}
 
228
 
 
229
 
 
230
void
 
231
run(Context_t *ctx)
 
232
{
 
233
  memset(&faces, 0, 6*sizeof(u_char));
 
234
  textures(ctx);
 
235
  cube();
 
236
  ctx->gl_done = 1;
 
237
}