-
Notifications
You must be signed in to change notification settings - Fork 24
/
glpanel.pas
executable file
·103 lines (88 loc) · 2.3 KB
/
glpanel.pas
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
unit glpanel;
interface
{$D-,L-,O+,Q-,R-,Y-,S-}
uses
dglOpenGL,Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ExtCtrls, stdctrls;
type
TGLPanel= class(TPanel)
private
DC: HDC;
RC: HGLRC;
protected
procedure Paint; override;
public
procedure MakeCurrent; overload;
procedure MakeCurrent(dummy: boolean); overload;
procedure ReleaseContext;
published
end;
procedure rglSetupGL(lPanel: TGLPanel; lAntiAlias: GLint);
procedure Register;
implementation
uses mainunit;
procedure Register;
begin
RegisterComponents('GLPanel', [TGLPanel]);
end;
procedure TGLPanel.Paint;
begin
wglMakeCurrent(self.DC, self.RC);
GLForm1.GLboxPaint(self);
SwapBuffers(Self.DC);
end;
procedure TGLPanel.MakeCurrent;
begin
wglMakeCurrent(self.DC, self.RC);
end;
procedure TGLPanel.MakeCurrent(dummy: boolean);
begin
MakeCurrent;
end;
procedure TGLPanel.ReleaseContext;
begin
wglMakeCurrent(0,0);
end;
procedure rglSetupGL(lPanel: TGLPanel; lAntiAlias: GLint);
var
//http://stackoverflow.com/questions/3444217/opengl-how-to-limit-to-an-image-component
PixelFormat: integer;
const
PFD: TPixelFormatDescriptor = (
nSize: sizeOf(TPixelFormatDescriptor);
nVersion: 1;
dwFlags: PFD_SUPPORT_OPENGL or PFD_DRAW_TO_WINDOW or PFD_DOUBLEBUFFER;
iPixelType: PFD_TYPE_RGBA;
cColorBits: 24;
cRedBits: 0;
cRedShift: 0;
cGreenBits: 0;
cGreenShift: 0;
cBlueBits: 0;
cBlueShift: 0;
cAlphaBits: 24;
cAlphaShift: 0;
cAccumBits: 0;
cAccumRedBits: 0;
cAccumGreenBits: 0;
cAccumBlueBits: 0;
cAccumAlphaBits: 0;
cDepthBits: 16;
cStencilBits: 0;
cAuxBuffers: 0;
iLayerType: PFD_MAIN_PLANE;
bReserved: 0;
dwLayerMask: 0;
dwVisibleMask: 0;
dwDamageMask: 0);
begin
lPanel.DC := GetDC(lPanel.Handle);
if lAntiAlias > 0 then
PixelFormat := lAntiAlias
else
PixelFormat := ChoosePixelFormat(lPanel.DC, @PFD);
SetPixelFormat(lPanel.DC, PixelFormat, @PFD);
lPanel.RC := wglCreateContext(lPanel.DC);
wglMakeCurrent(lPanel.DC, lPanel.RC);
end;
end.