Task: OpenGL



C#: using OpenTK;
using OpenTK.Graphics;
namespace OpenGLTest
{
    class Program
    {
        static void Main(string[] args)
        {
            
            GameWindow window = new GameWindow(640, 480, GraphicsMode.Default, "OpenGL Example");

            GL.MatrixMode(MatrixMode.Projection);
            GL.LoadIdentity();
            GL.Ortho(-30.0, 30.0, -30.0, 30.0, -30.0, 30.0);
            GL.MatrixMode(MatrixMode.Modelview);

            
            window.RenderFrame += new RenderFrameEvent(a_RenderFrame);
            
            window.Run();
        }
        static void a_RenderFrame(GameWindow sender, RenderFrameEventArgs e)
        {
            GL.ClearColor(0.3f, 0.3f, 0.3f, 0f);
            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

            GL.ShadeModel(ShadingModel.Smooth);

            GL.LoadIdentity();
            GL.Translate(-15.0f, -15.0f, 0.0f);

            GL.Begin(BeginMode.Triangles);
            GL.Color3(1.0f, 0.0f, 0.0f);
            GL.Vertex2(0.0f, 0.0f);
            GL.Color3(0.0f, 1.0f, 0.0f);
            GL.Vertex2(30f, 0.0f);
            GL.Color3(0.0f, 0.0f, 1.0f);
            GL.Vertex2(0.0f, 30.0f);
            GL.End();
            
            sender.SwapBuffers();
        }
    }
}









Ada: with Lumen.Window;
with Lumen.Events;
with Lumen.Events.Animate;
with GL;
with GLU;

procedure OpenGL is

   The_Window : Lumen.Window.Handle;

   Program_Exit : Exception;

   
   procedure Quit_Handler (Event : in Lumen.Events.Event_Data) is
   begin
      raise Program_Exit;
   end;

   
   procedure Resize_Scene (Width, Height : in Natural) is
      use GL;
      use GLU;
   begin
      
      glViewport (0, 0, GLsizei (Width), GLsizei (Height));

      
      glMatrixMode (GL_PROJECTION);
      glLoadIdentity;

      
      gluPerspective (45.0, GLdouble (Width) / GLdouble (Height), 0.1, 100.0);

      
      glMatrixMode (GL_MODELVIEW);
      glLoadIdentity;
   end Resize_Scene;

   procedure Init_GL is
      use GL;
      use GLU;
   begin
      
      glShadeModel (GL_SMOOTH);

      
      glClearColor (0.0, 0.0, 0.0, 0.0);

      
      glClearDepth (1.0);
      
      glEnable (GL_DEPTH_TEST);
      
      glDepthFunc (GL_LEQUAL);

      glHint (GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
   end Init_GL;

   
   procedure Resize_Handler (Event : in Lumen.Events.Event_Data) is
      Height : Natural := Event.Resize_Data.Height;
      Width  : Natural := Event.Resize_Data.Width;
   begin
      
      if Height = 0 then
         Height := 1;
      end if;

      Resize_Scene (Width, Height);
   end;

   procedure Draw is
      use GL;
   begin
      
      glClear (GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT);
      
      glLoadIdentity;

      
      glBegin (GL_TRIANGLES);
      glColor3f (1.0, 0.0, 0.0);
      glVertex3f ( 0.0,  1.0, 0.0);
      glColor3f (0.0, 1.0, 0.0);
      glVertex3f (-1.0, -1.0, 0.0);
      glColor3f (0.0, 0.0, 1.0);
      glVertex3f ( 1.0, -1.0, 0.0);
      glEnd;
   end Draw;

   procedure Frame_Handler (Frame_Delta : in Duration) is
   begin
      Draw;
      Lumen.Window.Swap (The_Window);
   end Frame_Handler;

begin

   Lumen.Window.Create (Win    => The_Window,
                        Name   => "OpenGL Demo",
                        Width  => 640,
                        Height => 480,
                        Events => (Lumen.Window.Want_Key_Press => True,
                                   Lumen.Window.Want_Exposure  => True,
                                   others                      => False));

   Resize_Scene (640, 480);
   Init_GL;

   Lumen.Events.Animate.Select_Events
     (Win   => The_Window,
      FPS   => Lumen.Events.Animate.Flat_Out,
      Frame => Frame_Handler'Unrestricted_Access,
      Calls => (Lumen.Events.Resized       => Resize_Handler'Unrestricted_Access,
                Lumen.Events.Close_Window  => Quit_Handler'Unrestricted_Access,
                others                     => Lumen.Events.No_Callback));

exception
   when Program_Exit =>
      null; 
end OpenGL;