You can use this code, which is originally from Asphyre 4.1 (it uses vertex & index buffers):
Code:
Theta:= 0.0;
ThetaInc:= 2.0 * Pi / Rings;
PhiInc:= 2.0 * Pi / Sides;
for j:= 0 to Rings do
begin
CosTheta:= Cos(Theta);
SinTheta:= Sin(Theta);
Phi:= 0.0;
for i:= 0 to Sides do
begin
CosPhi:= Cos(Phi);
SinPhi:= Sin(Phi);
Delta := Radius + TubeRadius * CosPhi;
IncludeVertex(
Vector3(CosTheta * Delta, TubeRadius * SinPhi, -SinTheta * Delta),
Vector3(CosTheta * CosPhi, SinPhi, -SinTheta * CosPhi),
Point2(Theta * TexTilesX / (2.0 * Pi), Phi * TexTilesY / (2.0 * Pi)));
ni:= i + 1;
nj:= j + 1;
if (i < Sides)and(j < Rings) then
begin
IncludeIndex(i + j * SideBlock);
IncludeIndex(i + nj * SideBlock);
IncludeIndex(ni + nj * SideBlock);
IncludeIndex(i + j * SideBlock);
IncludeIndex(ni + nj * SideBlock);
IncludeIndex(ni + j * SideBlock);
end;
Phi:= Phi + PhiInc;
end;
Theta:= Theta + ThetaInc;
end;
Porting the code to OpenGL should be a matter of changing "IncludeVertex" to rendering calls.
Bookmarks