0% found this document useful (0 votes)
40 views4 pages

Додаток №1

The document defines a Delphi unit for drawing 2D graphics using OpenGL. It initializes an OpenGL context, draws grid lines and axes on the form's paint event, and plots a sine wave function.

Uploaded by

Pro STOY
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
40 views4 pages

Додаток №1

The document defines a Delphi unit for drawing 2D graphics using OpenGL. It initializes an OpenGL context, draws grid lines and axes on the form's paint event, and plots a sine wave function.

Uploaded by

Pro STOY
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

unit Unit1;

interface

uses

Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,

Vcl.Controls, Vcl.Forms, Vcl.Dialogs, StdCtrls, ExtCtrls, opengl;

type

TForm1 = class(TForm)

procedure FormCreate(Sender: TObject);

procedure FormDestroy(Sender: TObject);

procedure The_FormPaint(Sender: TObject);

private

{ Private declarations }

public

{ Public declarations }

hrc: HGLRC;

end;

var

Form1: TForm1;

x:double ;

y:double;

implementation

{$R *.dfm}

procedure SetDCPixelFOrmat (hdc: HDC);

var pfd: TPixelFormatDescriptor;

nPixelFormat: integer;

begin

FillChar (pfd,SizeOf(pfd), 0);

nPixelFormat:=ChoosePixelFormat(hdc, @pfd);

SetPixelFormat(hdc, nPixelFormat, @pfd);


end;

procedure TForm1.FormCreate(Sender: TObject);

begin

SetDCPixelFormat(Canvas.Handle);

hrc:=wglCreateContext(Canvas.Handle);

end;

procedure TForm1.The_FormPaint (Sender: TObject);

begin

wglMakeCurrent(Canvas.Handle, hrc);

glColor3d(0, 2, 1);

glLineWidth(1);

glEnable(GL_LINE_STIPPLE);

glLineStipple(2, $CCCC);

glBegin(GL_LINES);

{горизонтальна сітка}

glVertex2d(1, 0.2);

glVertex2d(-1, 0.2);

glVertex2d(1, -0.2);

glVertex2d(-1, -0.2);

glVertex2d(1, 0.4);

glVertex2d(-1, 0.4);

glVertex2d(1, -0.4);

glVertex2d(-1, -0.4);

glVertex2d(1, 0.6);

glVertex2d(-1, 0.6);

glVertex2d(1, -0.6);

glVertex2d(-1, -0.6);

glVertex2d(1, 0.8);

glVertex2d(-1, 0.8);

glVertex2d(1, -0.8);

glVertex2d(-1, -0.8);

glVertex2d(1, 0.99);

glVertex2d(-1, 0.99);

glVertex2d(1, -0.99);

glVertex2d(-1, -0.99);

{}
glVertex2d(0.2, 1);

glVertex2d(0.2, -1);

glVertex2d(-0.2, 1);

glVertex2d(-0.2, -1);

glVertex2d(0.4, 1);

glVertex2d(0.4, -1);

glVertex2d(-0.4, 1);

glVertex2d(-0.4, -1);

glVertex2d(0.6, 1);

glVertex2d(0.6, -1);

glVertex2d(-0.6, 1);

glVertex2d(-0.6, -1);

glVertex2d(0.8, 1);

glVertex2d(0.8, -1);

glVertex2d(-0.8, 1);

glVertex2d(-0.8, -1);

glVertex2d(0.99, 1);

glVertex2d(0.99, -1);

glVertex2d(-0.99, 1);

glVertex2d(-0.99, -1);

glEnd;

{стрілки}

glColor3d(1, 1, 1);

glLineWidth(1);

glDisable(GL_LINE_STIPPLE);

glBegin(GL_LINES);

glVertex2d(1, 0);

glVertex2d(0.8, 0.1);

glVertex2d(1, 0);

glVertex2d(0.8, -0.1);

glVertex2d(0, 1);

glVertex2d(-0.07, 0.67);

glVertex2d(0, 1);

glVertex2d(0.07, 0.67);
glEnd;

{ось кординат}

glColor3d(1, 1, 1);

glBegin(GL_LINES);

glVertex2d(0, -1);

glVertex2d(0, 1);

glVertex2d(-1, -0);

glVertex2d(1, 0);

glEnd;

glColor3d(1, 0, 0);

glLineWidth (2);

glBegin(GL_LINE_STRIP);

x:=-1;

repeat

y:=exp(ln(10)*(abs (x)-1))*sin(15*x);

glVertex2d(x, y);

x:=x+0.01;

until x>=1;

glEnd;

glpopMatrix;

wglMakeCurrent(0, 0);

end;

procedure TForm1.FormDestroy(Sender: TObject);

begin

wglDeleteContext(hrc);

end;

end.

You might also like