- procedure bitmap_render_ganz_neu(Breite, Hoehe : Integer; Dateiname : String);
- Var
- FormatIndex : integer;
- ErrorCode : GLenum;
- Bitmap1: TBitmap;
- Bitmap1DC : HDC;
- Bitmap1PFD: TPixelFormatDescriptor;
- Bitmap1RC : HGLRC;
- begin
- Bitmap1 := TBitmap.Create;
- Bitmap1DC := Bitmap1.Canvas.Handle;
- Bitmap1.PixelFormat := pf32bit;
- FillChar(Bitmap1PFD, SizeOf(TPixelFormatDescriptor), 0);
- With Bitmap1PFD Do Begin
- nSize:= SizeOf(Bitmap1PFD);
- nVersion:= 1;
- dwFlags:= PFD_SUPPORT_GDI or PFD_DRAW_TO_BITMAP or PFD_SUPPORT_OPENGL;
- iPixelType:= PFD_TYPE_RGBA;
- cColorBits:= 32;
- cDepthBits:= 32;
- iLayerType:= PFD_MAIN_PLANE;
- cRedBits := 0;
- cRedShift := 0;
- cGreenBits := 0;
- cGreenShift := 0;
- cBlueBits := 0;
- cBlueShift := 0;
- cAlphaBits := 0;
- cAlphaShift := 0;
- cAccumBits := 0;
- cAccumRedBits := 0;
- cAccumGreenBits := 0;
- cAccumBlueBits := 0;
- cAccumAlphaBits := 0;
- cStencilBits := 0;
- cAuxBuffers := 0;
- bReserved := 0;
- dwLayerMask := 0;
- dwVisibleMask := 0;
- dwDamageMask := 0;
- End;
- FormatIndex:= ChoosePixelFormat(Bitmap1DC, @Bitmap1PFD);
- If FormatIndex = 0 Then
- Raise Exception.Create('ChoosePixelFormat failed ' +
- IntToStr(GetLastError));
- If Not SetPixelFormat(Bitmap1DC, FormatIndex, @Bitmap1PFD) Then
- Raise Exception.Create('SetPixelFormat failed ' +
- IntToStr(GetLastError));
- Bitmap1RC:= wglCreateContext(Bitmap1DC);
- If FGLContext = 0 Then
- Raise Exception.Create('wglCreateContext failed ' +
- IntToStr(GetLastError));
- If Not wglMakeCurrent(Bitmap1DC, Bitmap1RC) Then
- Raise Exception.Create('wglMakeCurrent failed ' +
- IntToStr(GetLastError));
- ErrorCode:= glGetError;
- If ErrorCode <> GL_NO_ERROR Then
- Raise Exception.Create('FormCreate:' + gluErrorString(ErrorCode));
- glViewport(0, 0, Bitmap1.Width, Bitmap1.Height); // Setzt den Viewport für das OpenGL Fenster
- glMatrixMode(GL_PROJECTION); // Matrix Mode auf Projection setzen
- glLoadIdentity(); // Reset View
- glOrtho(-Breite/2, Breite/2, -Hoehe/2, Hoehe/2, -Breite, Breite);
- ErrorCode:= glGetError;
- If ErrorCode <> GL_NO_ERROR Then
- Raise Exception.Create('Resize:' + gluErrorString(ErrorCode));
- glMatrixMode(GL_MODELVIEW); // Zurück zur Modelview Matrix
- glLoadIdentity(); // Reset View
- glClear(GL_COLOR_BUFFER_BIT Or GL_DEPTH_BUFFER_BIT);
- glClearColor(0.5, 0.7, 0.9, 1.0);
- glEnable(GL_DEPTH_TEST);
- glClearDepth(0.98);
- Zeichne_in_Speicher(Breite, Hoehe); //Zeichenbefehle
- glFinish;
- ErrorCode:= glGetError;
- If ErrorCode <> GL_NO_ERROR Then
- Raise Exception.Create('Paint:' + gluErrorString(ErrorCode));
- Bitmap1.SaveToFile(Dateiname);
- Bitmap1.Destroy;
- End;