OpenGL textures problem

Started by
2 comments, last by ParadigmShift 20 years, 5 months ago
I used to use OpenGL extensively in Windows, now I''m using DX9 but porting it back to OpenGL on Mandrake 9.2... For some reason textures won''t work. I''m trying to make a simple color pattern. The code is:

  // TEST ONLY BEGIN
  unsigned char *buffer = new unsigned char[256*256*4];
  for (long x=0;x<256;x++)
  for (long y=0;y<256;y++) {
    buffer[x*256*4+y*4] = x;
    buffer[x*256*4+y*4+1] = y;
    buffer[x*256*4+y*4+2] = (x*x+y*y)/256;
    buffer[x*256*4+y*4+3] = 255;
  }

  glPixelStorei(GL_UNPACK_ALIGNMENT, 1);

  glEnable(GL_TEXTURE_2D);
  glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 256, 256, 0, GL_RGBA, GL_UNSIGNED_BYTE, buffer);
  // TEST ONLY END
    
   GFXVERTEX *vertices = obj->GetVertices();
   WORD *indices = obj->GetIndices();
      
   glBegin( GL_TRIANGLES );            /* Drawing Using Triangles */
   for (long i=0;inumFaces;i++) {
      glColor3f(1.0, 1.0, 1.0);
      glTexCoord2f(0, 0);
      glVertex3f(vertices[indices[i*3]].x,
                vertices[indices[i*3]].y,
                vertices[indices[i*3]].z);
      glTexCoord2f(0,1);
      glVertex3f(vertices[indices[i*3+1]].x,
                vertices[indices[i*3+1]].y,
                vertices[indices[i*3+1]].z);
      glTexCoord2f(1,0);
      glVertex3f(vertices[indices[i*3+2]].x,
                vertices[indices[i*3+2]].y,
                vertices[indices[i*3+2]].z);
   }
   glEnd( );                       
 
But I just see white triangles. Any ideas? Thanks, Tom
"E-mail is for geeks and pedophiles." -Cruel Intentions
Advertisement
The things I notice are...

You don''t generate a texture using glGenTextures or bind it using glBindTexture.

Why you shouldn''t use iostream.h - ever! | A Good free online C++ book
glGenTextures/glBindTexture was called at least once before this code was run.

I added the two functions and it still doesn''t work. Has anyone run across a problem like this before?

Tom
"E-mail is for geeks and pedophiles." -Cruel Intentions
Where did you add them? I think we need more information.

Why you shouldn''t use iostream.h - ever! | A Good free online C++ book

This topic is closed to new replies.

Advertisement