@@ -35,8 +35,9 @@ vector<string> instructions = {
35
35
" 'f' - toggle full screen" ,
36
36
" fails on Intel GPU" ,
37
37
" 'i' - toggle instructions" ,
38
- " 'l ' and 'L ' - line width " ,
38
+ " '+ ' and '- ' - field of view " ,
39
39
" 'p' - toggle pause" ,
40
+ " 'w' - toggle wireframe" ,
40
41
" 'z' and 'Z' - zoom" ,
41
42
" 'x' and ESC - exit"
42
43
};
@@ -74,13 +75,13 @@ void DisplayInstructions(int w , int h)
74
75
#define DISPLAY_MODE (GLUT_RGBA | GLUT_DEPTH | GLUT_DOUBLE)
75
76
#endif // USE_STEREO
76
77
77
- const int NUMBER_OF_OBJECTS = 32 ;
78
+ const int NUMBER_OF_OBJECTS = 128 ;
78
79
vector<Instance> instances;
79
80
freetype::font_data our_font;
80
81
FrameBufferObject fbo;
81
82
82
83
Disc disc1 (64 , pi <float >() * 1.5f, 0.25f, 0.125f);
83
- Disc disc2 (64 , pi <float >() * 2.0f , 0.25f , 0.0f);
84
+ Disc disc2 (64 , pi <float >() * 2.0f , 1.0f , 0.0f);
84
85
Disc disc3 (128 , pi <float >() * 2.0f , 1.0f , 0.0f);
85
86
Cylinder cylinder1 (32 , 4 , pi <float >() * 2.0f, 1.0f, 1.0f);
86
87
Cylinder cylinder2 (4 , 2 , pi <float >() * 2.0f , 1.0f , 0.5f);
@@ -265,32 +266,55 @@ void KeyboardFunc(unsigned char c, int x, int y)
265
266
266
267
case ' x' :
267
268
case 27 :
269
+ glutLeaveFullScreen ();
268
270
glutLeaveMainLoop ();
269
271
return ;
270
272
}
271
273
}
272
274
273
275
void DrawScene (Window * window)
274
276
{
277
+ glClearColor (0 , 0 , 0 , 0 );
278
+ glClear (GL_COLOR_BUFFER_BIT);
279
+
280
+ vec3 ambient = vec3 (0 .1f , 0 .1f , 0 .1f );
281
+ vec3 specular = vec3 (1 .0f , 1 .0f , 1 .0f );
275
282
phong_shader.GLReturnedError (" DrawScene() - entering" );
276
283
#ifdef MOVE
277
- mat4 m = rotate (mat4 () , radians (window->LocalTime () * 30 .0f ) , vec3 (0 .0f , 1 .0f , 0 .2f ));
278
- m = translate (m, vec3 (0 . 0f , 11 .5f * cos (window->LocalTime () * 0 . 5f ) + 2 .0f , 11 .5f * sin (window->LocalTime () * 0 . 5f ) + 2 .0f ));
284
+ mat4 m = rotate (mat4 () , radians (window->LocalTime () * 60 .0f ) , vec3 (0 .0f , 1 .0f , 0 .2f ));
285
+ m = translate (m, vec3 (11 . 5f * sin (window-> LocalTime () * 1 . 0f - 0.5 ) + 2 . 0f , 11 .5f * cos (window->LocalTime () * 1 . 0f ) + 2 .0f , 11 .5f * sin (window->LocalTime () * 1 . 0f ) + 2 .0f ));
279
286
#else
280
287
mat4 m;
281
288
#endif // MOVE
289
+ mat4 projection_matrix = perspective (radians (window->fovy ) , window->aspect , window->near_distance , window->far_distance );
290
+ glViewport (0 , 0 , window->size .x , window->size .y );
282
291
283
- mat4 view_matrix = lookAt (vec3 (m * vec4 (eye, 1 .0f )), cop, up);
292
+ vec3 e = vec3 (m * vec4 (eye , 1 .0f ));
293
+ mat4 view_matrix = lookAt (e, cop, up);
284
294
mat4 model_matrix;
285
- mat4 projection_matrix = perspective (radians (window->fovy ), window->aspect , window->near_distance , window->far_distance );
286
295
296
+ // Skybox can be made here - translate by the inverse of the eye
297
+ model_matrix = translate (model_matrix , e);
298
+ model_matrix = scale (model_matrix , vec3 (10 .0f , 10 .0f , 10 .0f ));
299
+
300
+ phong_shader.Use (model_matrix , view_matrix , projection_matrix);
301
+ phong_shader.SelectSubroutine (PhongShader::PHONG_WITH_TEXTURE);
302
+ phong_shader.EnableTexture (textures[4 ] , 0 );
303
+ phong_shader.SetMaterial (vec3 (1 .0f , 1 .0f , 1 .0f ) , vec3 () , 32 .0f , ambient);
304
+ phong_shader.SetLightPosition (vec3 (0 .0f , 0 .0f , 1000 .0f ));
305
+ phong_shader.SetOpacity (1 .0f );
306
+ glEnable (GL_BLEND);
307
+ glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
308
+ cube.Draw (false );
309
+ phong_shader.UnUse ();
310
+ glDisable (GL_TEXTURE_2D);
311
+ glClear (GL_DEPTH_BUFFER_BIT);
312
+
313
+ model_matrix = mat4 ();
287
314
vec3 z_axis = vec3 (0 .0f , 0 .0f , 1 .0f );
288
315
vec3 y_axis = vec3 (0 .0f , 1 .0f , 0 .0f );
289
- vec3 ambient = vec3 (0 .1f , 0 .1f , 0 .1f );
290
- vec3 specular = vec3 (1 .0f , 1 .0f , 1 .0f );
291
316
float c_offset = radians (45 .0f );
292
317
293
- glViewport (0 , 0 , window->size .x , window->size .y );
294
318
295
319
const int count_of_shapes = 4 ;
296
320
@@ -312,11 +336,12 @@ void DrawScene(Window * window)
312
336
disc1.Draw (false );
313
337
break ;
314
338
case 1 :
315
- disc3 .Draw (false );
339
+ disc2 .Draw (false );
316
340
break ;
317
341
case 2 :
342
+ glEnable (GL_TEXTURE_2D);
318
343
phong_shader.SelectSubroutine (PhongShader::PHONG_WITH_TEXTURE);
319
- phong_shader.EnableTexture (textures[2 ], 0 );
344
+ phong_shader.EnableTexture (textures[i % textures. size () - 1 ], 0 );
320
345
plane2.Draw (false );
321
346
glDisable (GL_TEXTURE_2D);
322
347
break ;
@@ -327,11 +352,13 @@ void DrawScene(Window * window)
327
352
phong_shader.UnUse ();
328
353
}
329
354
355
+ glDisable (GL_BLEND);
330
356
model_matrix = mat4 ();
331
357
mat4 mz = model_matrix;
332
358
model_matrix = scale (model_matrix, vec3 (0 .5f , 0 .5f , 16 .0f ));
333
359
334
360
phong_shader.Use (model_matrix, view_matrix, projection_matrix);
361
+ phong_shader.SelectSubroutine (PhongShader::BASIC_PHONG);
335
362
phong_shader.SetMaterial (vec3 (0 .0f , 0 .0f , 0 .8f ), specular, 128 .0f , ambient);
336
363
phong_shader.SetLightPosition (vec3 (0 .0f , 1000 .0f , 0 .0f ));
337
364
cylinder1.Draw (false );
@@ -340,6 +367,7 @@ void DrawScene(Window * window)
340
367
model_matrix = rotate (mz, radians (90 .0f ), y_axis);
341
368
model_matrix = scale (model_matrix, vec3 (0 .5f , 0 .5f , 16 .0f ));
342
369
phong_shader.Use (model_matrix, view_matrix, projection_matrix);
370
+ phong_shader.SelectSubroutine (PhongShader::BASIC_PHONG);
343
371
phong_shader.SetMaterial (vec3 (1 .0f , 0 .0f , 0 .0f ), specular, 128 .0f , ambient);
344
372
phong_shader.SetLightPosition (vec3 (0 .0f , 1000 .0f , 0 .0f ));
345
373
cylinder1.Draw (false );
@@ -348,12 +376,13 @@ void DrawScene(Window * window)
348
376
model_matrix = rotate (mz, radians (-90 .0f ), vec3 (1 .0f , 0 .0f , 0 .0f ));
349
377
model_matrix = scale (model_matrix, vec3 (0 .5f , 0 .5f , 16 .0f ));
350
378
phong_shader.Use (model_matrix, view_matrix, projection_matrix);
379
+ phong_shader.SelectSubroutine (PhongShader::BASIC_PHONG);
351
380
phong_shader.SetMaterial (vec3 (0 .0f , 1 .0f , 0 .0f ), specular, 128 .0f , ambient);
352
381
phong_shader.SetLightPosition (vec3 (0 .0f , 1000 .0f , 0 .0f ));
353
382
cylinder1.Draw (false );
354
383
phong_shader.UnUse ();
355
384
356
- cylinder1.UpdateValues (TestUpdate, window->LocalTime (), nullptr );
385
+ // cylinder1.UpdateValues(TestUpdate, window->LocalTime(), nullptr);
357
386
}
358
387
359
388
void DisplayCube ()
@@ -406,7 +435,7 @@ void DisplayDisc()
406
435
vec4 crimson (0 .6f , 0 .0f , 0 .0f , 1 .0f );
407
436
vec3 ambient = vec3 (0 .0f , 0 .0f , 0 .0f );
408
437
vec3 specular = vec3 (0 .0f , 0 .0f , 0 .3f );
409
- vec3 diffuse = vec3 (0 .0f , 0 .0f , 0 .9f );
438
+ vec3 diffuse = vec3 (0 .9f , 0 .9f , 0 .9f );
410
439
411
440
glClearColor (crimson.r , crimson.g , crimson.b , crimson.a );
412
441
glClear (GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
@@ -422,20 +451,21 @@ void DisplayDisc()
422
451
phong_shader.Use (model_matrix , view_matrix , projection_matrix);
423
452
phong_shader.SetMaterial (diffuse , specular , 128 .0f , ambient);
424
453
phong_shader.SetLightPosition (vec3 (0 .0f , 0 .0f , 1000 .0f ));
425
- phong_shader.SelectSubroutine (PhongShader::PHONG_WITH_TEXTURE);
426
- phong_shader.EnableTexture (textures[2 ] , 0 );
427
- disc3.Draw (false );
454
+ phong_shader.SelectSubroutine (PhongShader::BASIC_PHONG);
455
+ // phong_shader.SelectSubroutine(PhongShader::PHONG_WITH_TEXTURE);
456
+ // phong_shader.EnableTexture(textures[2] , 0);
457
+ disc2.Draw (false );
428
458
phong_shader.UnUse ();
429
459
430
460
if (window->draw_normals )
431
461
{
432
462
constant_shader.Use (model_matrix , view_matrix , projection_matrix);
433
463
constant_shader.SetMaterial (diffuse , specular , 32 .0f , vec3 (1 .0f , 1 .0f , 1 .0f ));
434
- disc3 .Draw (true );
464
+ disc2 .Draw (true );
435
465
constant_shader.UnUse ();
436
466
}
437
467
glutSwapBuffers ();
438
- disc3.UpdateValues (TestUpdateDisc , window->LocalTime (), nullptr );
468
+ // disc3.UpdateValues(TestUpdateDisc , window->LocalTime(), nullptr);
439
469
}
440
470
441
471
void DisplayPlane ()
@@ -547,21 +577,43 @@ void DisplayPlane()
547
577
548
578
void DisplayGrid ()
549
579
{
550
- // cout << "dg\n";
580
+ static int texture_index = 0 ;
581
+ static int opacity_direction = 0 ;
551
582
552
583
Window * window = Window::FindCurrentWindow (windows);
553
584
if (window->handle == BAD_GL_VALUE)
554
585
return ;
555
586
587
+ float fade_controller = float (fmod (double (window->LocalTime ()), 10.0 ));
588
+ float opacity = 1 .0f ;
589
+
590
+ if (fade_controller < 1 .0f )
591
+ {
592
+
593
+ opacity = smoothstep (0 .0f , 1 .0f , fade_controller);
594
+ if (opacity_direction < 0 )
595
+ texture_index = (texture_index + 1 ) % textures.size ();
596
+ opacity_direction = 1 ;
597
+ }
598
+ else if (fade_controller >= 9 .0f )
599
+ {
600
+ opacity = smoothstep (0 .0f , 1 .0f , 10 .0f - fade_controller);
601
+ opacity_direction = -1 ;
602
+ }
603
+
604
+ // cout << "Fade Controller: " << fade_controller << " opacity: " << opacity << endl;
605
+
556
606
glViewport (0 , 0 , window->size .x , window->size .y );
557
- vec4 crimson (0 .6f , 0 .0f , 0 .0f , 1 .0f );
607
+ vec4 crimson (0 .6f , 0 .0f , 0 .0f , 0 .0f );
558
608
vec3 ambient = vec3 (0 .0f , 0 .0f , 0 .0f );
559
609
vec3 specular = vec3 (1 .0f , 1 .0f , 1 .0f );
560
610
vec3 diffuse = vec3 (0 .0f , 0 .0f , 0 .8f );
561
611
562
612
glClearColor (crimson.r , crimson.g , crimson.b , crimson.a );
563
613
glClear (GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
564
614
glEnable (GL_DEPTH_TEST);
615
+ glEnable (GL_BLEND);
616
+ glBlendFunc (GL_SRC_ALPHA , GL_ONE_MINUS_SRC_ALPHA);
565
617
566
618
vector<Constellation::PositionData> & pd = gc.GetPositionData ();
567
619
@@ -600,7 +652,8 @@ void DisplayGrid()
600
652
phong_shader.SetMaterial (diffuse , specular , 64 .0f , ambient);
601
653
phong_shader.SetLightPosition (vec3 (0 .0f , 0 .0f , 1000 .0f ));
602
654
phong_shader.SelectSubroutine (PhongShader::PHONG_WITH_TEXTURE);
603
- phong_shader.EnableTexture (textures[1 ] , 0 );
655
+ phong_shader.EnableTexture (textures[texture_index] , 0 );
656
+ phong_shader.SetOpacity (opacity);
604
657
plane2.Draw (false );
605
658
phong_shader.UnUse ();
606
659
if (window->draw_normals )
@@ -613,6 +666,7 @@ void DisplayGrid()
613
666
// Animate the rotation of the objects within the grid.
614
667
(*iter).outward_direction_vector = vec3 (r * vec4 ((*iter).outward_direction_vector , 1 .0f ));
615
668
}
669
+ glDisable (GL_BLEND);
616
670
glutSwapBuffers ();
617
671
}
618
672
@@ -704,7 +758,7 @@ bool InitializeTextures()
704
758
texture_file_names.push_back (" c2.jpg" );
705
759
texture_file_names.push_back (" c3.jpg" );
706
760
texture_file_names.push_back (" c4.jpg" );
707
-
761
+ texture_file_names. push_back ( " carthage-logo-main.png " );
708
762
textures.resize (texture_file_names.size ());
709
763
for (size_t i = 0 ; i < texture_file_names.size (); i++)
710
764
{
@@ -751,12 +805,12 @@ int main(int argc, char * argv[])
751
805
gc.Initialize (525 );
752
806
753
807
// This vector is used to initialize all the window objects.
754
- // windows.push_back(Window("Basic Shape Viewer" , nullptr , nullptr , nullptr , nullptr , ivec2(512 , 512) , 50.0f , 1.0f , 100.0f));
808
+ windows.push_back (Window (" Basic Shape Viewer" , nullptr , nullptr , nullptr , nullptr , ivec2 (512 , 512 ) , 50 .0f , 1 .0f , 100 .0f ));
755
809
// windows.push_back(Window("Cylinder" , DisplayCylinder , nullptr , nullptr , nullptr , ivec2(512 , 512) , 50.0f , 1.0f , 100.0f));
756
810
windows.push_back (Window (" Plane" , DisplayPlane , nullptr , nullptr , nullptr , ivec2 (512 , 512 ) , 50 .0f , 1 .0f , 100 .0f ));
757
811
// windows.push_back(Window("Disc" , DisplayDisc , nullptr , nullptr , nullptr , ivec2(512 , 512) , 50.0f , 1.0f , 100.0f));
758
812
// windows.push_back(Window("Cube", DisplayCube, nullptr, nullptr, nullptr, ivec2(512, 512), 50.0f, 1.0f, 100.0f));
759
- // windows.push_back(Window("Grid" , DisplayGrid , nullptr , nullptr , nullptr , ivec2(512 , 512) , 50.0f , 1.0f , 400.0f));
813
+ windows.push_back (Window (" Grid" , DisplayGrid , nullptr , nullptr , nullptr , ivec2 (512 , 512 ) , 50 .0f , 1 .0f , 400 .0f ));
760
814
Window::InitializeWindows (windows , DisplayFunc , KeyboardFunc , CloseFunc, ReshapeFunc , IdleFunc);
761
815
762
816
windows[0 ].SetWindowTitle (" NEW TITLE" );
0 commit comments