Нашел у себя такую выдержку из некого FAQ'а по OpenGL. Код Дельфовский, но трудностей с переводом возникнуть не должно. Сорри, сам с OpenGL не баловался, за работоспособность не отвечаю.
Код
Листинг 13 Данная процедура заполняет основную поверхность голубым цветом и выводит текст "Primary surface" (Основная поверхность) в центре слева. Фоновый буфер закрашивается в красный цвет и содержит текст "Back buffer" (Фоновый буфер) в центре справа.
procedure TForm1.DrawSurfaces;
var DC : HDC;
ARect : TRect;
DDCanvas : TCanvas;
ATopPos : integer;
begin
// fill the primary surface with red and the back buffer with blue
// and put some text on each. Using a canvas makes this trivial.
DDCanvas := TCanvas.Create;
try
// first output to the primary surface
if PrimarySurface.GetDC( DC ) = DD_OK then
try
ARect := Rect( 0, 0, 640, 480 );
with DDCanvas do begin
Handle := DC; // make the canvas output to the DC
Brush.Color := clRed;
FillRect( ARect );
Brush.Style := bsClear; // transparent text background
Font.Name := 'Arial';
Font.Size := 24;
Font.Color := clWhite;
ATopPos := ( 480 - TextHeight( 'A' ) ) div 2;
TextOut( 10, ATopPos, 'Primary surface' );
end;
finally
// make sure we tidy up and release the DC
DDCanvas.Handle := 0;
PrimarySurface.ReleaseDC( DC );
end;
// now do back buffer
if BackBuffer.GetDC( DC ) = DD_OK then
try
with DDCanvas do begin
Handle := DC; // make the canvas output to the DC
Brush.Color := clBlue;
FillRect( ARect );
Brush.Style := bsClear; // transparent text background
Font.Name := 'Arial';
Font.Size := 24;
Font.Color := clWhite;
TextOut( 630 - TextWidth( 'Back buffer' ), ATopPos, 'Back buffer' );
end;
finally
// make sure we tidy up and release the DC
DDCanvas.Handle := 0;
BackBuffer.ReleaseDC( DC );
end;
finally
// make sure the canvas is freed
DDCanvas.Free;
end;
end;