sharpgl icon indicating copy to clipboard operation
sharpgl copied to clipboard

Some triangles can't display correctly

Open congwuqi opened this issue 2 years ago • 1 comments

This is my first time using SharpGL and I have never used OpenGL before. I want to read a file in STL format, but it will display triangles incorrectly. (could it be normal vector error that caused the lighting problem?But I have checked all the normal vectors and they are still correct when they are sent to gl) There is no problem using Windos's 3D Viewer. Could you tell me where the problem might be?

` float[] no_mat = new float[] { 0.0f, 0.0f, 0.0f, 1.0f }; // 无材质颜色 float[] mat_ambient = new float[] { 0.7f, 0.7f, 0.7f, 1.0f }; // 环境颜色 float[] mat_ambient_color = new float[] { 0.8f, 0.6f, 0.2f, 1.0f }; float[] mat_diffuse = new float[] { 0.2f, 0.5f, 0.8f, 1.0f }; // 散射颜色 float[] mat_specular = new float[] { 1.0f, 1.0f, 1.0f, 1.0f }; // 镜面反射颜色 float[] no_shininess = new float[] { 0.0f }; // 镜面反射指数为0 float[] low_shininess = new float[] { 5.0f }; // 镜面反射指数为5.0 float[] high_shininess = new float[] { 100.0f }; // 镜面反射指数为100.0 float[] mat_emission = new float[] { 0.3f, 0.2f, 0.3f, 0.0f }; // 发射光颜色

        gl.PushMatrix();
        gl.Material(OpenGL.GL_FRONT, OpenGL.GL_AMBIENT, no_mat);
        gl.Material(OpenGL.GL_FRONT, OpenGL.GL_DIFFUSE, mat_diffuse);
        gl.Material(OpenGL.GL_FRONT, OpenGL.GL_SPECULAR, no_mat);
        gl.Material(OpenGL.GL_FRONT, OpenGL.GL_SHININESS, no_shininess);
        gl.Material(OpenGL.GL_FRONT, OpenGL.GL_EMISSION, no_mat);
        for (int i = 0; i < LengthOfTriangles; i++)
        {

            gl.Begin(OpenGL.GL_TRIANGLES);
            {
                if (triangleDisplay)
                {
                    gl.Color(0, 0, 1f);
                    gl.Vertex(triangles[i].Vertex1.X, triangles[i].Vertex1.Y, triangles[i].Vertex1.Z);
                    gl.Vertex(triangles[i].Vertex2.X, triangles[i].Vertex2.Y, triangles[i].Vertex2.Z);
                    gl.Vertex(triangles[i].Vertex3.X, triangles[i].Vertex3.Y, triangles[i].Vertex3.Z);
                    gl.Normal(triangles[i].Normal.X, triangles[i].Normal.Y, triangles[i].Normal.Z);
                }
                

            }
            gl.End();

        }
        gl.PopMatrix();`

congwuqi avatar Apr 08 '22 08:04 congwuqi

屏幕截图 2022-04-08 160449 屏幕截图 2022-04-08 160501

congwuqi avatar Apr 08 '22 08:04 congwuqi