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
/*
*  hello.cpp
*
*  Created by Daisuke Nogami on Sep, 05.
*  opyright 2005 Daisuke Nogami [null-null.net]. Some rights reserved.
*/
 
 
#include "stdafx.h"
#include "hello.h"
 
void setView(){
  glClear( GL_COLOR_BUFFER_BIT );
  glLoadIdentity();
  glOrtho( 0.0, 1024, 0.0, 768, -1.0, 1.0 );
}
 
void glPrint( void* font, const char* str ){
  int i = 0;
    while( str[i] != '\0' ){
        glutBitmapCharacter( font, (int)str[i] );
        i++;
    }
}
 
void drawWeatherStatus(){
  glColor3f( 1, 1, 1 );
 
  glRasterPos3f( 20, 20, 0 );
  glPrint( GLUT_BITMAP_HELVETICA_18, ("at "+weather.getLocation()).c_str() );
  glRasterPos3f( 20, 45, 0 );
  glPrint( GLUT_BITMAP_HELVETICA_18, (weather.getCurrentDate()+"'s weather [after "+weather.getAddHours()+" hours]").c_str() );
  glRasterPos3f( 20, 185, 0 );
  glPrint( GLUT_BITMAP_HELVETICA_12, ("weahter: "+weather.getCurrentWeather()).c_str() );
  glRasterPos3f( 20, 165, 0 );
  glPrint( GLUT_BITMAP_HELVETICA_12, ("temperature[degreesC]: "+weather.getCurrentTemp()).c_str() );
  glRasterPos3f( 20, 145, 0 );
  glPrint( GLUT_BITMAP_HELVETICA_12, ("precipitation rate: "+weather.getCurrentPrecRate()+"mm").c_str() );
  glRasterPos3f( 20, 125, 0 );
  glPrint( GLUT_BITMAP_HELVETICA_12, ("humidity: "+weather.getCurrentHum()+"%").c_str() );
  glRasterPos3f( 20, 105, 0 );
  glPrint( GLUT_BITMAP_HELVETICA_12, ("wind direction: "+weather.getCurrentWinDir()).c_str() );
  glRasterPos3f( 20, 85, 0 );
  glPrint( GLUT_BITMAP_HELVETICA_12, ("wind speed: "+weather.getCurrentWinSpd()+"m/s").c_str() );
}
 
void display(void){
  setView();
 
  // update motion
  ds.proc();
  /*glBindTexture( GL_TEXTURE_2D, texName[1] );
	glTexSubImage2D(
		GL_TEXTURE_2D, 0, 0, 0, ds._cWidth, ds._cHeight,
		GL_RGB, GL_UNSIGNED_BYTE, ds.btmp
	);
 
	// draw motion
	glBlendFunc( GL_SRC_ALPHA, GL_ONE );
	glEnable( GL_BLEND );
	glEnable( GL_TEXTURE_2D );
	glDisable( GL_DEPTH_TEST );
	glColor3f( 0.0, 0.0, 0.392 );
	glBegin( GL_POLYGON );
	glTexCoord2f( 0.0f, 0.0f );
	glVertex2f( 0, 768 );
	glTexCoord2f( 1.0f, 0.0f );
	glVertex2f( 1024, 768 );
	glTexCoord2f( 1.0f, 1.0f );
	glVertex2f( 1024, 0 );
	glTexCoord2f( 0.0f, 1.0f );
	glVertex2f( 0,0 );
	glEnd();*/
 
  // attached by motion
  mfilter.attach( &cellset, &rfilter );
  mfilter.attach( &cellset, &asfilter );
 
  // update filter
  asfilter.update();
  asfilter.mappingTo( &cellset );
  rfilter.update();
  rfilter.mappingTo( &cellset );
 
  // 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.update_and_draw();
 
  // draw weather status
  glDisable(GL_BLEND);
  glDisable(GL_TEXTURE_2D);
  drawWeatherStatus();
  
  glutSwapBuffers();
}
 
void init(void){
  glClearColor( 0.0, 0.0, 0.392, 1.0 );
  //glClearColor( 0.0, 0.0, 0.0, 1.0 );
 
  // generate texture
  glGenTextures( 2, texName );
 
  // onomatopoeia
  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.data
  );
  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, ds._cHeight, ds._cHeight,
    0, GL_RGB, GL_UNSIGNED_BYTE, ds.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();
  ds.start();
}
 
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 50://2
      // stop thread
      weather.signal();
      break;
    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( 4 );
      break;
    case 't':
      asfilter.sync( 0, 4 );
      rfilter.sync( 4 );
      break;
    case 'y':
      asfilter.sync( 0, 100 );
      rfilter.sync( 0 );
      break;
    case '\033':
      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;
}
[トップ] [一覧] [最終更新] [検索] [バックアップ]