Error in OpenGL??

Hello,

when i experimented with Mipmaps, I found out, that there seems to be a problem with 2-pixel-wide RGB-textures. The following Code should show a red rectangle. But if the Texture has a width of 2 and not using the alpha-byte the color is scrambled. Is there anything wrong in my code?

the code:

//Author : Stefan Preuss
//email: stpreuss@ira.uka.de
//*****************************
// Seems that OpenGL can’t handle textures of width 2.
// Is that a bug or a feature?
// Normally no one would use such a small texture,
// but if you want use mipmaps (not the automatic generated ones with
// gluBuild2dMipmaps) it would be nice to use 2-pixel bitmaps

//Error occured on:
// OS, IDE, CPU, GPU
//WindowsXP, Visual Studio 6, Pentium3, SiS630
//WindowsXP, Visual Studio 6, Dual Athlon, NVIDIA GeForce4 Ti 4200
//Linux, Gideon(qMake), Pentium 4, NVIDIA GeForce4 Ti 4200
//MacOS X, ??, G5, ??
//Windows2000, Visual Studio 6, Pentium3, NVIDIA Geforce2
//Windows XP, Visual Studio .NET, Pentium3 m, SiS 630

#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glut.h>

GLuint texNumber =0;
GLubyte* p_texture; //Texturemap

//*************************************************
//False Textures if width of the texture is 2 or 1
//*************************************************
int texX=2; //width of the texture
int texY=16; //height of the texture

void callBackDipsplayFunc()
{
glMatrixMode(GL_MODELVIEW);

//set clear color
glClearColor(0.0f, 0.0f, 0.0f, 1.0f); //schwarz
//clear frame and z -Buffer
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

//activate Texture
glEnable(GL_TEXTURE_2D);

// set texture to be not blended

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);

// fill texture with pixel information from the rgb image

glTexImage2D(GL_TEXTURE_2D, // target
0, // MIPMAP level
3, // color components
texX, // texture width
texY, // texture height
0, // border
GL_RGB, // format
GL_UNSIGNED_BYTE, // type of one component
(GLvoid*) p_texture); // pixel buffer

glBegin(GL_QUADS);
//glColor3d(0.0, 1.0, 0.0);

  glTexCoord2d ( 0.0, 0.0);
  glVertex3d   (-1.0,-1.0, 5.0);

  glTexCoord2d ( 1.0, 0.0);
  glVertex3d   ( 1.0,-1.0, 5.0);

  glTexCoord2d ( 1.0, 1.0);
  glVertex3d   ( 1.0, 1.0, 5.0);

  glTexCoord2d ( 0.0, 1.0);
  glVertex3d   (-1.0, 1.0, 5.0);

glEnd();

//Flush the Drawing commands
glFlush();
//show back buffer
glutSwapBuffers();

}

void callBackReshapeFunc(int newWidth, int newHeight)
{
if(newHeight==0){newHeight=1;}
GLdouble aspect=(GLdouble)newWidth/(GLdouble)newHeight;

glMatrixMode(GL_PROJECTION);
glLoadIdentity();

// set output dimensions
glViewport(0,0, (GLint)newWidth, (GLint)newHeight);

//set perspective projection matrix
gluPerspective( 50.0,aspect,1.0,20.0);

}

int main(int argc, char* argv)
{

//******************
//initialize Texture
//******************

//RGB-texture
p_texture = new unsigned char[texXtexY3];

//fill all pixel unicolor
for (int index=0;index<texXtexY3;index=index+3)
{
p_texture[index] =255; //red
p_texture[index+1] = 0; //green
p_texture[index+2] = 0; //blue
}

//********************
//activate Glut System
//********************

//set active buffers
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);

//create render window
int windowID = glutCreateWindow(“Error?”);

//set callbacks
glutDisplayFunc(callBackDipsplayFunc);
glutReshapeFunc(callBackReshapeFunc);

//************
//setup OpenGL
//************

//-----------
//set render Parameters
//activate z-Buffer
glEnable(GL_DEPTH_TEST);

//-------------------
//set camera position
//-------------------

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(0.0, 0.0, 10.0,
0.0, 0.0, 0.0,
0.0, 1.0, 0.0);

//********
//run!
//********

//DoModal
glutMainLoop();

//***********
//cleaning up
//***********
delete p_texture;

return 0;
}

[This message has been edited by dorbie (edited 01-19-2004).]

Have a look at:
glPixelStorei(GL_PACK_ALIGNMENT, align);
and
glPixelStorei(GL_UNPACK_ALIGNMENT, align);