Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it necessary to call glEnable(GL_TEXTURE) before using textures in OpenGL 2.1?

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:

  1. 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).

  2. 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);
    
  3. And in draw_scene():

    glUseProgram(program);
    glActiveTexture(GL_TEXTURE0);
    glBindTexture(GL_TEXTURE_2D, texture_id);
    glUniform1i(uniform_texture, 0);
    ...
    
  4. 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;
    }
    
  5. Fragment shader:

    uniform sampler2D my_texture;
    varying vec2 fragTexCoord;
    
    void main()
    {
        gl_FragColor = texture2D(my_texture, fragTexCoord);
    }
    
like image 603
Bình Nguyên Avatar asked Jan 06 '13 05:01

Bình Nguyên


1 Answers

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.

like image 154
Sergey K. Avatar answered Oct 22 '22 14:10

Sergey K.