KONKÁV POLYGON IN DELPHI

Top  Previous  Next

Tökéletesen működik OpenGl1 unittal.

 

clip0016

 

unit Unit1;

 

interface

 

uses

Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,

ComCtrls, ExtCtrls, AL_GL, OpenGL1;

 

type

TGLdouble = GLdouble;

TGLVectord3  = array[0..2] of GLdouble;

TVector3d = TGLVectord3;

 

// GLU types

TGLUNurbs = record

end;

TGLUQuadric = record

end;

TGLUTesselator = record

end;

PGLUNurbs = ^TGLUNurbs;

PGLUQuadric = ^TGLUQuadric;

PGLUTesselator = ^TGLUTesselator;

// backwards compatibility

TGLUNurbsObj = TGLUNurbs;

TGLUQuadricObj = TGLUQuadric;

TGLUTesselatorObj = TGLUTesselator;

TGLUTriangulatorObj = TGLUTesselator;

PGLUNurbsObj = PGLUNurbs;

PGLUQuadricObj = PGLUQuadric;

PGLUTesselatorObj = PGLUTesselator;

PGLUTriangulatorObj = PGLUTesselator;

 

TGLPoint = record

  x,y,z : double;

end;

 

TForm1 = class(TForm)

  AL_OpenGL1: TAL_OpenGL;

  Panel1: TPanel;

  StatusBar1: TStatusBar;

  procedure AL_OpenGL1Paint(Sender: TObject);

private

  { Private declarations }

public

  { Public declarations }

end;

 

var

Form1: TForm1;

 

implementation

 

{$R *.DFM}

 

procedure PolygonTess( x, y, AngleRotate: single; n: array of TGLPoint );

var

i:integer;

vvv : array of TVector3d;

tglutessobj : GLUtesselator;

begin

glPushMatrix();

tglutessobj := glunewtess();

gluTessCallback( tglutessobj, GLU_TESS_BEGIN, @glBegin );

gluTessCallback( tglutessobj, GLU_TESS_VERTEX, @glVertex3dv );

gluTessCallback( tglutessobj, GLU_TESS_END, @glEnd );

 

SetLength( vvv, Length( n ) );

 

glTranslated(x,y,0);

glRotatef(AngleRotate, 0,0,1);

 

glNewList(1, GL_COMPILE);

 

gluTessBeginPolygon ( tglutessobj );

For i:=0 to High( n )  do

 begin

  vvv[ i ][ 0 ] := n[ i ].x;

  vvv[ i ][ 1 ] := n[ i ].y;

  vvv[ i ][ 2 ] := 0;

  gluTessVertex(tglutessobj, @vvv[ i ], @vvv[ i ] );

 end ;

gluTessEndPolygon( tglutessobj );

glEndList;

 

glCallList( 1 );

glDeleteLists( 1, 1 );

 

gluDeleteTess( tglutessobj );

SetLength( vvv, 0 );

 

glPopMatrix();

end;

 

procedure TForm1.AL_OpenGL1Paint(Sender: TObject);

Var   pArr : array[0..3] of TGLPoint;

    i: integer;

Const arr  : array[0..3,0..2] of single = ( (-3,3,0),(0,2,0),(3,3,0),(0,0,0) );

begin

For i:=0 to 3 do begin

    pArr[i].x := arr[i,0];

    pArr[i].y := arr[i,1];

    pArr[i].z := arr[i,2];

end;

glColor3f(0,1,0);

PolygonTess(2,-4,35,pArr);

end;

 

end.