我嘗試使用VBO作爲folloiwng畫線的banch(改變基本的和最簡單的事情):OpenGL與OpenTK:如何替換不工作GL.EnableClientState(ArrayCap.ColorArray)?
struct VertexColor
{
public Vector2d vertex;
public uint color;
//...
}
//...
Draw(){
GL.EnableClientState(ArrayCap.ColorArray);
GL.EnableClientState(ArrayCap.VertexArray);
GL.BindBuffer(BufferTarget.ArrayBuffer, lineVbo.VboID);
GL.BindBuffer(BufferTarget.ElementArrayBuffer, lineVbo.EboID);
GL.VertexPointer(2, VertexPointerType.Double, BlittableValueType.StrideOf(lineList.ToArray()), 0);
GL.ColorPointer(4, ColorPointerType.UnsignedByte, BlittableValueType.StrideOf(lineList.ToArray()), 16);
GL.DrawElements(PrimitiveType.Lines, lineVbo.NumElements, DrawElementsType.UnsignedInt, 0);
}
它的工作以及我的電腦上,但在其他一個DrawElements拋出「內存違規訪問」,這是可能的因爲使用glEnableClientState(根據SO上的類似問題)。
我用新的繪圖代替它(通過着色器,但實際上我不需要在我的程序中的任何着色器):
Shader.Bind(shader); //Shader is a helper class that works correctly
GL.BindBuffer(BufferTarget.ArrayBuffer, lineVbo.VboID);
GL.VertexAttribPointer(0, 2, VertexAttribPointerType.Double, false, BlittableValueType.StrideOf(lineList.ToArray()), 0);
GL.EnableVertexAttribArray(0);
GL.VertexAttribPointer(1, 4, VertexAttribPointerType.UnsignedByte, false, BlittableValueType.StrideOf(lineList.ToArray()), 16);
GL.EnableVertexAttribArray(1);
GL.BindBuffer(BufferTarget.ArrayBuffer, lineVbo.EboID);
GL.DrawElements(PrimitiveType.LineStrip, lineVbo.NumElements, DrawElementsType.UnsignedInt, (IntPtr)0);
片段着色器提供了一個錯誤「錯誤:29718:48252:‘’:存儲限定符與佈局限定符ID無效「:
#version 330 core
layout(location = 1) in vec4 fragmentColor;
out vec4 color;
void main(){
color = fragmentColor;
}
如何克服此錯誤或以其他方式替換EnableClientState?