I am having a problem displaying my texture using a quad. If I draw it using glDrawPixels, its ok. I would rather use a quad since it is more flexible. The pixel data is stored in an array as unsigned chars.
Below is the code snippets. Can anyone tell me what I am doing wrong? Thanks!
// generate a 2d texture image from an arary
pBitmap->w = (int)array[0]; // first 2 entries hold width & height.
pBitmap->h = (int)array[1];
pBitmap->pixels = &array[2];
glGenTextures( 1, &(pBitmap->texId) );
glBindTexture(GL_TEXTURE_2D, pBitmap->texId );
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, pBitmap->w, pBitmap->h, 0, GL_RGB, GL_UNSIGNED_BYTE, pBitmap->pixels );
// draw a texture (2d) x axis acoss, y axis down
#if 1
glRasterPos2f( (float)x+.5, (float)y + (float)pBitmap->h + .5);
glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
glDrawPixels( pBitmap->w, pBitmap->h, GL_RGB, GL_UNSIGNED_BYTE, pBitmap->pixels );
#else
glEnable( GL_TEXTURE_2D );
glBindTexture( GL_TEXTURE_2D, pBitmap->texId );
glColor4f( 1.0f, 1.0f, 1.0f, 1.0f );
glBegin( GL_QUADS);
// Bottom Left
glTexCoord2f( 0, 0 );
glVertex2i( x, y );
// Top left
glTexCoord2f( 0, 1 );
glVertex2i( x, y+h );
// Top right
glTexCoord2f( 1, 1 );
glVertex2i( x+w, y+h );
// Bottom right
glTexCoord2f( 1 , 0 );
glVertex2i( x+w, y );
glEnd();
glDisable( GL_TEXTURE_2D );
#endif