Files |  Tutorials |  Articles |  Links |  Home |  Team |  Forum |  Wiki |  Impressum

Aktuelle Zeit: Di Jul 15, 2025 13:28

Foren-Übersicht » English » English Programming Forum
Unbeantwortete Themen | Aktive Themen



Ein neues Thema erstellen Auf das Thema antworten  [ 3 Beiträge ] 
Autor Nachricht
 Betreff des Beitrags: glu tesselate a star
BeitragVerfasst: Sa Apr 05, 2008 17:40 
Offline
DGL Member
Benutzeravatar

Registriert: Di Jul 01, 2003 18:59
Beiträge: 887
Wohnort: (The Netherlands)
Programmiersprache: fpc/delphi/java/c#
I am trying to tesselate a star using glu funtions. Only for one point the colors seem to be wrong. i.e. it turns out to be black.
I am trying to follow this tutorial: http://www.songho.ca/opengl/gl_tessellation.html
Thanks for your answers in advance.

Code:
  1.  
  2. unit OpenGLTemplateForm;
  3.  
  4. interface
  5.  
  6. uses
  7.  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  8.   StdCtrls, ExtCtrls, ComCtrls, DglOpenGL;
  9.  
  10. type
  11.   TDGLForm = class(TForm)
  12.     procedure FormKeyPress(Sender: TObject; var Key: Char);
  13.     procedure FormCreate(Sender: TObject);
  14.     procedure FormDestroy(Sender: TObject);
  15.   private
  16.     { Private declarations }
  17.   public
  18.     { Public declarations }
  19.   end;
  20.  
  21.   TOpenGLRender = class(TThread)
  22.   private
  23.     DC:HDC;
  24.     RC:HGLRC;
  25.     angle: integer;
  26.     fHandle: cardinal;
  27.     fOptions: TRCOptions;
  28.     fPixelDepth: byte;
  29.     fDepthBuffer: byte;
  30.   public
  31.     destructor Destroy; override;
  32.     procedure Init;
  33.     procedure Draw;
  34.     procedure Stop;
  35.     procedure Execute; override;
  36.     property Handle: cardinal read fHandle write fHandle;
  37.     property Options: TRCOptions read fOptions write fOptions;
  38.     property PixelDepth: byte read fPixelDepth write fPixelDepth;
  39.     property DepthBuffer: byte read fDepthBuffer write fDepthBuffer;
  40.   end;
  41.  
  42. var
  43.   DGLForm: TDGLForm;
  44.   OpenGLRender: TOpenGLRender;
  45.  
  46. implementation
  47.  
  48. {$R *.DFM}
  49.  
  50. type
  51.      PGLarrayd3 = ^TGLArrayd3;
  52.      TGLArrayd4 = array[0..3] of GLDouble;
  53.      PGLArrayd4 = ^TGLArrayd4;
  54.      TGLArrayd6 = array[0..5] of GLDouble;
  55.      PGLArrayd6 = ^TGLArrayd6;
  56.      TGLArrayvertex4 = array[0..3] of TGLArrayd6;
  57.      PGLArrayvertex4 = ^TGLArrayvertex4;
  58.  
  59. function getNormal(p1,p2,p3:TGLArrayf3):TGLArrayf3;
  60. var a,b:TGLArrayf3;
  61. begin
  62.  a[0]:=p2[0]-p1[0]; a[1]:=p2[1]-p1[1]; a[2]:=p2[2]-p1[2];
  63.  b[0]:=p3[0]-p1[0]; b[1]:=p3[1]-p1[1]; b[2]:=p3[2]-p1[2];
  64.  result[0]:=a[1]*b[2]-a[2]*b[1];
  65.  result[1]:=a[2]*b[0]-a[0]*b[2];
  66.  result[2]:=a[0]*b[1]-a[1]*b[0];
  67. end;
  68.  
  69. //TOpenGLRender
  70.  
  71. destructor TOpenGLRender.Destroy;
  72. begin
  73.   inherited;
  74. end;
  75.  
  76. procedure TOpenGLRender.Execute;
  77. begin
  78.   Init;
  79.   while not terminated do
  80.   begin
  81.     Draw;
  82.     sleep(1);
  83.   end;
  84.   Stop;
  85. end;
  86.  
  87. procedure TOpenGLRender.Init;
  88. const
  89.   light0_position:TGLArrayf4=( -8.0, 8.0, -16.0, 0.0);
  90.   ambient:  TGLArrayf4=( 0.3, 0.3, 0.3, 0.3);
  91. begin
  92.  
  93.   InitOpenGL;
  94.  
  95.   DC := GetDC(fHandle);
  96.   // Create RenderContext (32 Bit PixelDepth, 24 Bit DepthBuffer, Doublebuffering)
  97.   RC := CreateRenderingContext(DC, fOptions, fPixelDepth, fDepthBuffer, 0, 0, 0, 0);
  98.   // Activate RenderContext
  99.   ActivateRenderingContext(DC, RC);
  100.  
  101.   // set viewing projection
  102.   glMatrixMode(GL_PROJECTION);
  103.   glFrustum(-0.1, 0.1, -0.1, 0.1, 0.3, 25.0);
  104.  
  105.   // position viewer
  106.   glMatrixMode(GL_MODELVIEW);
  107.  
  108.   // Active DepthBuffer
  109.   glEnable(GL_DEPTH_TEST);
  110.   glDepthFunc(GL_LESS);
  111.  
  112.   glShadeModel(GL_SMOOTH);                    // shading mathod: GL_SMOOTH or GL_FLAT
  113.  
  114.   // track material ambient and diffuse from surface color, call it before glEnable(GL_COLOR_MATERIAL)
  115.   glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
  116.   glEnable(GL_COLOR_MATERIAL);
  117.  
  118.   // Set lighting
  119.   glEnable(GL_LIGHTING);
  120.   glLightfv(GL_LIGHT0, GL_POSITION, @light0_position);
  121.   glLightfv(GL_LIGHT0, GL_AMBIENT, @ambient);
  122.   glEnable(GL_LIGHT0);
  123.  
  124.   // Set clear background color
  125.   glClearColor(0,0,0,0);
  126. end;
  127.  
  128. procedure tessBeginCB(which: GLenum); stdcall;
  129. begin
  130.     glBegin(which);
  131. end;
  132.  
  133. procedure tessEndCB(); stdcall;
  134. begin
  135.     glEnd();
  136. end;
  137.  
  138. procedure tessErrorCB(errorCode: GLenum); stdcall;
  139. var
  140.   errorStr: string;
  141. begin
  142.     errorStr := gluErrorString(errorCode);
  143. end;
  144.  
  145. procedure tessVertexCB(data: PGLArrayd6); stdcall;
  146. begin
  147.     glColor3d(data[3], data[4], data[5]);
  148.     glVertex3d( data[0], data[1], data[2] );
  149. end;
  150.  
  151. var
  152. vertices: array[0..64] of TGLArrayd6;
  153. vertexIndex: integer = 0;
  154.  
  155. procedure tessCombineCB(newVertex : PGLArrayd6; neighborVertex : Pointer;
  156.                       neighborWeight : PGLArrayd4; var outData : Pointer); stdcall;
  157. type
  158.   PGLArrayd3= ^TGLArrayd3;
  159. var
  160.   vertice: PGLarrayd3;
  161.   test: pointer;
  162. begin
  163.  
  164.     vertices[vertexIndex][0] := newVertex[0];
  165.     vertices[vertexIndex][1] := newVertex[1];
  166.     vertices[vertexIndex][2] := newVertex[2];
  167.  
  168.     vertices[vertexIndex][3] := neighborWeight[0] * PGLArrayvertex4(neighborVertex)[0][3] +   // red
  169.                                 neighborWeight[1] * PGLArrayvertex4(neighborVertex)[1][3] +
  170.                                 neighborWeight[2] * PGLArrayvertex4(neighborVertex)[2][3] +
  171.                                 neighborWeight[3] * PGLArrayvertex4(neighborVertex)[3][3];
  172.     vertices[vertexIndex][4] := neighborWeight[0] * PGLArrayvertex4(neighborVertex)[0][4] +   // green
  173.                                 neighborWeight[1] * PGLArrayvertex4(neighborVertex)[1][4] +
  174.                                 neighborWeight[2] * PGLArrayvertex4(neighborVertex)[2][4] +
  175.                                 neighborWeight[3] * PGLArrayvertex4(neighborVertex)[3][4];
  176.     vertices[vertexIndex][5] := neighborWeight[0] * PGLArrayvertex4(neighborVertex)[0][5] +   // blue
  177.                                 neighborWeight[1] * PGLArrayvertex4(neighborVertex)[1][5] +
  178.                                 neighborWeight[2] * PGLArrayvertex4(neighborVertex)[2][5] +
  179.                                 neighborWeight[3] * PGLArrayvertex4(neighborVertex)[3][5];
  180.  
  181.     // return output data (vertex coords and others)
  182.     outData := @vertices[vertexindex];
  183.  
  184.     vertexIndex := vertexIndex + 1;  // increase index for next vertex
  185. end;
  186.  
  187. procedure TOpenGLRender.Draw;
  188. var
  189.   test: TGLArrayd3;
  190.   star: array[0..4] of TGLArrayd6;
  191.   tess: pointer;
  192.  
  193. begin
  194.   vertexindex:=0;
  195.   angle:=180;//angle+1;
  196.  
  197.   glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT);
  198.   glLoadIdentity;
  199.   glTranslatef(0.0, 0.0, -12.0);
  200.   glRotatef(angle, 0.0, 1.0, 0.0);
  201.  
  202.   star[0][0] := 0.0;
  203.   star[0][1] := 3.0;
  204.   star[0][2] := 0.0;
  205.  
  206.   star[0][3] := 1;
  207.   star[0][4] := 0;
  208.   star[0][5] := 0;
  209.  
  210.   star[1][0] := -1.0;
  211.   star[1][1] := 0.0;
  212.   star[1][2] := 0.0;
  213.  
  214.   star[1][3] := 0;
  215.   star[1][4] := 1;
  216.   star[1][5] := 0;
  217.  
  218.   star[2][0] := 1.6;
  219.   star[2][1] := 1.9;
  220.   star[2][2] := 0.0;
  221.  
  222.   star[2][3] := 1;
  223.   star[2][4] := 0;
  224.   star[2][5] := 1;
  225.  
  226.   star[3][0] := -1.6;
  227.   star[3][1] := 1.9;
  228.   star[3][2] := 0.0;
  229.  
  230.   star[3][3] := 1;
  231.   star[3][4] := 1;
  232.   star[3][5] := 0;
  233.  
  234.   star[4][0] := 1.0;
  235.   star[4][1] := 0.0;
  236.   star[4][2] := 0.0;
  237.  
  238.   star[4][3] := 0;
  239.   star[4][4] := 0;
  240.   star[4][5] := 1;
  241.  
  242.   tess := gluNewTess();
  243.  
  244.   gluTessCallback(tess, GLU_TESS_BEGIN, @tessBeginCB);
  245.   gluTessCallback(tess, GLU_TESS_END, @tessEndCB);
  246.   gluTessCallback(tess, GLU_TESS_ERROR, @tessErrorCB);
  247.   gluTessCallback(tess, GLU_TESS_VERTEX, @tessVertexCB);
  248.   gluTessCallback(tess, GLU_TESS_COMBINE, @tessCombineCB);
  249.  
  250.  
  251.   gluTessProperty(tess, GLU_TESS_WINDING_RULE, GLU_TESS_WINDING_NONZERO);
  252.  
  253.   gluTessBeginPolygon(tess, 0);                   // with NULL data
  254.     gluTessBeginContour(tess);
  255.  
  256.       test[0] := star[0][0];
  257.       test[1] := star[0][1];
  258.       test[2] := star[0][2];
  259.  
  260.       gluTessVertex(tess, test, @star[0]);
  261.  
  262.       test[0] := star[1][0];
  263.       test[1] := star[1][1];
  264.       test[2] := star[1][2];
  265.  
  266.       gluTessVertex(tess, test, @star[1]);
  267.  
  268.       test[0] := star[2][0];
  269.       test[1] := star[2][1];
  270.       test[2] := star[2][2];
  271.  
  272.       gluTessVertex(tess, test, @star[2]);
  273.  
  274.       test[0] := star[3][0];
  275.       test[1] := star[3][1];
  276.       test[2] := star[3][2];
  277.  
  278.       gluTessVertex(tess, test, @star[3]);
  279.  
  280.       test[0] := star[4][0];
  281.       test[1] := star[4][1];
  282.       test[2] := star[4][2];
  283.  
  284.       gluTessVertex(tess, test, @star[4]);
  285.  
  286.     gluTessEndContour(tess);
  287.   gluTessEndPolygon(tess);
  288.  
  289.   gluDeleteTess(tess);        // delete after tessellation
  290.  
  291.   SwapBuffers(DC);
  292. end;
  293.  
  294. procedure TOpenGLRender.Stop;
  295. begin
  296.   DeactivateRenderingContext; // Deactivate RenderContext
  297.   wglDeleteContext(RC); //Delete RenderContext
  298.   ReleaseDC(Handle, DC);
  299. end;
  300.  
  301. //TDGLForm
  302.  
  303. procedure TDGLForm.FormCreate(Sender: TObject);
  304. begin
  305.   DecimalSeparator:='.'; //always use . as decimal seperator
  306.   OpenGLRender := TOpenGLRender.Create(true);
  307.   OpenGLRender.Handle := Handle;
  308.   OpenGLRender.Options := [opDoubleBuffered];
  309.   OpenGLRender.PixelDepth := 32;
  310.   OpenGLRender.DepthBuffer := 24;
  311.   OpenGLRender.Resume;
  312. end;
  313.  
  314. procedure TDGLForm.FormDestroy(Sender: TObject);
  315. begin
  316.   OpenGLRender.Suspend;
  317.   OpenGLRender.Free;
  318. end;
  319.  
  320. procedure TDGLForm.FormKeyPress(Sender: TObject; var Key: Char);
  321. begin
  322.   case Key of
  323.     #27 : Close;
  324.   end;
  325. end;
  326.  
  327. end.
  328.  

_________________
http://3das.noeska.com - create adventure games without programming


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags:
BeitragVerfasst: So Apr 06, 2008 12:43 
Offline
DGL Member
Benutzeravatar

Registriert: Di Jul 01, 2003 18:59
Beiträge: 887
Wohnort: (The Netherlands)
Programmiersprache: fpc/delphi/java/c#
Solved

The neighborweight needed to be an array 0..3 of PGLFloat.
The neighborvertex needed to be an array of 0..3 of an array 0..5 of PGLDouble. Here i made the mistake to not address the second array as an pointer type and thus getting wrong values.

Code:
  1.  
  2. type
  3.      TGLArrayd6 = array[0..5] of GLDouble;
  4.      PGLArrayd6 = ^TGLArrayd6;
  5.      TGLArrayvertex4 = array[0..3] of PGLArrayd6;
  6.      PGLArrayvertex4 = ^TGLArrayvertex4;
  7.      PGLArrayf4 = ^TGLArrayf4;
  8.  
  9. procedure tessCombineCB(newVertex : PGLArrayd6; neighborVertex : Pointer;
  10.                       neighborWeight : Pointer; var outData : Pointer); stdcall;
  11. begin
  12.  
  13.     vertices[vertexIndex][0] := newVertex^[0];
  14.     vertices[vertexIndex][1] := newVertex^[1];
  15.     vertices[vertexIndex][2] := newVertex^[2];
  16.  
  17.     vertices[vertexIndex][3] := PGLArrayf4(neighborWeight)^[0] *
  18.                                 PGLArrayvertex4(neighborVertex)^[0][3] +   // red
  19.                                 PGLArrayf4(neighborWeight)^[1] *
  20.                                 PGLArrayvertex4(neighborVertex)^[1][3] +
  21.                                 PGLArrayf4(neighborWeight)^[2] *
  22.                                 PGLArrayvertex4(neighborVertex)^[2][3] +
  23.                                 PGLArrayf4(neighborWeight)^[3] *
  24.                                 PGLArrayvertex4(neighborVertex)^[3][3];
  25.     vertices[vertexIndex][4] := PGLArrayf4(neighborWeight)^[0] *
  26.                                 PGLArrayvertex4(neighborVertex)^[0][4] +   // green
  27.                                 PGLArrayf4(neighborWeight)^[1] *
  28.                                 PGLArrayvertex4(neighborVertex)^[1][4] +
  29.                                 PGLArrayf4(neighborWeight)^[2] *
  30.                                 PGLArrayvertex4(neighborVertex)^[2][4] +
  31.                                 PGLArrayf4(neighborWeight)^[3] *
  32.                                 PGLArrayvertex4(neighborVertex)^[3][4];
  33.     vertices[vertexIndex][5] := PGLArrayf4(neighborWeight)^[0] *
  34.                                 PGLArrayvertex4(neighborVertex)^[0][5] +   // blue
  35.                                 PGLArrayf4(neighborWeight)^[1] *
  36.                                 PGLArrayvertex4(neighborVertex)^[1][5] +
  37.                                 PGLArrayf4(neighborWeight)^[2] *
  38.                                 PGLArrayvertex4(neighborVertex)^[2][5] +
  39.                                 PGLArrayf4(neighborWeight)^[3] *
  40.                                 PGLArrayvertex4(neighborVertex)^[3][5];
  41.     //vertices[vertexIndex][5] := vertexIndex;
  42.  
  43.  
  44.     // return output data (vertex coords and others)
  45.     outData:= @vertices[vertexindex];
  46.  
  47.     vertexIndex := vertexIndex + 1;  // increase index for next vertex
  48. end;
  49.  

_________________
http://3das.noeska.com - create adventure games without programming


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags:
BeitragVerfasst: Fr Aug 22, 2008 16:34 
Offline
DGL Member
Benutzeravatar

Registriert: Di Jul 01, 2003 18:59
Beiträge: 887
Wohnort: (The Netherlands)
Programmiersprache: fpc/delphi/java/c#
My TPolygon Class: (MPL license)

Code:
  1.  
  2. unit Polygon;
  3.  
  4. interface
  5.  
  6. uses DGLOpenGL;
  7.  
  8. type
  9. TPoint = packed record
  10.   x: single;
  11.   y: single;
  12.   z: single;
  13.   r: single;
  14.   g: single;
  15.   b: single;
  16.   a: single;
  17. end;
  18.  
  19. TPolygon = class
  20. private
  21.   FPoints: array of TPoint; //polygon point
  22.   FVertex: array of TPoint; //triangulated data
  23.   FColor: TPoint;
  24.   FCount: integer;
  25.   FVertexCount: integer;
  26.   FTesselated: boolean;
  27.   procedure SetPoint(I: integer; Value: TPoint);
  28.   procedure AddVertex(x: single; y: single; z: single; r: single; g: single; b: single; a:single);
  29.   function GetPoint(I: integer): TPoint;
  30.   function GetCount(): integer;
  31.   procedure tessBegin(which: GLenum);
  32.   procedure tessEnd();
  33.   procedure tessVertex(x: single; y: single; z: single; r: single; g: single; b: single; a:single);
  34. public
  35.   constructor Create();
  36.   destructor Destroy();
  37.   procedure SetColor(R: single; G: single; B: single;A: single);
  38.   procedure Add(X: single; Y: single); overload;
  39.   procedure Add(X: single; Y: single; Z: single); overload;
  40.   procedure Add(X: single; Y: single; Z: single; R: single; G: single; B: single; A: single); overload;
  41.   procedure Render();
  42.   procedure Tesselate();
  43.   property Points[I: integer]: TPoint read GetPoint write SetPoint;
  44.   property Count: integer read GetCount;
  45. end;
  46.  
  47. implementation
  48.  
  49. type
  50.      TGLArrayd6 = array[0..5] of GLDouble;
  51.      PGLArrayd6 = ^TGLArrayd6;
  52.      TGLArrayvertex4 = array[0..3] of PGLArrayd6;
  53.      PGLArrayvertex4 = ^TGLArrayvertex4;
  54.      PGLArrayf4 = ^TGLArrayf4;
  55.  
  56. threadvar
  57.   PolygonClass: TPolygon;
  58.  
  59. procedure TPolygon.SetColor(R: single; G: single; B: single;A: single);
  60. begin
  61.   FColor.r := R;
  62.   FColor.g := G;
  63.   FColor.b := B;
  64.   FColor.a := A;
  65. end;
  66.  
  67. procedure TPolygon.tessBegin(which: GLenum);
  68. begin
  69.     glBegin(which);
  70. end;
  71.  
  72. procedure TPolygon.tessEnd();
  73. begin
  74.     glEnd();
  75. end;
  76.  
  77. procedure TPolygon.tessVertex(x: single; y: single; z: single; r: single; g: single; b: single; a:single);
  78. begin
  79.     glcolor3f(r,g,b);
  80.     glVertex3f(x,y,z);
  81. end;
  82.  
  83. procedure TPolygon.AddVertex(x: single; y: single; z: single; r: single; g: single; b: single; a:single);
  84. begin
  85.     FVertexCount := FVertexCount + 1;
  86.     SetLength(FVertex, FVertexCount);
  87.  
  88.     FVertex[FVertexCount-1].R := R;
  89.     FVertex[FVertexCount-1].G := G;
  90.     FVertex[FVertexCount-1].B := B;
  91.  
  92.     FVertex[FVertexCount-1].X := X;
  93.     FVertex[FVertexCount-1].Y := Y;
  94.     FVertex[FVertexCount-1].Z := Z;
  95. end;
  96.  
  97. constructor TPolygon.Create();
  98. begin
  99.   inherited Create();
  100.   FCount := 0;
  101.   FVertexCount := 0;
  102.   FTesselated := false;
  103.   FColor.R := 0.0;
  104.   FColor.G := 0.0;
  105.   FColor.B := 0.0;
  106.   FColor.A := 0.0;
  107. end;
  108.  
  109. destructor TPolygon.Destroy();
  110. begin
  111.   FTesselated := false;
  112.   FCount := 0;
  113.   FVertexCount := 0;
  114.   SetLength(FPoints, FCount);
  115.   SetLength(FVertex, FVertexCount);
  116.   inherited Destroy;
  117. end;
  118.  
  119. procedure TPolygon.SetPoint(I: integer; Value: TPoint);
  120. begin
  121.   FTesselated := false; //check first on changed values
  122.   FPoints[I] := Value;
  123. end;
  124.  
  125. function TPolygon.GetPoint(I: integer): TPoint;
  126. begin
  127.   result := FPoints[I];
  128. end;
  129.  
  130. function TPolygon.GetCount(): integer;
  131. begin
  132.   result := FCount;
  133. end;
  134.  
  135. procedure TPolygon.Add(X: single; Y: single);
  136. begin
  137.   FTesselated := false;
  138.   FCount := FCount + 1;
  139.   SetLength(FPoints, FCount);
  140.   FPoints[FCount-1].X := X;
  141.   FPoints[FCount-1].Y := Y;
  142.   FPoints[FCount-1].Z := 0.0;
  143.   FPoints[FCount-1].R := FColor.R;
  144.   FPoints[FCount-1].G := FColor.G;
  145.   FPoints[FCount-1].B := FColor.B;
  146.   FPoints[FCount-1].A := FColor.A;
  147. end;
  148.  
  149. procedure TPolygon.Add(X: single; Y: single; Z: single);
  150. begin
  151.   FTesselated := false;
  152.   FCount := FCount + 1;
  153.   SetLength(FPoints, FCount);
  154.   FPoints[FCount-1].X := X;
  155.   FPoints[FCount-1].Y := Y;
  156.   FPoints[FCount-1].Z := Z;
  157.   FPoints[FCount-1].R := FColor.R;
  158.   FPoints[FCount-1].G := FColor.G;
  159.   FPoints[FCount-1].B := FColor.B;
  160.   FPoints[FCount-1].A := FColor.A;
  161. end;
  162.  
  163. procedure TPolygon.Add(X: single; Y: single; Z: single; R: single; G: single; B: single; A: single);
  164. begin
  165.   FTesselated := false;
  166.   FCount := FCount + 1;
  167.   SetLength(FPoints, FCount);
  168.   FPoints[FCount-1].X := X;
  169.   FPoints[FCount-1].Y := Y;
  170.   FPoints[FCount-1].Z := Z;
  171.   FPoints[FCount-1].R := R;
  172.   FPoints[FCount-1].G := G;
  173.   FPoints[FCount-1].B := B;
  174.   FPoints[FCount-1].A := A;
  175. end;
  176.  
  177. Procedure TPolygon.Render();
  178. var
  179.   loop: integer;
  180. begin
  181.   if FTesselated = false then Tesselate;
  182.  
  183.   glbegin(GL_TRIANGLES);
  184.   for loop:=0 to FVertexCount-1 do
  185.   begin
  186.     glcolor3f(FVertex[loop].R,FVertex[loop].G,FVertex[loop].B);
  187.     glvertex3f(FVertex[loop].X,FVertex[loop].Y,FVertex[loop].Z);
  188.   end;
  189.   glend;
  190. end;
  191.  
  192. procedure TPolygon.Tesselate();
  193. var
  194.   loop: integer;
  195.   tess: pointer;
  196.   test: TGLArrayd3;
  197.   pol: PGLArrayd6;
  198.  
  199.   MyTest: string;
  200.  
  201. procedure iTessBeginCB(which: GLenum); {$IFDEF Win32}stdcall; {$ELSE}cdecl; {$ENDIF}
  202. begin
  203.   //PolygonClass.tessBegin(which);
  204. end;
  205.  
  206. procedure iTessEndCB(); {$IFDEF Win32}stdcall; {$ELSE}cdecl; {$ENDIF}
  207. begin
  208.   //PolygonClass.tessEnd();
  209. end;
  210.  
  211. procedure iTessEdgeCB(flag: GLboolean; lpContext: pointer); {$IFDEF Win32}stdcall; {$ELSE}cdecl; {$ENDIF}
  212. begin
  213.       //just do nothing to force GL_TRIANGLES !!!
  214. end;
  215.  
  216. procedure iTessVertexCB(data: PGLArrayd6); {$IFDEF Win32}stdcall; {$ELSE}cdecl; {$ENDIF}
  217. begin
  218.   //PolygonClass.tessVertex(data[0], data[1], data[2], data[3], data[4], data[5],0);
  219.   PolygonClass.AddVertex(data[0], data[1], data[2], data[3], data[4], data[5],0);
  220. end;
  221.  
  222.  
  223. procedure iTessCombineCB(newVertex : PGLArrayd6; neighborVertex : Pointer;
  224.                       neighborWeight : Pointer; var outData : Pointer); {$IFDEF Win32}stdcall; {$ELSE}cdecl; {$ENDIF}
  225. var
  226.   vertex: PGLArrayd6;
  227.   loop: integer;
  228.   colorloop: integer;
  229.   color: double;
  230. begin
  231.   new(vertex);
  232.  
  233.   vertex[0] := newVertex^[0];
  234.   vertex[1] := newVertex^[1];
  235.   vertex[2] := newVertex^[2];
  236.  
  237.   for colorloop := 3 to 5 do
  238.   begin
  239.     vertex[colorloop] := 0.0;
  240.     for loop:=0 to 3 do
  241.     begin
  242.       if PGLArrayf4(neighborWeight)^[loop] <> 0 then
  243.       begin
  244.         vertex[colorloop] := vertex[colorloop] +
  245.              PGLArrayf4(neighborWeight)^[loop] *
  246.              PGLArrayvertex4(neighborVertex)^[loop][colorloop]
  247.       end;
  248.     end;
  249.   end;
  250.  
  251.   // return output data (vertex coords and others)
  252.   outData:= vertex;
  253. end;
  254.  
  255. begin
  256.   PolygonClass := Self;
  257.  
  258.   tess := gluNewTess();
  259.  
  260.   gluTessCallback(tess, GLU_TESS_BEGIN, @iTessBeginCB );
  261.   gluTessCallback(tess, GLU_TESS_END, @iTessEndCB);
  262.   gluTessCallback(tess, GLU_TESS_VERTEX, @iTessVertexCB);
  263.   gluTessCallback(tess, GLU_TESS_COMBINE, @iTessCombineCB);  //does not work for font?
  264.   gluTessCallback(tess, GLU_TESS_EDGE_FLAG_DATA, @iTessEdgeCB); //force triangles
  265.  
  266.   gluTessProperty(tess, GLU_TESS_WINDING_RULE, GLU_TESS_WINDING_NONZERO );
  267.  
  268.   gluTessBeginPolygon(tess, nil);                   // with NULL data
  269.   gluTessBeginContour(tess);
  270.  
  271.   for loop := 0 to FCount-1 do
  272.   begin
  273.       new(pol);
  274.       pol[3]:=FPoints[loop].R; //color
  275.       pol[4]:=FPoints[loop].G;
  276.       pol[5]:=FPoints[loop].B;
  277.  
  278.       pol[0]:=FPoints[loop].X;
  279.       pol[1]:=FPoints[loop].Y;
  280.       pol[2]:=0;
  281.  
  282.       test[0] := pol[0];
  283.       test[1] := pol[1];
  284.       test[2] := pol[2];
  285.       gluTessVertex(tess, test, pol);
  286.   end;
  287.  
  288.   gluTessEndContour(tess);
  289.   gluTessEndPolygon(tess);
  290.   gluDeleteTess(tess);        // delete after tessellation
  291.  
  292.   PolygonClass := nil;
  293.   FTesselated := true;
  294. end;
  295.  
  296. end.
  297.  

_________________
http://3das.noeska.com - create adventure games without programming


Nach oben
 Profil  
Mit Zitat antworten  
Beiträge der letzten Zeit anzeigen:  Sortiere nach  
Ein neues Thema erstellen Auf das Thema antworten  [ 3 Beiträge ] 
Foren-Übersicht » English » English Programming Forum


Wer ist online?

Mitglieder in diesem Forum: 0 Mitglieder und 4 Gäste


Du darfst keine neuen Themen in diesem Forum erstellen.
Du darfst keine Antworten zu Themen in diesem Forum erstellen.
Du darfst deine Beiträge in diesem Forum nicht ändern.
Du darfst deine Beiträge in diesem Forum nicht löschen.
Du darfst keine Dateianhänge in diesem Forum erstellen.

Suche nach:
Gehe zu:  
  Powered by phpBB® Forum Software © phpBB Group
Deutsche Übersetzung durch phpBB.de
[ Time : 0.010s | 16 Queries | GZIP : On ]