filehello.cpp
  0
  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
/*
 *  hello.cpp
 *
 *  Created by Daisuke Nogami.
 *  Copyright 2005 Daisuke Nogami [null-null.net]. All rights reserved.
 */
 
#include "stdafx.h"
#include "hello.h"
 
#include "math.h"
 
#define VISIBLE_MOTION_SHADOW
 
bool isCapture = false;
 
void setView(){
  glClear( GL_COLOR_BUFFER_BIT );
  glLoadIdentity();
  glOrtho( 0.0, 1024, 0.0, 768, -1.0, 1.0 );
  //glOrtho( 30.0, 994, 30.0, 738, -1.0, 1.0 );
}
 
void display(void){
  setView();
 
  // update...
  if( !isCapture ){
 
    mfilter.proc();
 
    // attached by motion
    mfilter.attach( &cellset, &rfilter );
    mfilter.attach( &cellset, &asfilter );
 
    // update filter
    asfilter.update();
    asfilter.mappingTo( &cellset );
    rfilter.update();
    rfilter.mappingTo( &cellset );
 
    cellset.update();
  }
 
  // draw...
 
#ifdef VISIBLE_MOTION_SHADOW
 
  // draw background shadow
  glBindTexture( GL_TEXTURE_2D, texName[1] );
  glTexSubImage2D(
    GL_TEXTURE_2D, 0, 0, 0, mfilter._cWidth, mfilter._cHeight,
    GL_RGB, GL_UNSIGNED_BYTE, mfilter.btmp
  );
 
  glBlendFunc( GL_SRC_ALPHA, GL_ONE );
  glEnable( GL_BLEND );
  glEnable( GL_TEXTURE_2D );
  glDisable( GL_DEPTH_TEST );
  glColor3f( 0.0, 0.0, 0.392 );
  //glColor3f( 0.0, 0.0, 0.3 );
  mfilter.draw();
 
#endif
 
  // draw onomatopoeia
  glBindTexture( GL_TEXTURE_2D, texName[0] );
  glBlendFunc( GL_SRC_ALPHA, GL_ONE );
  glEnable( GL_BLEND );
  glEnable( GL_TEXTURE_2D );
  glColor3f( 1.0, 1.0, 1.0 );
  cellset.draw();
 
  static int ws_timer = 0;
  if( mfilter.mfv.size() != 0 ){
    ws_timer = 30;
  }
  if( ws_timer >= 0 ){
    ws_timer--;
 
    // draw weather status
    glDisable(GL_BLEND);
    glDisable(GL_TEXTURE_2D);
    weather.drawStatus();
  }
 
  // draw shade
  /*glDisable( GL_BLEND );
	glDisable( GL_TEXTURE_2D );
	glDisable( GL_DEPTH_TEST );
	glColor3f( 0, 0.5, 1.0 );
	glLineWidth( 1 );
	mfilter.shade();*/
 
  // dsp airstream
  float px, py, p, max;
  px = asfilter.as_src.dirX;
  py = asfilter.as_src.dirY;
  max = sqrt( 1024.*1024.+768.*768. );
  p = sqrt( px*px+py*py )/max;
  pasnd.mdata.asunit.power = p;
 
  // dsp rain
  if( rfilter.raindrops.size() == 0 ){
    pasnd.mdata.asunit.mVol = 1.;
    pasnd.mdata.runit.mVol = 0.;
  }
  else{
    pasnd.mdata.asunit.mVol = 0.2;
    pasnd.mdata.runit.mVol = 3.;
  }
 
  // dsp raindrops
  int i;
  for( i = 0; i < mfilter.hitRainDropNum; i++ ){
    pasnd.mdata.rdunit.push();
  }
 
  glutSwapBuffers();
}
 
void init(void){
 
#ifdef VISIBLE_MOTION_SHADOW
 
  glClearColor( 0.0, 0.0, 0.0, 1.0 );
 
#else
 
  //glClearColor( 0.0, 0.0, 0.392, 1.0 );
  glClearColor( 0.0, 0.0, 0.3, 1.0 );
 
#endif
 
  // generate texture
  glGenTextures( TEX_NUM, texName );
 
  // onomatopoeia
  onomato_img.load( "data/onomato_m.tga", 512, 512 );
  glBindTexture( GL_TEXTURE_2D, texName[0] );
  glTexImage2D(
    GL_TEXTURE_2D, 0 , GL_RGBA, onomato_img.width, onomato_img.height,
    0, GL_RGBA, GL_UNSIGNED_BYTE, onomato_img.btmp
  );
  glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
  glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
 
  // motion [from camera]
  glBindTexture( GL_TEXTURE_2D, texName[1] );
  glTexImage2D(
    GL_TEXTURE_2D, 0 , GL_RGB, mfilter._cHeight, mfilter._cHeight,
    0, GL_RGB, GL_UNSIGNED_BYTE, mfilter.btmp
  );
  glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
  glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
 
  // start thread
  weather.start();
  mfilter.start();
 
  // initialize audio
  pasnd.init();
}
 
void resize( int w, int h ){
    glViewport( 0, 0, w, h );
    glLoadIdentity();
    glOrtho( 0.0, w, 0.0, h, -1.0, 1.0 );
}
 
void keyboard(unsigned char key, int x, int y){
  //printf( "key: %c\n", key );
  switch (key) {
    case 'q':
      asfilter.sync( 0, 1 );
      rfilter.sync( 0 );
      break;
    case 'w':
      asfilter.sync( 0, 4 );
      rfilter.sync( 0 );
      break;
    case 'e':
      asfilter.sync( 0, 8 );
      rfilter.sync( 0 );
      break;
    case 'r':
      asfilter.sync( 0, 1 );
      rfilter.sync( 1 );
      break;
    case 't':
      asfilter.sync( 0, 1 );
      rfilter.sync( 4 );
      break;
    case 'y':
      asfilter.sync( 0, 4 );
      rfilter.sync( 4 );
      break;
    case 'u':
      weather.sync();
      break;
    //
    case 's':
      isCapture = !isCapture;
      break;
    //
    case 49://1
      // start thread
      pasnd.start();
      break;
    case 50://2
      // stop thread
      weather.signal();
      pasnd.stop();
      break;
    //
    case 51://3
      // refresh screen
      mfilter.shadeCapture = true;
      break;
    //
    case 27://esc
      pasnd.releace();
      exit(0);
      break;
  }
}
 
void mouse( int button, int state, int x, int y ){
  //
}
 
void motion( int x, int y ){
  //
}
 
void timer( int val ){
  glutPostRedisplay();
  glutTimerFunc( 20, timer, 0 );
}
 
int main(int argc, char *argv[]){
  glutInit(&argc, argv);
  glutInitDisplayMode( GLUT_RGBA | GLUT_DOUBLE );
  glutCreateWindow(argv[0]);
 
  //glutInitWindowSize( 512, 384 );
  //glutReshapeWindow(512, 384);
  glutFullScreen();
 
  glutSetCursor(GLUT_CURSOR_NONE);
  glutDisplayFunc(display);
  //glutIdleFunc( display );
  glutTimerFunc( 20, timer, 0 );
  //glutReshapeFunc( resize );
  glutKeyboardFunc(keyboard);
  glutMouseFunc(mouse);
  glutMotionFunc(motion);
 
  init();
 
  glutMainLoop();
 
  return 0;
}
[トップ] [一覧] [最終更新] [検索] [バックアップ]