.


:




:

































 

 

 

 


OpenGL




OpenGL , . OpenGL 32- . Windows. , , OpenGL, , .

OpenGL , , . . OpenGL , DirectX.

OpenGL Silicon Graphics, Inc. (SGI) . - Windows API. - .

, OpenGL , .

: opengl32.dll, glu32.dll, glaux.dll. . , glaux.dll, . OpenGL , , .. . (Installable Client Diver, ICD) (Mini-Client Driver, MCD).

OpenGL. . . , , .

, OpenGL:

, , , , , .

, , .

, .

.

.

NURBS.

.

.

.

.

.

.

Windows.

 

OpenGL , , .. .

. OpenGL . , , , .

OpenGL , , .

, glColor 16 . [15] :

rtype CommandName [1 2 3 4][b s i f d ub us ui][v] (atype arg )

, , .

CommandName , , glColor
[1 2 3 4] ,
[b s i f d ub us ui] ,
[v] , .

 

OpenGL.

OpenGL
b GLbyte char
s GLshort short
i GLint int
f GLfloat float
d GLdouble double
ub GLubyte unsigned byte
us GLushort unsigned short
ui GLuint unsigned int

 

glColor:

glColor4f (0.8,0.5,0.4,1.0);

glColor3i (200,109,38);

 

FormCreate, OpenGL. , OpenGL . OpenGL Windows . OpenGL .

procedure TfrmGL.FormCreate(Sender: TObject);

var

pfd: TPixelFormatDescriptor;

nPixelFormat: integer;

begin

hdc:= GetDC (Panel1.Handle);

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

pfd.nSize:= SizeOf(pfd);

pfd.dwFlags:=PFD_DOUBLEBUFFER;

nPixelFormat:= ChoosePixelFormat(hdc,@pfd);

if nPixelFormat = 0 then

begin

ShowMessage( OpenGL);

Halt;

end;

 

SetPixelFormat(hdc,nPixelFormat,@pfd);

RContext:= wglCreateContext(hdc);

WglMakeCurrent(hrc,RContext);

 

glClearColor (0.0, 0.0, 0.0,1.0); //

glEnable(GL_DEPTH_TEST);

SphereObj:=gluNewQuadric;

CylObj:=gluNewQuadric;

LightObj:=gluNewQuadric;

end;

GetDC. . , , ObjectPascal TPixelFormatDescriptor. :

typedef struct tagPIXELFORMATDESCRIPTOR { // pfd

WORD nSize;//

WORD nVersion;// 1.

DWORD dwFlags;// , : PFD_SUPPORT_GDI

BYTE iPixelType;// : PFD_TYPE_RGBA //PFD_TYPE_COLORINDEX

BYTE cColorBits;// , Alpha

BYTE cRedBits;//

BYTE cRedShift;

BYTE cGreenBits; //

BYTE cGreenShift;

BYTE cBlueBits; //

BYTE cBlueShift;

BYTE cAlphaBits;

BYTE cAlphaShift;

BYTE cAccumBits;

BYTE cAccumRedBits;

BYTE cAccumGreenBits;

BYTE cAccumBlueBits;

BYTE cAccumAlphaBits;

BYTE cDepthBits;// z-

BYTE cStencilBits;

BYTE cAuxBuffers;

BYTE iLayerType;// PFD_MAIN_PLANE

BYTE bReserved;

DWORD dwLayerMask;

DWORD dwVisibleMask;

DWORD dwDamageMask;

} PIXELFORMATDESCRIPTOR;

 

OpenGL. , ChoosePixelFormat(hdc,@pfd) .

, , , , ChoosePixelFormat, pfd.nSize . : pfd.dwFlags:=PFD_DOUBLEBUFFER. , . .

:

SetPixelFormat(hdc, nPixelFormat ,@pfd).

, OpenGL:

RContext:= wglCreateContext(hdc);

:

wglMakeCurrent(hdc,RContext).

OpenGL :

wglMakeCurrent(0, 0),

:

wglDeleteContext(RContext).

, wglMakeCurrent , . :

BOOL wglMakeCurrent(

HDC hdc, //

HGLRC hglrc // OpenGL

);

, . True.

FormDestroy:

procedure TfrmGL.FormDestroy(Sender: TObject);

begin

wglMakeCurrent(0, 0);

wglDeleteContext(RContext);

ReleaseDC (Handle, RContext);

DeleteDC (hdc);

end;

OpenGL , .

. , FormPaint.

 

procedure TfrmGL.FormPaint(Sender: TObject);

var

ps: TPaintStruct;

begin

try

BeginPaint (Panel1.Handle, ps); //

//

glClear (GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT);

SetUpCommons;

DrawScene;

glFlush;

SwapBuffers(hrc);

EndPaint (Panel1.Handle, ps);

except

end;

end;

 

try..except, BeginPaint EndPaint. BeginPaint .

OpenGL:

glFlush;

SwapBuffers(hrc);

 

glFlush OpenGL OpenGL , , . , .

SwapBuffers . , HDC, Windows, . true .

:

glClear (GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT);

SetUpCommons;

DrawScene;

glClear OpenGL. OpenGL , . , : . , , , .. z, . glClear, , GL_COLOR_BUFFER_BIT, - GL_DEPTH_BUFFER_BIT. OpenGL , .

OpenGL. SetUpCommons . DrawScene .

SetUpCommons:

glMatrixMode(GL_PROJECTION);

glLoadIdentity;

 

Case RGProj.ItemIndex of

0: glOrtho (-LC,LC,-Panel1.height/Panel1.width*LC,

Panel1.height/Panel1.width*LC, 3, 1000);

 

1: glFrustum (-1,1,-Panel1.height/Panel1.width,

Panel1.height/Panel1.width, 3, 1000);

end;//case

 

procedure TfrmGL.InitViewPort;

begin

glViewport(0, 0, Panel1.Width, Panel1.Height);

glMatrixMode(GL_PROJECTION);

glLoadIdentity;

glFrustum (-1,1,-Panel1.height/Panel1.width,

Panel1.height/Panel1.width, 3, 1000);

end;

 

glViewport . Windows, . - :

void glViewport(

GLint x,

GLint y,

GLsizei width,

GLsizei height

);

x y . , (x,y)=(0,0). width height , . Windows .

 

glMatrixMode(GL_PROJECTION) . OpenGL , , . , , , . . OpenGL . .

, . , , , . , glLoadIdentity, .

. glFrustum:

 

void glFrustum(

GLdouble left,
GLdouble right,
Gldouble bottom,
GLdouble top,
GLdouble near,
GLdouble far
);

 

: left right near . bottom top, far. , . , OpenGL Windows.

glu32.dll gluPerspective, .

 

 






:


: 2016-10-30; !; : 595 |


:

:

.
==> ...

1373 - | 1214 -


© 2015-2024 lektsii.org - -

: 0.062 .