Using OpenGL with GLUT in Lazarus

The Glut unit is deprecated but it still works. This example should work if you put the 32-bit glut32.dll (available for download here) in the program folder. You need a new simple program, not an application with a form, to test this example. We found this wiki page useful for preparing our simple example.

program GlutTest;
{$Apptype GUI}
// 
uses
  GL, GLU, GLUT;  // Put glut32.dll in program folder if necessary

procedure display; cdecl;
begin
  glClearColor (1.0, 1.0, 1.0, 1.0); // white background
  glMatrixMode(GL_PROJECTION);
  glLoadIdentity;
  glOrtho(0, 200, 0, 200, -1, 1);
  glClear(GL_COLOR_BUFFER_BIT);
  glColor3f (1.0, 0.0, 0.0);  // red
  glBegin(GL_POLYGON);
    // Irregular convex pentagon
    glVertex2i(5, 155);
    glVertex2i(10, 190);
    glVertex2i(40, 180);
    glVertex2i(175, 75);
    glVertex2i(50, 20);
  glEnd;

  glutSwapBuffers;
end;

begin
  glutInit(@argc, @argv);
  glutInitDisplayMode (GLUT_DOUBLE OR GLUT_RGB OR GLUT_DEPTH);
  glutInitWindowSize (200, 200);
  glutCreateWindow ('Glut Test');
  glutDisplayFunc(@display);
  glutMainLoop;
end.
    

You should see a window with a red irregular pentagon on a white background.

Programming - a skill for life!

How to use OpenGL for 2D and 3D graphics