-1

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

Box Box Box Box
  • 5,094
  • 10
  • 49
  • 67
noName
  • 132
  • 1
  • 9
  • (1) Are you certain that GL is properly initialized? E.g. can you display a diffuse-shaded cube? If not, then another path of questions needs to be asked. The following assumes that your problem is with textures and not basic GL. (2) RGB should have 3 bytes per pixel, but it appears that you are only reading 1. Am I wrong? – Reality Pixels May 05 '16 at 15:35
  • Yes I read 1 byte from the ppm file... did I understand something wrong ? – noName May 05 '16 at 16:00
  • I find out that glGenTextures generates 0 do anyone know what I did wrong ?? – noName May 05 '16 at 19:48
  • Given `glGenTextures` returning **0**, you probably have no GL context active in the calling thread. Implementations are not required to do this (in fact it is actually frowned upon -- since there is supposed to be no context in which to store the error state), but some may raise a `GL_INVALID_OPERATION` error that you can test for with `glGetError (...)` if you make an API call with no context active. – Andon M. Coleman May 07 '16 at 21:27

1 Answers1

0

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

glEnable(GL_TEXTURE2D)

and try again:

glGenTextures(1, &textureID)
jromeror
  • 100
  • 12