You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

59 lines
1.5 KiB

  1. program SimpleLoadFromFile;
  2. {$mode objfpc}{$H+}
  3. uses
  4. {$IFDEF UNIX}{$IFDEF UseCThreads}
  5. cthreads,
  6. {$ENDIF}{$ENDIF}
  7. Classes, Windows, SysUtils, dglOpenGL, glBitmap, Helper;
  8. var
  9. oglWindow: TOpenGLWindow;
  10. running: Boolean = true;
  11. function WindowProc(hWnd: HWND; Msg: UINT; wParam: WPARAM; lParam: LPARAM): LRESULT; stdcall;
  12. var
  13. tex: TglBitmap2D;
  14. begin
  15. case Msg of
  16. WM_DESTROY: begin
  17. running := false;
  18. end;
  19. WM_KEYDOWN: begin
  20. if wParam = VK_RETURN then begin
  21. tex := TglBitmap2D.Create; // create empty texture
  22. try
  23. tex.GrabScreen(0, 0, 800, 600, tfRGB8ub3); // copy current framebuffer content to texture
  24. tex.SaveToFile(ExtractFilePath(ApplicationName) + 'screen.bmp', ftBMP); // save texture to file
  25. WriteLn('screen saved to screen.bmp');
  26. finally
  27. FreeAndNil(tex);
  28. end;
  29. end;
  30. end;
  31. end;
  32. result := DefWindowProc(hWnd, Msg, wParam, lParam);
  33. end;
  34. procedure RenderLoop;
  35. begin
  36. glBegin(GL_TRIANGLES);
  37. glColor4f(1, 0, 0, 1); glVertex2f(400, 100);
  38. glColor4f(0, 1, 0, 1); glVertex2f(100, 500);
  39. glColor4f(0, 0, 1, 1); glVertex2f(700, 500);
  40. glEnd;
  41. end;
  42. begin
  43. oglWindow := CreateOpenGLWindow('GrapScreen (hit enter to grab screen)', 800, 600, @WindowProc);
  44. while running and ProgressMesages do begin
  45. RenderLoop;
  46. SwapBuffers(oglWindow.DC);
  47. end;
  48. DestroyOpenGLWindow(oglWindow);
  49. end.