dwmkerr / dwmkerr/sharpgl

Some triangles can't display correctly

Open
#209 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
C#
Stars
804
Forks
294
Avg merge
3d 23h
Merged PRs (30d)
1

Description

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();`

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the C# SharpGL rendering loop included in the issue and inspect how the STL triangle vertices and normals are submitted inside gl.Begin(OpenGL.GL_TRIANGLES). No repository file or test is named; done would require identifying the cause of the incorrect triangle display and documenting a reproducible correction or test.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
computer-graphics
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.