In OpenGL 2.1+ do we need to call glEnable(GL_TEXTURE)
before using textures? And if we got trouble with texture, what is may be cause?
Update:
I'm using OpenGL 2.1 for Desktop and my step is:
Load bmp 24 bit image (I checked in gDebuger and it show my texture ok, so i'm sure my load image procedure not failed).
Call several OpenGL functions in init()
procedude:
glGenTextures(1, &texture_id);
glBindTexture(GL_TEXTURE_2D, texture_id);
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, image_width, image_height, 0, GL_BGR, GL_UNSIGNED_BYTE, image_data);
And in draw_scene():
glUseProgram(program);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, texture_id);
glUniform1i(uniform_texture, 0);
...
Vertex shader (version 120):
attribute vec3 vPos;
attribute vec2 vTexCoord;
uniform mat4 MV;
uniform mat4 Projection;
varying vec2 fragTexCoord;
void main()
{
fragTexCoord = vTexCoord;
gl_Position = Projection * MV * vPos;
}
Fragment shader:
uniform sampler2D my_texture;
varying vec2 fragTexCoord;
void main()
{
gl_FragColor = texture2D(my_texture, fragTexCoord);
}
If you use GLSL shaders in OpenGL 2.1 then the call to glEnable(GL_TEXTURE_*)
has no meaning. You apply texture in your fragment shader.
If you intend to move on to the OpenGL 3.x core profile, keep in mind that glEnable(GL_TEXTURE_*)
is deprecated.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With