- procedure TSphere.GenerateVBO;
- const
- STACKS = 16;
- SLICES = 24;
- var
- points: TList<TVertex3f>;
- i, j, k, Offset: Integer;
- theta, phi: Extended;
- begin
- points := TList<TVertex3f>.Create;
- try
- // North Pole
- points.Add(Vertex3f(0, FRadius, 0));
- for i := 1 to STACKS do
- begin
- theta := i * Pi / STACKS;
- for j := 0 to SLICES-1 do
- begin
- phi := 2 * j * Pi / SLICES;
- points.Add(Vertex3f(
- cos(phi) * sin(theta) * FRadius,
- cos(theta) * FRadius,
- sin(phi) * sin(theta) * FRadius
- ));
- end;
- end;
- // South Pole
- points.Add(Vertex3f(0, -FRadius, 0));
- FVBO.VertexCount := points.Count;
- FVBO.IndexCount := points.Count;
- for i := 0 to points.Count-1 do
- begin
- FVBO.OpenVertex(i);
- FVBO.Write3f(element_type_vertex, points[i].X, points[i].Y, points[i].Z);
- FVBO.Write3ub(element_type_color, GetRValue(FColor), GetGValue(FColor), GetBValue(FColor));
- FVBO.WriteIndexUByte(i, i);
- end;
- FVBO.GenerateBuffer;
- finally
- FreeAndNil(points);
- end;
- end;