Search code examples
copengltexturesglutfreeglut

OpenGL no texture


I have a problem, I want to bind a texture on a simple cube but my texture isnt displayed and I realy dont know what I did wrong.

this Is the texture part of my program :

void loadTextureSTD(char * path, int size, int size_x, int size_y)
{
  glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);

  glGenTextures(1, &textureID);

  glBindTexture(GL_TEXTURE_2D, textureID);

  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);


  texture = loadImageSTD(path, size, size_x, size_y);

  glTexImage2D(
          GL_TEXTURE_2D, 0, GL_RGB,
          size_x , size_y, 0, GL_RGB,
          GL_UNSIGNED_BYTE, texture
          );

}

this is the display part:

      glTexCoordPointer(2, GL_FLOAT, 0, vector_array_p0);
      glVertexPointer(3, GL_FLOAT, 0, vector_array_p0); GL_VERTEX_ARRAY (p0)
      glNormalPointer(GL_FLOAT, 0, normals_array_p0);
      glDrawElements(GL_TRIANGLES, animation0, GL_UNSIGNED_INT, face_array_p0);

This is my result (Light is on 0, 10, 0) : result


Solution

  • It seems as if textures are not enabled. Enable them:

    glEnable(GL_TEXTURE2D)
    

    and try again:

    glGenTextures(1, &textureID)