我正在创建一个包含基本游戏需求的游戏引擎。使用glslDevil,结果是我的绑定VBO方法抛出InvalidValue错误。调用glVertexPointer和调用glEnableVertexPointer会导致问题。顶点属性索引导致问题。该指数是4294967295,远远超过15.其他一切都很好。我正在使用OpenTK。这是绑定到属性方法。
public void BindToAttribute(ShaderProgram prog, string attribute)
{
int location = GL.GetAttribLocation(prog.ProgramID, attribute);
GL.EnableVertexAttribArray(location);
Bind();
GL.VertexAttribPointer(location, Size, PointerType, true, TSize, 0);
}
public void Bind()
{
GL.BindBuffer(Target, ID);
}
如果需要,这是我的着色器。
顶点着色器:
uniform mat4 transform;
uniform mat4 projection;
uniform mat4 camera;
in vec3 vertex;
in vec3 normal;
in vec4 color;
in vec2 uv;
out vec3 rnormal;
out vec4 rcolor;
out vec2 ruv;
void main(void)
{
rcolor = color;
rnormal = normal;
ruv = uv;
gl_Position = camera * projection * transform * vec4(vertex, 1);
}
Fragment Shader:
in vec3 rnormal;
in vec4 rcolor;
in vec2 ruv;
uniform sampler2D texture;
void main(void)
{
gl_FragColor = texture2D(texture, ruv) * rcolor;
}
我没有正确获取索引或是否存在其他问题?
答案 0 :(得分:0)
你得到的索引似乎是问题所在:这是当opengl找不到具有该名称的有效属性/制服时得到的索引。
可能会发生一些事情:
总的来说,这个数字表明OpenGL无法找到你想要的制服或属性
编辑:
以下是一个技巧:让我们假设您有一些像素着色器代码,它返回的值是许多值的总和:
out vec4 color;
void main()
{
// this shader does many calculations when you are
// using many values, but let's assume you want to debug
// just the diffuse color... how do you do it?
// if you change the output to return just the diffuse color,
// the optimizer might remove code and you might have problems
//
// if you have this
color = various_calculation_1 + various_calculation_2 + ....;
// what you can do is the following
color *= 0.0000001f; // so basically it's still calculated
// but it almost won't show up
color += value_to_debug; // example, the diffuse color
}