我正在尝试在OpenGL中纹理四边形,并在获得统一位置时保持-1。
编辑:没有统一代码,它渲染得很好(减去c的纹理)。 这是代码:
纹理绑定代码;
m_renderer.prepare();
m_colorProgram.start();
// Sets the active texture to '0'.
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, m_texture.id);
GLint samplerLoc = m_colorProgram.getUniformLocation("mySampler");
// Tells OGl that we are using the active texture '0' as stated above.
glUniform1i(samplerLoc, 0);
m_renderer.render(m_model);
// Always unbind
glBindTexture(GL_TEXTURE_2D, 0);
m_colorProgram.stop();
m_colorProgram.getUniformLocation:
GLint GLSLProgram::getUniformLocation ( const std::string uniformName )
{
GLint location = glGetUniformLocation ( m_programID, "size" );
if ( location == (GLint)GL_INVALID_INDEX ) {
fatal_error ( "Uniform '" + uniformName + "' could not be found!" );
}
return location;
}
vert shader:
#version 130
// super simple shader program
in vec3 vertexPositon;
in vec4 vertexColor;
in vec2 vertexUV;
out vec4 fragColor;
out vec2 fragUV;
void main(){
gl_Position = vec4(vertexPositon,1.0);
fragColor = vertexColor;
fragUV = vertexUV;
}
frag shader:
#version 130
in vec4 fragColor;
in vec2 fragUV;
uniform sampler2D mySampler;
out vec4 color;
void main()
{
vec4 texColor = texture( mySampler, fragUV );
color = texColor * fragColor;
}
我在网上发现的大多数解决方案似乎表明Uniform正在被删除,因为它没有被使用,但是,正如你所看到的,它正被使用,但仍然返回-1
谁能告诉我为什么会这样?
答案 0 :(得分:0)
原来我在glGetUniform