c++ - OpenGLESv2 Shader glGetAttribLocation returns -1 -
hey, try code opengl es 2 engine @ shader creation function glgetattriblocation returns -1 means
the named attribute variable not active attribute in specified program object or name starts reserved prefix "gl_".
but defined in shader , doesnt start gl_. whats wrong code?
c++ code:
glprogram = glcreateprogram(); glvertshader = glcreateshader(gl_vertex_shader); glfragshader = glcreateshader(gl_fragment_shader); glshadersource(glvertshader, 1, vertsrc, null); glshadersource(glfragshader, 1, fragsrc, null); glint ret; glcompileshader(glvertshader); glgetshaderiv(glvertshader, gl_compile_status, &ret); if(!ret) { ///error handling - stripped internet } glcompileshader(glfragshader); glgetshaderiv(glfragshader, gl_compile_status, &ret); if(!ret) { ///error handling - stripped internet } glattachshader(glprogram, glvertshader); glattachshader(glprogram, glfragshader); gllinkprogram(glprogram); glgetprogramiv(glprogram, gl_link_status, &ret); if(!ret) { ///error handling - stripped internet } glattributes[0] = glgetattriblocation(glprogram, "vertex"); glattributes[1] = glgetattriblocation(glprogram, "texcoord_vs"); std::cout << "texcoord " << glgetattriblocation(glprogram, "texcoord_vs";
vert shader:
// vertex shader opengl es uniform mat4 projmat; uniform mat4 modviewmat; attribute vec2 vertex; attribute vec2 texcoord_vs; varying vec2 texcoord_fs; void main() { texcoord_fs = texcoord_vs; gl_position = projmat*modviewmat*vec4(vertex, 0.0, 1.0); }
edit: correct shader code , error texcoord_vs.
you didn't specify attribute not used, assume it's "texcoord_vs", because you're not using it, , such it's being stripped shader compiler.
i suppose meant texcoord_fs = texcoord_vs
?
Comments
Post a Comment