【发布时间】:2014-10-26 21:57:08
【问题描述】:
好的,我搜索了其他人的问题,但找不到解决问题的方法。我在 C# 和 GLSL 330 中使用 OpenTK。它正在产生错误消息 错误 c0000:语法错误,意外的“?”在令牌'?'
由于某种原因,它不喜欢我正在做的事情。所以,这是我的代码,希望有人能告诉我 我做错了什么。
public static string vertexShaderSource = @"
#version 330
uniform mat4 pvm;
in vec4 Position;
in vec2 texCoord;
out vec2 texCoordV;
void main()
{
texCoordV = texCoord;
gl_Position = Position * pvm;
}";
public static string fragmentShaderSource = @"
#version 330
in vec2 texCoordV;
out vec4 colorOut;
void main()
{
colorOut = vec4(texCoord, 0.0, 0.0);
}";
public void Initalize()
{
style = GUI_Skin.styles[0];
vertices = new Vector3[6];
vertices[0] = new Vector3(0, 0, 0f);
vertices[1] = new Vector3(100, 0, 0f);
vertices[2] = new Vector3(0, 100, 0f);
vertices[3] = new Vector3(100, 0, 0f);
vertices[4] = new Vector3(0, 100, 0f);
vertices[5] = new Vector3(100, 100, 0f);
GL.GenBuffers(1, out vertHandle);
GL.BindBuffer(BufferTarget.ArrayBuffer, vertHandle);
GL.BufferData<Vector3>(BufferTarget.ArrayBuffer,
new IntPtr(vertices.Length * Vector3.SizeInBytes),
vertices, BufferUsageHint.StaticDraw);
texCoords = new Vector2[6];
texCoords[0] = new Vector2(0,0);
texCoords[1] = new Vector2(1, 0);
texCoords[2] = new Vector2(0, 1);
texCoords[3] = new Vector2(1, 0);
texCoords[4] = new Vector2(0, 1);
texCoords[5] = new Vector2(1, 1);
GL.GenBuffers(1, out texHandle);
GL.BindBuffer(BufferTarget.ArrayBuffer, texHandle);
GL.BufferData<Vector2>(BufferTarget.ArrayBuffer,
new IntPtr(texCoords.Length * Vector2.SizeInBytes),
texCoords, BufferUsageHint.StaticDraw);
}
public void Draw()
{
GL.EnableVertexAttribArray(vertHandle);
GL.BindBuffer(BufferTarget.ArrayBuffer, vertHandle);
GL.VertexAttribPointer(0, 3, VertexAttribPointerType.Float, false, Vector3.SizeInBytes, 0);
GL.EnableVertexAttribArray(texHandle);
GL.BindBuffer(BufferTarget.ArrayBuffer, texHandle);
GL.VertexAttribPointer(0, 2, VertexAttribPointerType.Float, false, Vector2.SizeInBytes, 0);
GL.DrawArrays(PrimitiveType.Triangles, 0, 6);
GL.DisableVertexAttribArray(vertHandle);
GL.DisableVertexAttribArray(texHandle);
}
【问题讨论】:
-
通常有一些线路/位置信息有错误
-
编译顶点或片段着色器时是否出现此错误消息?
-
对我来说听起来像是字符编码的问题。 GLSL 需要 UTF-8 的一个小子集,如果遇到在 cmets 之外不希望出现的字符,则会生成诸如此类的错误。如果您删除
@并在每一行的末尾使用\n而不是一个长的逐字字符串文字,这会改变什么吗? -
棘轮怪胎它说 0(13) 表示行号||||||| BDL 是的,我可能应该提到它的编译错误|||||||||| Andon M. Coleman 似乎消除了错误,但现在它只是一个白屏。你在哪里是正确的:) 我之前在绑定顶点数据时遇到了一个类似的问题。可能与此有关。
-
@LeviGraham:嗯,我可以看到另一个问题。
gl_Position = Position * pvm;对我来说看起来很不寻常。通常在 OpenGL 中,你会有一些效果:gl_Position = pvm * Position。除非您的矩阵以行为主(这是可能的,因为我记得至少有一个 C# 框架可以做到这一点,但我不记得是哪个),您应该考虑交换操作数。
标签: c# opengl shader vbo opentk