@@ -12,7 +12,9 @@ vector<unsigned char> logo;
12
12
sf::SoundBuffer buffer;
13
13
sf::Sound sound (buffer);
14
14
15
- int flag=0 ,temp=0 ;
15
+ pthread_t threads[1 ]; // for multi threading
16
+ int rc1;
17
+ int flag=0 ,temp=0 ,loading=0 ,timerFlag=0 ;
16
18
int W,H;
17
19
typedef unsigned long long timestamp_t ;
18
20
int j=0 ;
@@ -26,8 +28,10 @@ int styleselect=0;
26
28
int NO_STYLE=5 ;
27
29
int countr=0 ,countg=0 ,countb=0 ;
28
30
float curtime;
31
+ string fName ;
29
32
30
33
static timestamp_t
34
+
31
35
get_timestamp ()
32
36
{
33
37
struct timeval now;
@@ -51,16 +55,6 @@ void getFft(const kiss_fft_cpx in[N], kiss_fft_cpx out[N])
51
55
52
56
}
53
57
54
- /* * print vector **/
55
- void print_vec (const std::vector<int > vec)
56
- {
57
- for (auto x : vec)
58
- {
59
- std::cout << ' ' << x;
60
- }
61
- std::cout << ' \n ' ;
62
- }
63
-
64
58
void reshape (int w, int h)
65
59
{
66
60
// W=w;
@@ -217,102 +211,17 @@ void idle()
217
211
glutPostRedisplay ();
218
212
}
219
213
220
- void display ( void )
214
+ void loadlogo ( )
221
215
{
222
- // sets color buffer bit
223
- glClearColor (28 /255.0 ,49 /255.0 ,58 /255.0 ,0.0 );
224
- glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // clears display with buffer color & depth values set in init()
225
- // circle
226
- glLoadIdentity (); // Loads identity matrix for each iteration of display
227
- // circle3d();
228
- glColor3f (0 ,1 ,0 );
229
-
230
- if (flag==0 )
231
- {
232
- glRasterPos3f (-200 ,-150 ,-500 );
233
- glDrawPixels (250 ,250 ,GL_RGBA,GL_UNSIGNED_BYTE,&logo[0 ]);
234
- drawStrokeText ((char *)" MORPHY" ,-100 ,125 ,-200 );
235
- instructText ((char *)" Press space to continue!" ,-75 ,-100 ,-200 );
236
- instructText ((char *)" K. Vishnudev" ,-75 ,-180 ,-200 );
237
- instructText ((char *)" Himanshu Kumar" ,-75 ,-200 ,-200 );
238
- }
239
- else
216
+ int error;
217
+ unsigned width = 250 ;
218
+ unsigned height = 250 ;
219
+ const char * name = " logo.png" ;
220
+ if ((error=lodepng::decode (logo,width,height,name)))
240
221
{
241
- std::ostringstream ss;
242
- float tottime = buffer.getDuration ().asSeconds ();
243
- float cursor = sound.getPlayingOffset ().asSeconds ();
244
- curtime = sound.getPlayingOffset ().asMilliseconds ();
245
- // cout<<curtime<<endl;
246
- float timepercent = (cursor/tottime)*760 ;
247
- ss << (int )cursor;
248
- const std::string tmp = " Time : " + ss.str ();
249
- const char * cstr = tmp.c_str ();
250
- glClearColor (0 ,0 ,0 ,0 );
251
- if (temp==1 )
252
- {
253
- glColor3f (128 /255.0 ,222 /255.0 ,234 /255.0 );
254
- glBegin (GL_POLYGON);
255
- glVertex3f (-380 ,-290 ,-300.0 );
256
- glVertex3f (-380 ,-280 ,-300.0 );
257
- glVertex3f (-380 +(int )timepercent,-280 ,-300.0 );
258
- glVertex3f (-380 +(int )timepercent,-290 ,-300.0 );
259
- glEnd ();
260
-
261
- glColor3f (1 ,1 ,244 /255.0 );
262
- glBegin (GL_LINE_LOOP);
263
- glVertex3f (-380 ,-292.0 ,-300.0 );
264
- glVertex3f (-380 ,-278.0 ,-300.0 );
265
- glVertex3f (380 ,-278.0 ,-300.0 );
266
- glVertex3f (380 ,-292.0 ,-300.0 );
267
- glEnd ();
268
-
269
-
270
- instructText ((char *)cstr,-250 ,-175 ,-200 );
271
- nav ();
272
-
273
- // instructText((char*)cstr,-250,-175,-200);
274
- if (styleselect==0 )
275
- {
276
- bars ();
277
- }
278
- else if (styleselect==1 )
279
- {
280
- circle3d ();
281
- }
282
- else if (styleselect==2 )
283
- {
284
- dust ();
285
- }
286
- else if (styleselect==3 )
287
- {
288
- pentagon ();
289
- }
290
- else if (styleselect==4 )
291
- {
292
- waves ();
293
- }
294
- // else if(styleselect==4)
295
- // {
296
- // CubicalMesh();
297
- // }
298
- // else if(styleselect==6)
299
- // {
300
- // DWaves();
301
- // }
302
- // else if(styleselect==6)
303
- // {
304
- // mesh3D();
305
- // }
306
- }
307
- else
308
- {
309
- // instructText((char *)"Paused!",-75,-200,-200);
310
- pausebutton ();
311
- }
222
+ printf (" Error %s" ,lodepng_error_text (error));
223
+ exit (0 );
312
224
}
313
- glutSwapBuffers ();
314
- // if(sound.getPlayingOffset().asSeconds()==buffer.getDuration().asSeconds())
315
- // exit(0);
316
225
}
317
226
318
227
int BinSrch (int freq)
@@ -329,31 +238,11 @@ int BinSrch(int freq)
329
238
return i;
330
239
}
331
240
332
- void loadlogo ()
333
- {
334
- int error;
335
- unsigned width = 250 ;
336
- unsigned height = 250 ;
337
- const char * name = " logo.png" ;
338
- if ((error=lodepng::decode (logo,width,height,name)))
339
- {
340
- printf (" Error %s" ,lodepng_error_text (error));
341
- exit (0 );
342
- }
343
- }
344
-
345
- int main (int argc, char *argv[])
346
- {
347
- loadlogo ();
348
- // SFML usage error
349
- if (argc < 2 )
350
- {
351
- std::cout << " Usage: wave_iteration <FILENAME>" << std::endl;
352
- return 1 ;
353
- }
241
+ void loadData (){
242
+ loadlogo ();
354
243
355
- if (!buffer.loadFromFile (argv[ 1 ] ))
356
- return 0 ;
244
+ if (!buffer.loadFromFile (fName . c_str () ))
245
+ exit ( 0 ) ;
357
246
// sound.play(); called just before display
358
247
std::cout<<" SampleRate: " <<(SAMPLE_RATE= buffer.getSampleRate ())<< std::endl;
359
248
std::cout<<" SampleCount: " <<(SAMPLE_COUNT= buffer.getSampleCount ())<< std::endl;
@@ -504,6 +393,151 @@ int main(int argc, char *argv[])
504
393
cout<<endl;
505
394
*/
506
395
}
396
+ }
397
+
398
+ void *callLoadData (void *thread)
399
+ {
400
+ loadData ();
401
+ loading=1 ;
402
+ pthread_exit (NULL );
403
+ }
404
+
405
+ void loadingScreen ()
406
+ {
407
+ static int rot_val=0 ;
408
+ drawStrokeText ((char *)" Loading!" ,-100 ,125 ,-200 );
409
+ glColor3f (1 ,1 ,1 );
410
+ glRotated (-rot_val,0 ,0 ,1 );
411
+ float i=1.5 ;
412
+ for (int theta=360 ;theta>0 ;theta-=30 )
413
+ {
414
+ int x=60 *cos (theta*3.141592 /180 );
415
+ int y=60 *sin (theta*3.141592 /180 );
416
+ glPointSize (i);
417
+ glBegin (GL_POINTS);
418
+ glVertex3f (x,y,-200 );
419
+ glEnd ();
420
+ i+=.5 ;
421
+ }
422
+ rot_val+=1 ;
423
+ }
424
+ void display (void )
425
+ {
426
+ // sets color buffer bit
427
+ glClearColor (28 /255.0 ,49 /255.0 ,58 /255.0 ,0.0 );
428
+ glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // clears display with buffer color & depth values set in init()
429
+ // circle
430
+ glLoadIdentity (); // Loads identity matrix for each iteration of display
431
+ // circle3d();
432
+ glColor3f (0 ,1 ,0 );
433
+ if (loading==0 ){
434
+ loadingScreen ();
435
+ if (timerFlag++==0 ){
436
+ rc1 = pthread_create (&threads[0 ], NULL , callLoadData, (void *)0 );
437
+ if (rc1){
438
+ cout << " Error:unable to create thread rc2," << rc1 << endl;
439
+ exit (-1 );
440
+ }
441
+ }
442
+ }
443
+ else if (flag==0 )
444
+ {
445
+ glRasterPos3f (-200 ,-150 ,-500 );
446
+ glDrawPixels (250 ,250 ,GL_RGBA,GL_UNSIGNED_BYTE,&logo[0 ]);
447
+ drawStrokeText ((char *)" MORPHY" ,-100 ,125 ,-200 );
448
+ instructText ((char *)" Press space to continue!" ,-75 ,-100 ,-200 );
449
+ instructText ((char *)" K. Vishnudev" ,-75 ,-180 ,-200 );
450
+ instructText ((char *)" Himanshu Kumar" ,-75 ,-200 ,-200 );
451
+ }
452
+ else
453
+ {
454
+ std::ostringstream ss;
455
+ float tottime = buffer.getDuration ().asSeconds ();
456
+ float cursor = sound.getPlayingOffset ().asSeconds ();
457
+ curtime = sound.getPlayingOffset ().asMilliseconds ();
458
+ // cout<<curtime<<endl;
459
+ float timepercent = (cursor/tottime)*760 ;
460
+ ss << (int )cursor;
461
+ const std::string tmp = " Time : " + ss.str ();
462
+ const char * cstr = tmp.c_str ();
463
+ glClearColor (0 ,0 ,0 ,0 );
464
+ if (temp==1 )
465
+ {
466
+ glColor3f (128 /255.0 ,222 /255.0 ,234 /255.0 );
467
+ glBegin (GL_POLYGON);
468
+ glVertex3f (-380 ,-290 ,-300.0 );
469
+ glVertex3f (-380 ,-280 ,-300.0 );
470
+ glVertex3f (-380 +(int )timepercent,-280 ,-300.0 );
471
+ glVertex3f (-380 +(int )timepercent,-290 ,-300.0 );
472
+ glEnd ();
473
+
474
+ glColor3f (1 ,1 ,244 /255.0 );
475
+ glBegin (GL_LINE_LOOP);
476
+ glVertex3f (-380 ,-292.0 ,-300.0 );
477
+ glVertex3f (-380 ,-278.0 ,-300.0 );
478
+ glVertex3f (380 ,-278.0 ,-300.0 );
479
+ glVertex3f (380 ,-292.0 ,-300.0 );
480
+ glEnd ();
481
+
482
+
483
+ instructText ((char *)cstr,-250 ,-175 ,-200 );
484
+ nav ();
485
+
486
+ // instructText((char*)cstr,-250,-175,-200);
487
+ if (styleselect==0 )
488
+ {
489
+ bars ();
490
+ }
491
+ else if (styleselect==1 )
492
+ {
493
+ circle3d ();
494
+ }
495
+ else if (styleselect==2 )
496
+ {
497
+ dust ();
498
+ }
499
+ else if (styleselect==3 )
500
+ {
501
+ pentagon ();
502
+ }
503
+ else if (styleselect==4 )
504
+ {
505
+ waves ();
506
+ }
507
+ // else if(styleselect==4)
508
+ // {
509
+ // CubicalMesh();
510
+ // }
511
+ // else if(styleselect==6)
512
+ // {
513
+ // DWaves();
514
+ // }
515
+ // else if(styleselect==6)
516
+ // {
517
+ // mesh3D();
518
+ // }
519
+ }
520
+ else
521
+ {
522
+ // instructText((char *)"Paused!",-75,-200,-200);
523
+ pausebutton ();
524
+ }
525
+ }
526
+ glutSwapBuffers ();
527
+ // if(sound.getPlayingOffset().asSeconds()==buffer.getDuration().asSeconds())
528
+ // exit(0);
529
+ }
530
+
531
+ int main (int argc, char *argv[])
532
+ {
533
+ // SFML usage error
534
+ if (argc < 2 )
535
+ {
536
+ std::cout << " Usage: wave_iteration <FILENAME>" << std::endl;
537
+ return 1 ;
538
+ }
539
+
540
+ fName =argv[1 ];
507
541
508
542
glutInit (&argc, argv);
509
543
W=glutGet (GLUT_SCREEN_WIDTH);
0 commit comments