I work on Windows XP and use glut. I don’t understand behaviour of my program. Below I list most important:
I defined two function :
void setTexture(GLuint textureName, GLubyte *data)
{
glBindTexture(GL_TEXTURE_2D, textureName);
glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
glPixelStorei(GL_UNPACK_SKIP_ROWS, 0);
glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexEnvi(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_MODULATE );
glTexImage2D(GL_TEXTURE_2D,0,4,N,N,0,GL_RGBA,GL_UNSIGNED_BYTE,data);
}
( N is defined bofore: const int N = 128)
and the second one :
void drawTexture(GLuint textureName, GLint position, GLfloat colour)
{
glBindTexture(GL_TEXTURE_2D,textureName);
glEnable(GL_TEXTURE_2D);
glBegin(GL_QUADS);
glColor3f(colour,0.0,0.0);
glTexCoord2f(0,0);
glVertex3i(0,0,position);
glTexCoord2f(1,0);
glVertex3i(N,0,position);
glTexCoord2f(1,1);
glVertex3i(N,N,position);
glTexCoord2f(0,1);
glVertex3i(0,N,position);
glDisable(GL_TEXTURE_2D);
}
my init() is :
void init(void)
{
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glShadeModel(GL_FLAT);
glViewport( 0, 0, N,N );
glLoadIdentity();
glMatrixMode( GL_PROJECTION );
glLoadIdentity();
glOrtho( 0, N, 0, N, -256, 256 );
glMatrixMode( GL_MODELVIEW );
glLoadIdentity();
}
my display function is :
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glEnable(GL_DEPTH_TEST);
glEnable(GL_BLEND);
glBlendFunc(GL_ONE,GL_ONE);
GLuint textureNames[2];
glGenTextures(2,textureNames);
GLubyte *shoe; //triangle is texture date which drawn a shoe for example
GLubyte *flower; ////triangle is texture date which drawn a flower for example
setTexture(textureNames[0],shoe);
setTexture(textureNames[1],flower);
//below is code I have problem:
drawTexture(textureNames[3],1,0.0f);
drawTexture(textureNames[3],2,1.0f);
/* if write it the output will be the same:
drawTexture(textureNames[3],1,1.0f);
drawTexture(textureNames[3],2,0.0f);
*/
glDisable(GL_BLEND);
glEnd();
glFlush();
}
I see always shoe - i don’t understant why.
the pointer shoe and flower is ok, if i comment
//drawTexture(textureNames[3],0,0.0f);
the output will be flower.
I really don’t understand what’s wrong is ? Propobly is stupid mistake. Thanks for any help, and any comments.