Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/opengl/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 用VBO中的OpenTK绘制三角形_C#_Opengl_Opentk - Fatal编程技术网

C# 用VBO中的OpenTK绘制三角形

C# 用VBO中的OpenTK绘制三角形,c#,opengl,opentk,C#,Opengl,Opentk,我无法用OpenTK中的VBO渲染三角形。我正在glControl_Load()事件中将数据加载到VBO。跑步时,我会看到一个没有三角形的背景屏幕。数据来自网格m。OpenGlarray(输出数据,输出索引)输出浮点和整数列表。顶点T1v1、T1v2、T1v3、T2v1、T2v2、T2v3等的浮动列表,每个三角形的所有三个顶点背靠背 然而,当我评论“中间”渲染代码时,给出了一个带有代码的空白屏幕,所有渲染都很好。。。。???我做错了什么 private void glControl_Lo

我无法用OpenTK中的VBO渲染三角形。我正在glControl_Load()事件中将数据加载到VBO。跑步时,我会看到一个没有三角形的背景屏幕。数据来自网格m。OpenGlarray(输出数据,输出索引)输出浮点和整数列表。顶点T1v1、T1v2、T1v3、T2v1、T2v2、T2v3等的浮动列表,每个三角形的所有三个顶点背靠背

然而,当我评论“中间”渲染代码时,给出了一个带有代码的空白屏幕,所有渲染都很好。。。。???我做错了什么

    private void glControl_Load(object sender, EventArgs e)
    {
        loaded = true;
        glControl.MouseMove += new MouseEventHandler(glControl_MouseMove);
        glControl.MouseWheel += new MouseEventHandler(glControl_MouseWheel);

        GL.ClearColor(Color.DarkSlateGray);
        GL.Color3(1f, 1f, 1f);

        m.OpenGLArrays(out data, out indices);
        this.indicesSize = (uint)indices.Length;
        GL.GenBuffers(1, out VBOid[0]);
        GL.GenBuffers(1, out VBOid[1]);

        SetupViewport();
    }

    private void SetupViewport()
    {
        if (this.WindowState == FormWindowState.Minimized) return;
        glControl.Width = this.Width - 32;
        glControl.Height = this.Height - 80;
        Frame_label.Location = new System.Drawing.Point(glControl.Width / 2, glControl.Height + 25);
        GL.MatrixMode(MatrixMode.Projection);
        //GL.LoadIdentity();
        GL.Ortho(0, glControl.Width, 0, glControl.Height, -1, 1); // Bottom-left corner pixel has coordinate (0, 0)
        GL.Viewport(0, 0, glControl.Width, glControl.Height); // Use all of the glControl painting area
        GL.Enable(EnableCap.DepthTest);

        GL.BindBuffer(BufferTarget.ArrayBuffer, VBOid[0]);
        GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(data.Length * sizeof(float)), data, BufferUsageHint.StaticDraw);
        GL.BindBuffer(BufferTarget.ArrayBuffer, 0);

        float aspect_ratio = this.Width / (float)this.Height;
        projection = Matrix4.CreatePerspectiveFieldOfView(MathHelper.PiOver4, aspect_ratio, 1, 1024);
        GL.MatrixMode(MatrixMode.Projection);
        GL.LoadMatrix(ref projection);
    }

    private void glControl_Paint(object sender, PaintEventArgs e)
    {
        if (loaded)
        {
            GL.Clear(ClearBufferMask.ColorBufferBit |
                     ClearBufferMask.DepthBufferBit |
                     ClearBufferMask.StencilBufferBit);

            modelview = Matrix4.LookAt(0f, 0f, -200f + zoomFactor, 0, 0, 0, 0.0f, 1.0f, 0.0f);
            var aspect_ratio = Width / (float)Height;
            projection = Matrix4.CreatePerspectiveFieldOfView(MathHelper.PiOver4, aspect_ratio, 1, 512);

            GL.MatrixMode(MatrixMode.Projection);
            GL.LoadMatrix(ref projection);
            GL.MatrixMode(MatrixMode.Modelview);
            GL.LoadMatrix(ref modelview);
            GL.Rotate(angleY, 1.0f, 0, 0);
            GL.Rotate(angleX, 0, 1.0f, 0);

            GL.EnableClientState(ArrayCap.VertexArray);

            GL.BindBuffer(BufferTarget.ArrayBuffer, VBOid[0]);

            GL.Color3(Color.Yellow);

            GL.VertexPointer(3, VertexPointerType.Float, Vector3.SizeInBytes, new IntPtr(0));
            GL.DrawArrays(PrimitiveType.Triangles, 0, data.Length);
            GL.BindBuffer(BufferTarget.ArrayBuffer, 0);
            GL.DisableClientState(ArrayCap.VertexArray);

            //GL.Color3(Color.Yellow);
            //GL.PolygonMode(MaterialFace.Front, PolygonMode.Fill);
            //GL.Begin(PrimitiveType.Triangles);

            //for (int i = 0; i < this.md.mesh.Count; i++)
            //{
            //    GL.Normal3(this.md.mesh[i].normal);
            //    GL.Vertex3(this.md.mesh[i].vertices[0]);
            //    GL.Vertex3(this.md.mesh[i].vertices[1]);
            //    GL.Vertex3(this.md.mesh[i].vertices[2]);
            //}
            //GL.End();
            //GL.EndList();

            glControl.SwapBuffers();

            Frame_label.Text = "Frame: " + frameNum++;
        }
    }
private void glControl\u加载(对象发送方,事件参数e)
{
加载=真;
glControl.MouseMove+=新的MouseEventHandler(glControl\u MouseMove);
glControl.MouseWheel+=新的MouseEventHandler(glControl\U MouseWheel);
GL.ClearColor(颜色为深灰色);
GL.Color3(一层、一层、一层);
m、 OpenGlarray(输出数据、输出索引);
this.indicatesize=(uint)index.Length;
GL.GenBuffers(1,out VBOid[0]);
GL.GenBuffers(1,out VBOid[1]);
SetupViewport();
}
私有void SetupViewport()
{
if(this.WindowState==FormWindowState.Minimized)返回;
glControl.Width=this.Width-32;
glControl.Height=this.Height-80;
Frame_label.Location=新系统图点(glControl.Width/2,glControl.Height+25);
GL.MatrixMode(MatrixMode.Projection);
//GL.LoadIdentity();
GL.Ortho(0,glControl.Width,0,glControl.Height,-1,1);//左下角像素具有坐标(0,0)
GL.Viewport(0,0,glControl.Width,glControl.Height);//使用所有glControl绘制区域
总账启用(启用CAP.深度测试);
GL.BindBuffer(BufferTarget.ArrayBuffer,VBOid[0]);
GL.BufferData(BufferTarget.ArrayBuffer,(IntPtr)(data.Length*sizeof(float)),data,BufferUsageHint.StaticDraw);
GL.BindBuffer(BufferTarget.ArrayBuffer,0);
浮动纵横比=此宽度/(浮动)此高度;
projection=Matrix4.CreatePerspectiveFieldOfView(MathHelper.PiOver4,纵横比,1,1024);
GL.MatrixMode(MatrixMode.Projection);
总帐负荷矩阵(参考投影);
}
私有void glControl_Paint(对象发送器,PaintEventArgs e)
{
如果(已加载)
{
GL.Clear(ClearBufferMask.ColorBufferBit|
ClearBufferMask.DepthBufferBit|
ClearBufferMask.StencilBufferBit);
modelview=Matrix4.LookAt(0f,0f,-200f+zoomFactor,0,0,0.0f,1.0f,0.0f);
var纵横比=宽度/(浮动)高度;
projection=Matrix4.CreatePerspectiveFieldOfView(MathHelper.PiOver4,纵横比,1512);
GL.MatrixMode(MatrixMode.Projection);
总帐负荷矩阵(参考投影);
GL.MatrixMode(MatrixMode.Modelview);
总帐负荷矩阵(参考模型视图);
GL.旋转(角度,1.0f,0,0);
GL.旋转(角度X,0,1.0f,0);
GL.EnableClientState(ArrayCap.VertexArray);
GL.BindBuffer(BufferTarget.ArrayBuffer,VBOid[0]);
GL.Color3(颜色为黄色);
GL.VERTEXPINTER(3,VERTEXPINTERTYPE.Float,矢量3.SizeInBytes,新IntPtr(0));
GL.DrawArray(PrimitiveType.Triangles,0,data.Length);
GL.BindBuffer(BufferTarget.ArrayBuffer,0);
总账DisableClientState(ArrayCap.VertexArray);
//GL.Color3(颜色为黄色);
//GL.PolygonMode(MaterialFace.Front,PolygonMode.Fill);
//GL.Begin(基本类型三角形);
//for(int i=0;i
如果某件事情看起来不对劲,那么它可能就不对了。我严肃地质疑我对opengl的理解,并花了数小时研究它。然而,这只是一个简单的错误,忘记在for循环中迭代count变量以将网格从一个对象传输到另一个对象。每个三角形都有相同的顶点!当涉及到调试时,总是期待意外的结果

您正在使用不推荐使用的OpenGL:如果您已经发现错误,您的答案/问题不可能帮助其他人,如果您可以删除它们,那就太好了。