Hi all, I’m having a problem again with a sample program from OpenGL super bible book. After converted the program to C#, I got this output
And this is the original output from the sample in C++
I used FLAT shading in my C# program so it is showing those little black triangles. Could any one please tell me how get rid of those black triangles?
I think that there is “1 line to 1 line” of code link between my C# function to draw the torus and the C++ function. But how my func got wrong ? or somewhere else my code got wrong ?
This is my func in C#:
public static void DrawTorus(float majorRadius, float minorRadius, int numMajor, int numMinor)
{
Vector3D3f vNormal = new Vector3D3f();
double majorStep = 2.0f * Math.PI / numMajor;
double minorStep = 2.0f * Math.PI / numMinor;
int i, j;
for (i = 0; i < numMajor; i++)
{
double a0 = i * majorStep;
double a1 = a0 + majorStep;
float x0 = (float)Math.Cos(a0);
float y0 = (float)Math.Sin(a0);
float x1 = (float)Math.Cos(a1);
float y1 = (float)Math.Sin(a1);
GL.Begin(GL.TRIANGLE_STRIP);
for (j = 0; j <= numMinor; j++)
{
double b = j * minorStep;
float c = (float)Math.Cos(b);
float r = minorRadius * c + majorRadius;
float z = minorRadius * (float)Math.Sin(b);
//First point
GL.TexCoord2f((float)i / (float)(numMajor), (float)(j) / (float)(numMinor));
vNormal[0] = x0 * c;
vNormal[1] = y0 * c;
vNormal[2] = z / minorRadius;
Math3D.NormalizeVector(vNormal);
GL.Normal3f(vNormal.X, vNormal.Y, vNormal.Z);
GL.Vertex3f(x0 * r, y0 * r, z);
GL.TexCoord2f((float)(i + 1) / (float)(numMajor), (float)(j) / (float)(numMinor));
vNormal[0] = x1 * c;
vNormal[1] = y1 * c;
vNormal[2] = z / minorRadius;
Math3D.NormalizeVector(vNormal);
GL.Normal3f(vNormal.Z, vNormal.Y, vNormal.Z);
GL.Vertex3f(x1 * r, y1 * r, z);
}
GL.End();
}
}