Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some triangles can't display correctly #209

Open
congwuqi opened this issue Apr 8, 2022 · 1 comment
Open

Some triangles can't display correctly #209

congwuqi opened this issue Apr 8, 2022 · 1 comment

Comments

@congwuqi
Copy link

congwuqi commented Apr 8, 2022

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
Copy link
Author

congwuqi commented Apr 8, 2022

屏幕截图 2022-04-08 160449

屏幕截图 2022-04-08 160501

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant