unit Unit1; {$mode objfpc}{$H+} interface uses Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, OpenGLContext, gl; // OpenGLを使う時はコレを追加 type { TForm1 } TForm1 = class(TForm) procedure FormCreate(Sender: TObject); procedure GLboxPaint(Sender: TObject); private GLBox: TOpenGLControl; public end; var Form1: TForm1; implementation {$R *.lfm} procedure TForm1.FormCreate(Sender: TObject); begin // フォーム生成時 // TOpenGLControl を新規作成してフォームの子にする GLbox := TOpenGLControl.Create(Self); GLbox.AutoResizeViewport := True; GLBox.Parent := Self; GLBox.MultiSampling := 4; GLBox.Align := alClient; // フォームのクライアント領域全体に広げる // 描画処理をするプロシージャを割り当て // "mode delphi" の場合は "GLBox.OnPaint := GLboxPaint" にする GLBox.OnPaint := @GLboxPaint; GLBox.invalidate; end; procedure TForm1.GLboxPaint(Sender: TObject); begin // GLBox (TOpenGLControl) 描画処理 // 背景を消去 glClearColor(0.27, 0.53, 0.71, 1.0); // Set blue background glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT); glLoadIdentity; // 三角形を描画 glBegin(GL_TRIANGLES); glColor3f(1, 0, 0); glVertex3f(0.0, 1.0, 0.0); glColor3f(0, 1, 0); glVertex3f(-1.0, -1.0, 0.0); glColor3f(0, 0, 1); glVertex3f(1.0, -1.0, 0.0); glEnd; // ダブルバッファ切り替え GLbox.SwapBuffers; end; end.