Hello,
I try to use a simple 2D texture with OpenGL 3.1 and by using a shader program. I tried to map on a sphere but it does not work. The Sphere is black.
My steps were.
1) To initialize the texture
Code :glPixelStorei(GL_UNPACK_ALIGNMENT, 1); glGenTextures(1, &tex); glBindTexture(GL_TEXTURE_2D, tex); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 128, 128, 0, GL_RGB, GL_UNSIGNED_BYTE, pointer);
2) Using a shader program with input attribute for the texels.
Code :// vertex shader #version 140 in vec3 MCVertex; in vec3 MCNormal; in vec2 TexCoord0; ... // fragment shader #version 140 in float LightIntensity; in vec2 TexCoord; out vec4 FragColor; uniform sampler2D SampleTexture; void main() { vec3 lightColor = vec3(texture(SampleTexture, TexCoord)); FragColor = vec4(lightColor * LightIntensity, 1.0); }
3) before I start to render the geometry, I bound the texture
Code :glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, _id);
What I have forgotten? Or maybe the order of the commands are wrong?
Thanks in advance!



