Delphi - объектно-ориентированный язык программирования, разработанный компанией Borland в 1995 году. Он основан на языке программирования Pascal, но имеет более расширенные возможности и добавлены новые функции.
Delphi является интегрированной средой разработки (IDE), которая позволяет разрабатывать программное обеспечение для различных платформ, включая Windows, macOS, Android и iOS. Delphi достигает многоплатформенности с помощью...
// К заголовку RadialBlur(For OpenGL)
// Данный код работает правильно только, если в
пректе 0 форм ,
// а сам код введен в DPR файл!
RadialBlur;
[0..2] of glFloat;
var [0..255] of Boolean; [0..3] of TVector;
normal: TVector; [0..3] of glFloat = (0.2, 0.2, 0.2,
1.0); [0..3] of glFloat = (0.0, 5.0, 10.0, 1.0);
[0..3] of glFloat = (0.2, 0.2, 0.2,
1.0); [0..3] of glFloat = (0.3, 0.3, 0.3,
1.0); [0..3] of glFloat = (0.8, 0.8, 0.8,
1.0); [0..3] of glFloat = (0.2, 0.2, 0.2,
1.0); glBindTexture(target: GLenum; texture: GLuint);
stdcall ; external opengl32;
glGenTextures(n: GLsizei; var textures: GLuint);
stdcall ; external opengl32;
glCopyTexSubImage2D(target: GLenum; level, xoffset,
yoffset, x, y: GLint; width, height: GLsizei);
stdcall ; external opengl32;
glCopyTexImage2D(target: GLenum; level: GLint;
internalFormat: GLenum; x, y: GLint;
width, height: GLsizei; border: GLint); stdcall ; external
opengl32; IntToStr(Num: Integer): string ;
begin ; EmptyTexture: glUint;
var of glUint;
pData: Pointer; ; ReduceToUnit(var vector: array of
glFloat); Length = 0 then
Length := 1;
; calcNormal(const v: array of TVector;
var cross: array of glFloat);
var [0..2] of glFloat;
begin ; ProcessHelix;
const [1..4] of glFloat = (0.4, 0.2, 0.8,
1.0); [1..4] of glFloat = (1, 1, 1, 1);
var phi < 360 do
begin theta < 360 * twists do
begin
v := phi / 180 * pi; ;
phi := phi + 20;
end ; ; ViewOrtho;
begin ; ViewPerspective;
begin ; RenderToTexture;
begin GL_DEPTH_BUFFER_BIT);
glViewport(0, 0, 640, 480); ; DrawBlur(const times: Integer; const inc:
glFloat); I := 0 to times - 1 do
begin ; ; glDraw();
begin GL_DEPTH_BUFFER_BIT);
glLoadIdentity(); ; glInit();
begin : ; glResizeWnd(Width, Height: Integer);
begin (Height = 0) then ; ProcessKeys;
begin ; WndProc(hWnd: HWND; Msg: UINT; wParam: WPARAM; lParam: LPARAM):
LRESULT; stdcall ;
begin (Msg) of
WM_CREATE:
begin
;
WM_CLOSE:
begin
PostQuitMessage(0);
Result := 0
end ;
keys[wParam] := True ;
Result := 0;
end ;
keys[wParam] := False ;
Result := 0;
end ;
WM_SIZE:
glResizeWnd(LOWORD(lParam),
HIWORD(lParam)); ;
WM_TIMER:
if wParam = FPS_TIMER then
begin
FPSCount :=
Round(FPSCount * 1000 / FPS_INTERVAL);
;
end ;
else ; ; glKillWnd(Fullscreen: Boolean);
begin Fullscreen then ^), 0);
ShowCursor(True );
end ; (not wglMakeCurrent(h_DC, 0)) then
MessageBox(0, 'Release of DC and RC failed!', 'Error',
MB_OK or MB_ICONERROR);
(not wglDeleteContext(h_RC)) then
begin MB_ICONERROR);
h_RC := 0;
end ; ((h_DC = 1) and (ReleaseDC(h_Wnd, h_DC) < > 0)) then
begin MB_ICONERROR);
h_DC := 0;
end ; ((h_Wnd < > 0) and (not DestroyWindow(h_Wnd)))
then ; (not UnRegisterClass('OpenGL', hInstance)) then
begin MB_ICONERROR);
hInstance := 0;
end ; ; glCreateWnd(Width, Height: Integer; Fullscreen: Boolean;
PixelDepth: Integer): Boolean;
var );
file : wndClass do ; (RegisterClass(wndClass) = 0) then MB_ICONERROR);
Result := False ;
Exit ; Fullscreen then
begin dmScreenSettings do
begin DM_PELSHEIGHT
or DM_BITSPERPEL;
end ;
(ChangeDisplaySettings(dmScreenSettings,
CDS_FULLSCREEN) =
begin
MessageBox(0, 'Unable to switch to fullscreen!',
'Error', MB_ICONERROR);
Fullscreen := False ;
end ;
end ; (Fullscreen) then
begin WS_CLIPSIBLINGS; ); ; ); h_Wnd = 0 then
begin MB_ICONERROR); ;
Exit;
end ; (h_DC = 0) then
begin MB_ICONERROR);
Result := False ;
Exit;
end ; pfd do
begin PFD_SUPPORT_OPENGL PFD_DOUBLEBUFFER; ; (PixelFormat = 0) then
begin MB_ICONERROR);
Result := False ;
Exit;
end ; (not SetPixelFormat(h_DC, PixelFormat, @pfd)) then
begin MB_ICONERROR);
Result := False ;
Exit;
end ; (h_RC = 0) then
begin MB_ICONERROR);
Result := False ;
Exit;
end ; (not wglMakeCurrent(h_DC, h_RC)) then
begin MB_ICONERROR);
Result := False ;
Exit;
end ; );
;
end ; WinMain(hInstance: HINST; hPrevInstance: HINST;
lpCmdLine: PChar; nCmdShow: Integer): Integer; stdcall ;
var ;
not glCreateWnd(640, 480, FALSE , 32) then
begin ; not finished do
begin (PeekMessage(msg, 0, 0, 0, PM_REMOVE)) then
begin
(msg.message = WM_QUIT) then
finished := True
else
begin ;
end
else
begin
Inc(FPSCount);
2; (keys[VK_ESCAPE]) then
else
ProcessKeys; ;
end ; );
Result := msg.wParam;
end ; .
program
uses
Windows,
Messages,
OpenGL;
const
WND_TITLE = 'Radial Blur';
FPS_TIMER = 1;
type
TVector = array
h_Wnd: HWND;
// Textures
BlurTexture: glUint; // An Unsigned Int
To Store The Texture Number
// User vaiables
Angle: glFloat;
Vertexes: array
LmodelAmbient: array
{$R *.RES}
procedure
procedure
procedure
procedure
function
Str(Num, result);
end
function
txtnumber: glUint;
data: array
begin
glGenTextures(1, txtnumber); // Create 1
Texture
glBindTexture(GL_TEXTURE_2D, txtnumber);
// Bind The Texture
glTexImage2D(GL_TEXTURE_2D, 0, 4, 128, 128, 0, GL_RGBA,
GL_UNSIGNED_BYTE, pData);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
result := txtNumber;
end
procedure
var
length: glFLoat;
begin
vector[0] := vector[0] / length;
vector[1] := vector[1] / length;
vector[2] := vector[2] / length;
end
procedure
v1, v2: array
// Calculate The Vector From Point 1 To
Point 0
v1[0] := v[0][0] - v[1][0]; // Vector
1.x=Vertex[0].x-Vertex[1].x
v1[1] := v[0][1] - v[1][1]; // Vector
1.y=Vertex[0].y-Vertex[1].y
v1[2] := v[0][2] - v[1][2]; // Vector
1.z=Vertex[0].y-Vertex[1].z
// Calculate The Vector From Point 2 To
Point 1
v2[0] := v[1][0] - v[2][0]; // Vector
2.x=Vertex[0].x-Vertex[1].x
v2[1] := v[1][1] - v[2][1]; // Vector
2.y=Vertex[0].y-Vertex[1].y
v2[2] := v[1][2] - v[2][2]; // Vector
2.z=Vertex[0].z-Vertex[1].z
// Compute The Cross Product To Give Us A
Surface Normal
cross[0] := v1[1] * v2[2] - v1[2] * v2[1];
// Cross Product For Y - Z
cross[1] := v1[2] * v2[0] - v1[0] * v2[2];
// Cross Product For X - Z
cross[2] := v1[0] * v2[1] - v1[1] * v2[0];
// Cross Product For X - Y
ReduceToUnit(cross); // Normalize The
Vectors
end
procedure
Twists = 5;
MaterialColor: array
Specular: array
x, y, z: glFLoat;
phi, theta: Integer;
r, u, v: glFLoat;
begin
glLoadIdentity();
glPushMatrix(); // Push The Modelview
Matrix
glTranslatef(0, 0, -50); // Translate 50
Units Into The Screen
glRotatef(angle / 2.0, 1, 0, 0); //
Rotate By angle/2 On The X-Axis
glRotatef(angle / 3.0, 0, 1, 0); //
Rotate By angle/3 On The Y-Axis
glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, @MaterialColor);
glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, @specular);
r := 1.5; // Radius
glBegin(GL_QUADS); // Begin Drawing Quads
phi := 0;
while
theta := 0;
while
x := cos(u) * (2 + cos(v)) * r;
// Calculate x Position (1st Point)
y := sin(u) * (2 + cos(v)) * r;
// Calculate y Position (1st Point)
z := (u - (2 * pi) + sin(v)) * r;
// Calculate z Position (1st Point)
vertexes[0][0] := x;
// Set x Value Of First Vertex
vertexes[0][1] := y;
// Set y Value Of First Vertex
vertexes[0][2] := z;
// Set z Value Of First Vertex
v := (phi / 180 * pi);
// Calculate Angle Of Second Point ( 0 )
u := ((theta + 20) / 180 * pi);
// Calculate Angle Of Second Point ( 20 )
x := cos(u) * (2 + cos(v)) * r;
// Calculate x Position (2nd Point)
y := sin(u) * (2 + cos(v)) * r;
// Calculate y Positio
z := (u - (2 * pi) + sin(v)) * r;
// Calculate z Position (2nd Point)
vertexes[1][0] := x;
// Set x Value Of Second Vertex
vertexes[1][1] := y;
// Set y Value Of Second Vertex
vertexes[1][2] := z;
// Set z Value Of Second Vertex
v := (phi + 20) / 180 * pi;
// Calculate Angle Of Third Point ( 20 )
u := (theta + 20) / 180 * pi;
// Calculate Angle Of Third Point ( 20 )
x := cos(u) * (2 + cos(v)) * r;
// Calculate x Position (3rd Point)
y := sin(u) * (2 + cos(v)) * r;
// Calculate y Position (3rd Point)
z := (u - (2 * pi) + sin(v)) * r;
// Calculate z Position (3rd Point)
vertexes[2][0] := x;
// Set x Value Of Third Vertex
vertexes[2][1] := y;
// Set y Value Of Third Vertex
vertexes[2][2] := z;
// Set z Value Of Third Vertex
v := (phi + 20) / 180 * pi;
// Calculate Angle Of Fourth Point ( 20 )
u := theta / 180 * pi;
// Calculate Angle Of Fourth Point ( 0 )
x := cos(u) * (2 + cos(v)) * r;
// Calculate x Position (4th Point)
y := sin(u) * (2 + cos(v)) * r;
// Calculate y Position (4th Point)
z := (u - (2 * pi) + sin(v)) * r;
// Calculate z Position (4th Point)
vertexes[3][0] := x;
// Set x Value Of Fourth Vertex
vertexes[3][1] := y;
// Set y Value Of Fourth Vertex
vertexes[3][2] := z;
// Set z Value Of Fourth Vertex
calcNormal(vertexes, normal);
// Calculate The Quad Normal
glNormal3f(normal[0], normal[1], normal[2]);
// Set The Normal
// Render The
Quad
glVertex3f(vertexes[0][0], vertexes[0][1],
vertexes[0][2]);
glVertex3f(vertexes[1][0], vertexes[1][1],
vertexes[1][2]);
glVertex3f(vertexes[2][0], vertexes[2][1],
vertexes[2][2]);
glVertex3f(vertexes[3][0], vertexes[3][1],
vertexes[3][2]);
theta := theta + 20;
end
glEnd();
procedure
glMatrixMode(GL_PROJECTION);
procedure
glMatrixMode(GL_PROJECTION);
procedure
glViewport(0, 0, 128, 128);
// Copy Our ViewPort To The Blur Texture
(From 0,0 To 128,128... No Border)
glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 0, 0, 128, 128, 0);
glClearColor(0.0, 0.0, 0.5, 0.5); // Set
The Clear Color To Medium Blue
// Clear The Screen And Depth Buffer
glClear(GL_COLOR_BUFFER_BIT or
procedure
var
spost, alpha, alphainc: glFloat;
I: Integer;
begin
alpha := 0.2;
glEnable(GL_TEXTURE_2D);
alphainc := alpha / times; //
alphainc=0.2f / Times To Render Blur
glBegin(GL_QUADS); // Begin Drawing Quads
// Number Of Times To Render Blur
for
glColor4f(1.0, 1.0, 1.0, alpha);
glTexCoord2f(0 + spost, 0 + spost);
// Texture Coordinate ( 0, 0 )
glVertex2f(0, 480); // Second
Vertex ( 0, 480 )
glTexCoord2f(1 - spost, 0 + spost);
// Texture Coordinate ( 1, 0 )
glVertex2f(640, 480); //
Third Vertex ( 640, 480 )
glTexCoord2f(1 - spost, 1 - spost);
// Texture Coordinate ( 1, 1 )
glVertex2f(640, 0); // Fourth
Vertex ( 640, 0 )
// Gradually Increase spost
(Zooming Closer To Texture Center)
spost := spost + inc;
// Gradually Decrease alpha
(Gradually Fading Image Out)
alpha := alpha - alphainc;
end
glEnd();
ViewPerspective(); // Switch To A
Perspective View
glEnable(GL_DEPTH_TEST); // Enable Depth
Testing
glDisable(GL_TEXTURE_2D); // Disable 2D
Texture Mapping
glDisable(GL_BLEND); // Disable Blending
glBindTexture(GL_TEXTURE_2D, 0); //
Unbind The Blur Texture
end
procedure
angle := ElapsedTime / 5; // Update angle
Based On The Clock
end
procedure
glClearColor(0.0, 0.0, 0.0, 0.5);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
file
glEnable(GL_DEPTH_TEST); // Enable Depth
Buffer
glEnable(GL_TEXTURE_2D); // Enable
Texture Mapping
// Set The Ambient Light Model
glLightModelfv(GL_LIGHT_MODEL_AMBIENT, @LmodelAmbient);
// Set The Global Ambient Light Model
glLightModelfv(GL_LIGHT_MODEL_AMBIENT, @GlobalAmbient);
glLightfv(GL_LIGHT0, GL_POSITION, @light0Pos);
// Set The Lights Position
glLightfv(GL_LIGHT0, GL_AMBIENT, @light0Ambient);
// Set The Ambient Light
glLightfv(GL_LIGHT0, GL_DIFFUSE, @light0Diffuse);
// Set The Diffuse Light
// Set Up Specular Lighting
glLightfv(GL_LIGHT0, GL_SPECULAR, @light0Specular);
glEnable(GL_LIGHTING); // Enable Lighting
glEnable(GL_LIGHT0); // Enable Light0
BlurTexture := EmptyTexture(); // Create
Our Empty Texture
glShadeModel(GL_SMOOTH); // Select Smooth
Shading
glMateriali(GL_FRONT, GL_SHININESS, 128);
end
procedure
if
glMatrixMode(GL_MODELVIEW); // Return to
the modelview matrix
glLoadIdentity(); // Reset View
end
procedure
end
function
case
Result := 0;
end
end
procedure
if
ChangeDisplaySettings(devmode(nil
MessageBox(0, 'Release of rendering context failed!',
'Error',
MB_OK or
MessageBox(0, 'Release of device context failed!', 'Error',
MB_OK or
begin
MessageBox(0, 'Unable to destroy window!', 'Error', MB_OK
or
h_Wnd := 0;
end
MessageBox(0, 'Unable to unregister window class!', 'Error',
MB_OK or
end
function
wndClass: TWndClass;
h_Instance := GetModuleHandle(nil
with
style := CS_HREDRAW or
if
MessageBox(0, 'Failed to register the window class!',
'Error',
MB_OK or
end
ZeroMemory(@dmScreenSettings, SizeOf(dmScreenSettings));
with
DISP_CHANGE_FAILED) then
MB_OK or
dwStyle := WS_POPUP or
else
begin
dwStyle := WS_OVERLAPPEDWINDOW or
glKillWnd(Fullscreen);
Result := False
glKillWnd(Fullscreen);
MessageBox(0, 'Unable to get a device context!', 'Error',
MB_OK or
glKillWnd(Fullscreen);
MessageBox(0, 'Unable to find a suitable pixel format',
'Error',
MB_OK or
glKillWnd(Fullscreen);
MessageBox(0, 'Unable to set the pixel format', 'Error',
MB_OK or
glKillWnd(Fullscreen);
MessageBox(0, 'Unable to create an OpenGL rendering context',
'Error', MB_OK or
glKillWnd(Fullscreen);
MessageBox(0, 'Unable to activate OpenGL rendering context',
'Error',
MB_OK or
// Ensure the OpenGL window is resized
properly
glResizeWnd(Width, Height);
glInit();
Result := True
function
msg: TMsg;
finished: Boolean;
DemoStart, LastTime: DWord;
begin
finished := False
Result := 0;
Exit;
end
DemoStart := GetTickCount();
// Main message loop:
while
LastTime := ElapsedTime;
ElapsedTime := GetTickCount() - DemoStart;
// Calculate Elapsed Time
// Average it out
for smoother movement
ElapsedTime := (LastTime + ElapsedTime) div
glDraw();
if
glKillWnd(FALSE
begin
WinMain(hInstance, hPrevInst, CmdLine, CmdShow);
end