1. with GLUT, System; 
  2.  
  3. package body GLUT_2D is 
  4.  
  5.    GLUT_char : constant array (Font_type) of System.Address := 
  6.      ( 
  7.       Screen_9_by_15 => GLUT.BITMAP_9_BY_15, 
  8.       Screen_8_by_13 => GLUT.BITMAP_8_BY_13, 
  9.       Times_Roman_10 => GLUT.BITMAP_TIMES_ROMAN_10, 
  10.       Times_Roman_24 => GLUT.BITMAP_TIMES_ROMAN_24, 
  11.       Helvetica_10   => GLUT.BITMAP_HELVETICA_10, 
  12.       Helvetica_12   => GLUT.BITMAP_HELVETICA_12, 
  13.       Helvetica_18   => GLUT.BITMAP_HELVETICA_18 
  14.      ); 
  15.  
  16.    procedure Text_Output (s : String; font  : Font_type) is 
  17.  
  18.    begin 
  19.       for i in s'Range loop 
  20.          GLUT.BitmapCharacter (GLUT_char (font), Character'Pos (s (i))); 
  21.       end loop; 
  22.    end Text_Output; 
  23.  
  24.    procedure Push_3D_set_2D (main_size_x, main_size_y  : GL.Sizei) is 
  25.  
  26.       use GL; 
  27.  
  28.    begin 
  29.       -- Push current matrix mode and viewport attributes. 
  30.       GL.PushAttrib (GL.TRANSFORM_BIT or GL.VIEWPORT_BIT); 
  31.       GL.MatrixMode (GL.PROJECTION); 
  32.       GL.PushMatrix; -- In GL.PROJECTION mode, the stack depth is at least 2 
  33.       GL.LoadIdentity; 
  34.       GL.Ortho ( 
  35.                 0.0, GL.Double (main_size_x), GL.Double (main_size_y), 0.0, 
  36.                 GL.Double'(-1.0), 1.0); 
  37.       GL.MatrixMode (GL.MODELVIEW); 
  38.       GL.PushMatrix; -- In GL.MODELVIEW mode, the stack depth is at least 32 
  39.       GL.LoadIdentity; 
  40.    end Push_3D_set_2D; 
  41.  
  42.    procedure Pop_3D is 
  43.    begin 
  44.       GL.MatrixMode (GL.MODELVIEW); 
  45.       GL.PopMatrix; 
  46.       GL.MatrixMode (GL.PROJECTION); 
  47.       GL.PopMatrix; 
  48.       GL.PopAttrib; 
  49.    end Pop_3D; 
  50.  
  51.    procedure Text_output ( 
  52.                           x, y          : GL.Int; 
  53.                           main_size_x, 
  54.                           main_size_y  : GL.Sizei; 
  55.                           s            : String; 
  56.                           font         : Font_type 
  57.                          ) 
  58.    is 
  59.    begin 
  60.       Push_3D_set_2D (main_size_x, main_size_y); 
  61.       GL.RasterPos (x, y); 
  62.       Text_Output (s, font); 
  63.       Pop_3D; 
  64.    end Text_output; 
  65.  
  66.    procedure Text_output ( 
  67.                           p     : GL.Double_Vector_3D; 
  68.                           s     : String; 
  69.                           font  : Font_type 
  70.                          ) 
  71.    is 
  72.    begin 
  73.       GL.PushMatrix; 
  74.       GL.Translate (p); 
  75.       GL.RasterPos (0, 0); 
  76.       Text_Output (s, font); 
  77.       GL.PopMatrix; 
  78.    end Text_output; 
  79.  
  80.    procedure Put_Image ( 
  81.                         Image_ID     : Integer; 
  82.                         x, y          : GL.Int; 
  83.                         size_x, 
  84.                         size_y       : GL.Int; 
  85.                         main_size_x, 
  86.                         main_size_y  : GL.Sizei 
  87.                        ) 
  88.    is 
  89.    begin 
  90.       --  fx := GL.Float (size_x) / GL.Float (main_size_x); 
  91.       --  fy := GL.Float (size_y) / GL.Float (main_size_y); 
  92.       Push_3D_set_2D (main_size_x, main_size_y); 
  93.       GL.Translate (GL.Double (x), GL.Double (y), 0.0); 
  94.       -- GL.Enable (GL.TEXTURE_2D); 
  95.       GL.BindTexture (GL.TEXTURE_2D, GL.Uint (Image_ID)); 
  96.       GL.GL_Begin (GL.QUADS); 
  97.       GL.TexCoord (0.0, 0.0); 
  98.       GL.Vertex (0, size_y); 
  99.       GL.TexCoord (1.0, 0.0); 
  100.       GL.Vertex (size_x, size_y); 
  101.       GL.TexCoord (1.0, 1.0); 
  102.       GL.Vertex (size_x, 0); 
  103.       GL.TexCoord (0.0, 1.0); 
  104.       GL.Vertex (0, 0); 
  105.       GL.GL_End; 
  106.       Pop_3D; 
  107.    end Put_Image; 
  108.  
  109. end GLUT_2D;