This is the code,
TT and C are depth-sorted arrays of triangles and their respective colors.
I used the bool variable Q to assure only once the paint is done and on the second time it destroys the openglcontrol1. After calling the destroy method, it does not render any more, but the cpu core #4 keeps its 40% performance.
urender, geotypes and geofunc are my units for geometrical calculations
uses
Classes, Windows,SysUtils, LCLProc, LResources, Forms, Controls, Graphics, Dialogs,
OpenGLContext, GL, GLU, urender, geotypes, geofunc;
type
{ TForm1 }
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
procedure OpenGLControl1Paint(Sender: TObject);
private
public
OpenGLControl1: TOpenGLControl;
end;
var
Form1: TForm1;
Q : boolean = true;
implementation
{$R *.lfm}
{ TForm1 }
procedure TForm1.FormCreate(Sender: TObject);
begin
OpenGLControl1:=TOpenGLControl.Create(form1);
with OpenGLControl1 do begin
Name:='OpenGLControl1';
Align:=alClient;
Parent:=Self;
OnPaint:=@OpenGLControl1Paint;
AutoResizeViewport:=true;
end;
end;
procedure TForm1.OpenGLControl1Paint(Sender: TObject);
var
i,j,N : integer;
r : single;
begin
if Q then
begin
glClearColor(1.0, 1.0, 1.0, 1.0);
glClear(GL_COLOR_BUFFER_BIT);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0, double(width) / height, 0.1, 100.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(5,5,5,0,0,0,0,1,0);
glEnable(GL_BLEND);
glBlendFunc (GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
// opengl geometry
n := 10;
for i := 0 to n-1 do
begin
glBegin(GL_TRIANGLES);
glColor4f(C[i].x,C[i].y,C[i].z,0.15);
for j := 0 to 2 do
glVertex3f( TT[i,j].x, TT[i,j].y, TT[i,j].z);
glEnd();
end;
OpenGLControl1.SwapBuffers;
Q := not(Q);
end
else
OpenGLControl1.destroy;
end;
end.