Texuring problem

Hi !

At the moment I’m trying to load a texture and map it to
a quad.
That should be simple, but the texture isn’t rendered
correctly and I’ve not the slightest idea why.
(I just want the texture to show up once (stretched))
Here’s my code:

// Load a texture

UINT_32 loadTexture (const std::string &k_filename)
{
  UINT_32 ul_return = 0;
  AUX_RGBImageRec *pt_bitmap = NULL;

  pt_bitmap = auxDIBImageLoad(k_filename.c_str ());

  if(NULL != pt_bitmap)
  {
    glGenTextures(1, &ul_return);
    glBindTexture(GL_TEXTURE_2D, ul_return);

    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);

    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);

    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
    
    glTexImage2D (GL_TEXTURE_2D, 0, GL_RGB, pt_bitmap->sizeX, pt_bitmap->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, pt_bitmap->data);

    if (pt_bitmap->data) 
    {
      free(pt_bitmap->data); 
    }

    free(pt_bitmap); 
  }

  return ul_return;
}

// Init OpenGL Perspective View

void initPerspectiveView (void)
{
  glClearDepth(1.0); 
  glEnable(GL_DEPTH_TEST); 
  glDepthFunc(GL_LESS); 

  glEnable (GL_BLEND); 
  glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

  glShadeModel(GL_SMOOTH); 

  glEnable (GL_TEXTURE_2D);
  glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);

  glDisable (GL_TEXTURE_GEN_Q);
  glDisable (GL_TEXTURE_GEN_R);
  glDisable (GL_TEXTURE_GEN_S);
  glDisable (GL_TEXTURE_GEN_T);

  glViewport (mk_displaySize.left, mk_displaySize.top, mk_displaySize.get_width (), mk_displaySize.get_height ());

  glMatrixMode(GL_TEXTURE);
  glLoadIdentity();

  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();

  gluPerspective(45.0f, (GLfloat)mk_displaySize.get_width () / (GLfloat) mk_displaySize.get_height (), 0.1f, 100.0f);

  /*
    Does glMatrixMode(GL_MODELVIEW);
    glLoadIdentity ();
    gluLookAt (...);
  */
  mk_camera.setup_modelview ();

  glClearColor (0.0, 0.0, 0.0, 1.0);
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 
}

// And finally we draw the quad

void draw (void)
{
  if (!b_textureLoaded)
  {
    ul_id =loadTexture ("brick.bmp");

    b_textureLoaded = true;
  }

  initPerspectiveView ();

  glPushMatrix ();

    glBindTexture(GL_TEXTURE_2D, ul_id);

    glBegin (GL_QUADS);
      glTexCoord2d(0.0f, 0.0f); glVertex3d(10.0f, 0.0f, -10.0f);
      glTexCoord2d(1.0f, 0.0f); glVertex3d(10.0f, 0.0f, -10.0f);
      glTexCoord2d(1.0f, 1.0f); glVertex3d(10.0f, 0.0f, 10.0f);
      glTexCoord2d(0.0f, 1.0f); glVertex3d(-10.0f, 0.0f, 10.0f);
    glEnd ();

  glPopMatrix ();

  glFlush ();
}

As you can see I tried to disable Autogeneration of texture coordinates and reseted the texture
matrix. But this didn’t help.

Here’s a screenshot of the rendered quad and the texture I’m using:

Thx for any help,

Andre

Looks like a data alignement issue. Are you sure your texture has only 3 components per pixel? Or maybe it is due to some padding at the end of each row. Is your texture stored in .bmp format?

Yes… it’S a .bmp

It’s the one you see in my first post.
but that shouldn’t be the problem, because
I have an example which uses this file and
displays everthing right…

Andre

Okay your bmp is correct so there should be no surprise here.

But re-reading your code more carefully, I think I found something interesting:

glBegin (GL_QUADS);
glTexCoord2d(0.0f, 0.0f); glVertex3d(10.0f, 0.0f, -10.0f);
glTexCoord2d(1.0f, 0.0f); glVertex3d(10.0f, 0.0f, -10.0f);

The two first vertices are identical.
Also I find a bit strange that you explicitly supply floats to glVertex3d and glTexCoord2d

edit : fixed UBB code

i dont think you loaded the bmp correctly. The file itself is fine, but your program’s interpretation is not, as far as I can tell.