Autor Beitrag
MariaMaria
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 16



BeitragVerfasst: Sa 02.07.05 16:49 
Hallo Leute,
Ich möchte OpenGL direkt in ein Bitmap rendern. Hat irgenjemand eine Ahnung wie sowas funktioniert?
(bitte mit quellcode)

danke inzwischen
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: Sa 02.07.05 16:58 
Funktioniert genauso, wie auf ein Fenster auch.
Einzige Ausnahme ist das Anfordern des HGLRC-Handles:

Anstatt DC := GetWindowDC(Wnd); übergibst Du DC := Bitmap.Canvas.Handle; zum Erzeugen des Render-Kontext. Ansonsten ist alles andere identisch (IIRC).

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.


Zuletzt bearbeitet von BenBE am Sa 02.07.05 16:59, insgesamt 1-mal bearbeitet
F34r0fTh3D4rk
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 5285
Erhaltene Danke: 28

Win Vista (32), Win 7 (64)
Eclipse, SciTE, Lazarus
BeitragVerfasst: Sa 02.07.05 16:58 
oder willst du das bild als bitmap speichern ?

dann brauchst du noch einen SaveDialog und machst das dann so:
ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
procedure GLScreenShot_BMP_1;
var
  F: file;
  FileInfo: BITMAPINFOHEADER;
  FileHeader: BITMAPFILEHEADER;
  pPicData: Pointer;
  Viewport: array[0..3] of integer;
begin
  ZeroMemory(@FileHeader, SizeOf(BITMAPFILEHEADER));
  ZeroMemory(@FileInfo, SizeOf(BITMAPINFOHEADER));
  glGetIntegerv(GL_VIEWPORT, @Viewport);
  FileInfo.biSize := SizeOf(BITMAPINFOHEADER);
  FileInfo.biWidth := Viewport[2];
  FileInfo.biHeight := Viewport[3];
  FileInfo.biPlanes := 1;
  FileInfo.biBitCount := 32;
  FileInfo.biSizeImage := FileInfo.biWidth*FileInfo.biHeight*(FileInfo.biBitCount);
  FileHeader.bfType := 19778;
  FileHeader.bfOffBits := SizeOf(BITMAPINFOHEADER)+SizeOf(BITMAPFILEHEADER);
  GetMem(pPicData, FileInfo.biSizeImage);
  glReadPixels(0, 0, Viewport[2], Viewport[3], GL_BGRA, GL_UNSIGNED_BYTE, pPicData);
  if Form1.savedialog1.execute then  //Formname noch anpassen, wenn nötig
    begin
      AssignFile(f, MainForm.SaveDialog1.filename);
      Rewrite(f, 1);
      BlockWrite(F, FileHeader, SizeOf(BITMAPFILEHEADER));
      BlockWrite(F, FileInfo, SizeOf(BITMAPINFOHEADER));
      BlockWrite(F, pPicData^, FileInfo.biSizeImage );
      CloseFile(f);
    end;
  FreeMem(pPicData, FileInfo.biSizeImage);
end;
MariaMaria Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 16



BeitragVerfasst: So 03.07.05 17:08 
user profile iconBenBE hat folgendes geschrieben:
Funktioniert genauso, wie auf ein Fenster auch.
Einzige Ausnahme ist das Anfordern des HGLRC-Handles:

Anstatt DC := GetWindowDC(Wnd); übergibst Du DC := Bitmap.Canvas.Handle; zum Erzeugen des Render-Kontext. Ansonsten ist alles andere identisch (IIRC).


Leider bekomme ich nur ein schwarzes Fenster, wenn ich das Bitmap nach dem Rendern auf die Form zeichne. Eine Ahnung was ich falsch gemacht habe: ?


ausblenden Delphi-Quelltext
1:
2:
DC := B.Canvas.Handle;
RC := CreateRenderingContext(DC, [], 24, 24, 0, 0, 0, 0);


und dann

ausblenden Delphi-Quelltext
1:
Canvas.Draw(0,0,B);					


Moderiert von user profile iconraziel: Code- durch Delphi-Tags ersetzt.
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: So 03.07.05 18:57 
Hast Du SwapBuffers angegeben? Frag evtl. auch einmal mit GetLastError auftretende Windows-Fehlercodes ab.

Bzw. gibt mal kurz etwas mehr Source. Evtl. seh ich dann eher, wo das Problem liegt.

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.