1. -- 
  2. -- Jan & Uwe R. Zimmer, Australia, July 2011 
  3. -- 
  4.  
  5. with Ada.Numerics;                      use Ada.Numerics; 
  6. with Ada.Numerics.Elementary_Functions; use Ada.Numerics.Elementary_Functions; 
  7.  
  8. with Graphics_Configuration;            use Graphics_Configuration; 
  9. with Graphics_Data;                     use Graphics_Data; 
  10.  
  11. with GL; 
  12.  
  13. with GLOBE_3D; 
  14. --  with GLOBE_3D.Textures; 
  15.  
  16. with GLU; 
  17. with GLUT;                              use GLUT; 
  18. with GLUT.Devices; 
  19.  
  20. with Vectors_2D_N;                      use Vectors_2D_N; 
  21.  
  22. package body Graphics_Setup is 
  23.  
  24.    Deg_2_Rad : constant := Pi / 180.0; 
  25.  
  26.    ------------------ 
  27.    -- Clear For 3D -- 
  28.    ------------------ 
  29.  
  30.    procedure Reset_for_3D is 
  31.  
  32.       use GL; 
  33.  
  34.       Aspect_Ratio       : constant GL.Double := GL.Double (Viewer_Size (x)) / GL.Double (Viewer_Size (y)); 
  35.       Half_Field_of_View : Float := 0.5 * Float (Eye.FOVy) * Deg_2_Rad; -- In Radians 
  36.  
  37.    begin 
  38.       if Aspect_Ratio > 1.0 then -- If Wider than High 
  39.          Half_Field_of_View := Arctan (Float (Aspect_Ratio) * Tan (Float (Eye.FOVy))); 
  40.       end if; 
  41.       Eye.Clipper.max_dot_product := GLOBE_3D.Real (Sin (Half_Field_of_View)); 
  42.       Eye.Clipper.main_clipping := (0, 0, Viewer_Size (x) - 1, Viewer_Size (y) - 1); 
  43.  
  44.       GL.Viewport (0, 0, GL.Sizei (Viewer_Size (x)), GL.Sizei (Viewer_Size (y))); 
  45.       GL.MatrixMode (GL.PROJECTION); 
  46.       GL.LoadIdentity; 
  47.  
  48.       GLU.Perspective (fovy   => Eye.FOVy, -- Field of View in the Y 
  49.                        aspect => Aspect_Ratio, 
  50.                        zNear  => Camera_Close_Clipping_Plane, 
  51.                        zFar   => Camera_Far_Clipping_Plane); 
  52.  
  53.       GL.MatrixMode (GL.MODELVIEW); 
  54.       GL.ShadeModel (GL.SMOOTH);           -- Smooth vs. Flat 
  55.       GL.ClearColor (0.0, 0.0, 0.07, 0.0); -- Clear Value for Colour Buffer 
  56.       GL.ClearAccum (0.0, 0.0, 0.0, 0.0);  -- Clear Value for Accumulation Buffer 
  57.    end Reset_for_3D; 
  58.  
  59.    -------------------- 
  60.    -- Window Resized -- 
  61.    -------------------- 
  62.  
  63.    procedure Window_Resize (Size_x, Size_y : Integer) is 
  64.  
  65.    begin 
  66.       Viewer_Size := ((x => Size_x, y => Size_y)); 
  67.       Reset_for_3D; 
  68.    end Window_Resize; 
  69.  
  70.    ---------------------- 
  71.    -- Initialize Video -- 
  72.    ----------------------- 
  73.  
  74. --     Actual_LINE_WIDTH : aliased GL.Float; 
  75.  
  76.    procedure Initialize_Graphics (Operations : access procedure) is 
  77.  
  78.       GLUT_Options : constant Unsigned := GLUT.DOUBLE or GLUT.RGB or GLUT.DEPTH; 
  79.       Error : Integer; 
  80.  
  81.    begin 
  82. --        GLOBE_3D.Set_global_data_name ("Textures.zip"); 
  83. --        GLOBE_3D.Textures.Register_textures_from_resources; 
  84.  
  85.       Eye.FOVy := Camera_Field_of_View; 
  86.  
  87.       -- GLUT Stuff -- 
  88.       -- Get a Window with the correct properties -- 
  89.       GLUT.Init; 
  90.       GLUT.InitDisplayMode (GLUT_Options); 
  91.       GLUT.InitWindowSize (Viewer_Size (x), Viewer_Size (y)); 
  92.       GLUT.InitWindowPosition (0, 50); 
  93.       Error := GLUT.CreateWindow (Viewer_Title); 
  94.       if Error = 0 then 
  95.          null; 
  96.       end if; 
  97.  
  98.       -- Feedback Procedures -- 
  99.       GLUT.ReshapeFunc (Window_Resize'Address); 
  100.       GLUT.DisplayFunc (Operations.all'Address); 
  101.       GLUT.IdleFunc (Operations.all'Address); 
  102.  
  103.       GLUT.Devices.Initialize; 
  104.  
  105.       -- GL Stuff -- 
  106.       -- Clear Modes -- 
  107.       GL.Disable (GL.BLEND); 
  108.       GL.Disable (GL.LIGHTING); 
  109.       GL.Disable (GL.AUTO_NORMAL); 
  110.       GL.Disable (GL.NORMALIZE); 
  111.       GL.Disable (GL.DEPTH_TEST); 
  112.  
  113.       Reset_for_3D; 
  114.  
  115.       -- Enable Lighting -- 
  116.       GL.Enable (GL.LIGHTING); 
  117.       for Source in Initial_Lights'Range loop 
  118.          GLOBE_3D.Define (Source, Initial_Lights (Source)); 
  119.          GLOBE_3D.Switch_light (Source, True); 
  120.       end loop; 
  121.  
  122.       -- Reset Eye 
  123.       Eye.Clipper.Eye_Position := Camera_Initial_Position; 
  124.       Eye.World_Rotation       := GLOBE_3D.Id_33; 
  125.       Eye.FOVy                 := Camera_Field_of_View; 
  126.  
  127. --        GL.GetFloatv (GL.LINE_WIDTH_RANGE, Actual_LINE_WIDTH'Access); 
  128. --        Put ("Actual_LINE_WIDTH: "); Put (Float (Actual_LINE_WIDTH), 3, 2, 0); 
  129.    end Initialize_Graphics; 
  130.  
  131.    -- 
  132.  
  133. end Graphics_Setup;