- procedure OutputToBitmap(FileName : string);
- var Bitmap : TBitmap;
- Dummi : Boolean;
- i,j : integer;
- h : byte;
- PixelData : PRGBQuad;
- Header : PBitmapInfo;
- begin
- Bitmap := TBitmap.Create;
- Bitmap.PixelFormat := pf32Bit;
- Bitmap.Width := RenderForm.ClientWidth;
- Bitmap.Height := RenderForm.ClientHeight;
- GetMem( PixelData, Bitmap.Width*Bitmap.Height*4 ); //Speicher für die Pixeldaten reservieren
- HptFenster.IdleHandler(HptFenster,Dummi); //Ausgabe Zeichnen
- glReadPixels(0, 0, Bitmap.Width, Bitmap.Height, GL_RGBA, GL_UNSIGNED_BYTE, PixelData);
- for i := 0 to Bitmap.Height * Bitmap.Width -1 do
- begin // RGB -> BGR (Bitmaps speichern BGR!)
- h := PixelData^.rgbBlue;
- PixelData^.rgbBlue := PixelData^.rgbRed;
- PixelData^.rgbRed := h;
- inc(PixelData);
- end;
- GetMem( Header, SizeOf( TBitmapInfoHeader ) );
- with Header^.bmiHeader do
- begin
- biSize := SizeOf( TBitmapInfoHeader );
- biWidth := Bitmap.Width;
- biHeight := Bitmap.Height;
- biPlanes := 1;
- biBitCount := 32;
- biCompression := BI_RGB;
- biSizeImage := Bitmap.Width*Bitmap.Height*4;
- end;
- SetDIBits( Bitmap.Canvas.Handle, Bitmap.Handle, 0, Bitmap.Height, PixelData, TBitmapInfo( Header^ ), DIB_RGB_COLORS );
- Bitmap.SaveToFile(FileName);
- Bitmap.Free;
- FreeMem( PixelData );
- FreeMem( Header );
- end;