Hey everyone,
I'm trying my hand at using textures in openGL. Currently, I'd like to get a hold of the uniform handle of my sampler2D variable.
The code is:
the glGetError() calls always return 0. Also, the error message that the attribute couldn't be bound also always shows.Code :qDebug() << "glGetError before binding attribute_s_texture is" << glGetError(); attribute_name = "texture1"; attribute_s_texture = glGetUniformLocation(program, attribute_name); qDebug() << "glGetError after binding attribute_s_texture is" << glGetError(); if (attribute_s_texture == -1) { fprintf(stderr, "Could not bind attribute %s\n", attribute_name); }
My fragment shader:
(I'm trying to write the shader in a way that draws a texture if there is one and doesn't when there isn't.)Code :varying vec3 f_color; uniform sampler2D texture1; void main(void) { //if(texture1 == 0) // gl_FragColor = vec4(f_color.x, f_color.y, f_color.z, 1.0); //else gl_FragColor = texture2D(texture1, gl_TexCoord[0].st); }
For sake of completion, my vertex shader:
(It's ... "experimental".)Code :attribute vec3 coord3d; attribute vec3 v_color; attribute vec3 v_normal; attribute vec3 v_uv; uniform mat4 mvp; varying vec3 normals; varying vec3 f_color; //varying float intensity; varying vec3 Id; void main(void) { gl_Position = mvp * vec4(coord3d, 1.0); //vec3 Id = vec3(gl_LightSource[0].position - gl_Position); Id = vec3(gl_LightSource[0].position - gl_Position); //vec3 lightDir = normalize(Id); //intensity = dot(lightDir, gl_Normal); //normals = gl_NormalMatrix * gl_Normal/*v_normal*/; //normals = gl_Normal; normals = v_normal; gl_TexCoord[0] = gl_MultiTexCoord0; f_color = v_color; }
Anyone got an idea? Since I'm using the texture1 variable, I don't think it's being optimized out, is it?