Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/318.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# 如何给顶点着色?_C#_Xamarin.ios_Opengl Es 2.0_Opentk - Fatal编程技术网

C# 如何给顶点着色?

C# 如何给顶点着色?,c#,xamarin.ios,opengl-es-2.0,opentk,C#,Xamarin.ios,Opengl Es 2.0,Opentk,如何在opengl es 2.0中设置顶点的颜色 现在我使用颜色数组: float[] TriangleColors = new float[]{ 1.0f, 1.0f, 0.0f, 1.0f, 1.0f, 0.0f, 1.0f, 1.0f, 0.0f, }; GL.EnableVer

如何在opengl es 2.0中设置顶点的颜色

现在我使用颜色数组:

float[] TriangleColors = new float[]{
                           1.0f, 1.0f, 0.0f,
                           1.0f, 1.0f, 0.0f,
                           1.0f, 1.0f, 0.0f,
                         };

GL.EnableVertexAttribArray((int)GLKVertexAttrib.Color);
GL.VertexAttribPointer((int)GLKVertexAttrib.Color,
                       3, VertexAttribPointerType.Float,
                       false, 0, 0);

GL.GenBuffers(1, out colorBuffer);
GL.BindBuffer(BufferTarget.ArrayBuffer, colorBuffer);

GL.BufferData (BufferTarget.ArrayBuffer,
               (IntPtr)(TriangleColors.Length * sizeof(float)),
               TriangleColors,
               BufferUsage.StaticDraw);

此代码不适用于我。

在调用glvertexattributepointer函数之前,应该生成存储顶点颜色的VBO并将其绑定到数组缓冲区目标

该功能可通过两种方式工作:

  • 您可以使用最后一个参数直接提供指向顶点属性数据的指针(在您的例子中是三角形颜色),然后您根本不需要任何VBO,但在调用函数时还必须确保没有缓冲区绑定到数组缓冲区

  • 另一方面,如果希望使用顶点缓冲区对象,则必须确保在调用函数时将正确的VBO绑定到数组缓冲区目标-这会更改最后一个参数的含义;它现在成为当前绑定缓冲区的字节偏移量

就你而言

GL.VertexAttribPointer((int)GLKVertexAttrib.Color,
                           3, VertexAttribPointerType.Float,
                           false, 0, 0);

您不提供指针,因此最后一个参数被视为进入数组缓冲区目标的字节偏移量(即,无偏移量);但是你的代码没有显示在那一点上是否有任何VBO被绑定,只显示你以后绑定颜色VBO。

你能给我举个例子吗?我有顶点数组和颜色数组,但我没有索引数组。也许您有示例C#(C++)+opengl es 2.0?我从来没有和着色器一起工作过。