Hello,
I am trying to read the position and texture data out of a collada file.
Reading the position data works fine, but the texture is not mapped correctly onto my plane.
I create the texture as follows:
for (int i=0; i<64*64; i++) _texture[i] = 255;
The texture is afterwards set this way:
_locTexture = glGetUniformLocation(shaderProgramId, "u_texture");
glGenTextures(1, &_textureID);
glBindTexture(GL_TEXTURE_2D, _textureID);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 64, 64, 0, GL_RGB, GL_UNSIGNED_BYTE, _texture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
During the draw phase I added this code:
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, _textureID);
glUniform1i(_locTexture, 0);
The shaders look like this:
Vertex shader:
attribute vec4 a_position; // Vertex position
attribute vec4 a_normal; // Vertex normal
attribute vec4 a_color; // Vertex color
attribute vec2 a_uv; // Vertex texture coordinate
uniform mat4 u_mvpMatrix; // model view matrix
varying vec4 v_color; // Resulting color per vertex
varying vec2 v_uv; // texture coordinate
void main(void) {
v_color = a_color;
gl_Position = u_mvpMatrix * a_position;
v_uv = a_uv;
}
Fragment shader:
uniform sampler2D u_texture;
varying vec2 v_uv;
varying vec4 v_color; // interpolated color calculated in the vertex shader
void main() {
gl_FragColor = texture2D(u_texture, v_uv);
}
The UV coordinates are read from the collada file which has been made in Blender 2.63a.
The result is shown in the attached screenshot.
Only the lower part is white, the rest seems to be random.
Does anybody have any idea what I’m doing wrong?