Multiple quads all same texture; I don't want it

Hi,

I am trying to make a book with a different picture on each page. My only problem is that when I try to draw it, all the pages are the same texture. Here is what my code basically does

enable texturing

for loop…
bind texture on for variable
draw quad
end loop…

disable texturing

I don’t know where I am going wrong. Could somebody help me?

Nothing wrong with the pseudocode. But I guess you’re having problem with the real code, no the pseudocode, so I sugges you post that instead.

The code is somewhat long, but here it is. The part that draws all my pages is in the last for loop.

void book UINT cover,UINT sides,int pages, float turned[], UINT pimage[]
{

#define PI 3.1415926535
float front = turned[0];

glEnable GL_TEXTURE_2D ;
glBindTexture GL_TEXTURE_2D, cover ;

glBegin GL_QUADS ;
glTexCoord2f 0,0 ;
glVertex3f -1,0.25,-1 ;
glTexCoord2f 0,1 ;
glVertex3f -1,0.25,1 ;
glTexCoord2f 1,1 ;
glVertex3f sin front *2-1,cos front *2+0.25,1 ;
glTexCoord2f 1,0 ;
glVertex3f sin front *2-1,cos front *2+0.25,-1 ;

glEnd ;

glBindTexture GL_TEXTURE_2D, sides ;

glBegin GL_QUADS ;
glTexCoord2f 0,1 ;
glVertex3f -1,0.25,-1 ;
glTexCoord2f 1,1 ;
glVertex3f -1,0.25,1 ;
glTexCoord2f 1,0 );
glVertex3f -1,-0.25,1 ;
glTexCoord2f 0,0 );
glVertex3f -1,-0.25,-1 ;

glTexCoord2f 0,0 ;
glVertex3f -1,-0.25,-1 ;
glTexCoord2f 0,1 ;
glVertex3f -1,-0.25,1 ;
glTexCoord2f 1,1 ;
glVertex3f 1,-0.25,1 ;
glTexCoord2f 1,0 ;
glVertex3f 1,-0.25,-1 ;
glEnd ;

glDisable GL_TEXTURE_2D ;
glEnable GL_TEXTURE_2D ;

glBegin GL_QUADS ;
for int x = 2; x < pages+1; x++ 
{
	glBindTexture GL_TEXTURE_2D, pimage[0] ;

	glTexCoord2f 0.0,0.0 ;
	glVertex3f -1+ sin turned[pages+1-x] *0.01,   float x/ pages*2 -0.255 + cos turned[pages+1-x] *0.1, -1 ;

	glTexCoord2f 0.0,1.0 ;
	glVertex3f -1+ sinturned[pages+1-x] *0.01,   float x/ pages*2 -0.255 + cos turned[pages+1-x] *0.1, 1 ;

	glTexCoord2f 1.0,1.0 ;
	glVertex3f -1+sin turned[pages+1-x] *2,  float x/ pages*2-0.255 +cos turned[pages+1-x] *2, 1 ;

	glTexCoord2f 1,0 ;
	glVertex3f -1+sin turned[pages+1-x] *2,  float x/ pages*2 -0.255 +cos turned[pages+1-x] *2, -1 ;
}
glEnd ;
glDisable GL_TEXTURE_2D ;

}

any and all replies are greatly appreciated. thanks

the problem seems to be that you always bind the same texture- pimage[0]- in the for loop.

your code should something like this:

 GLuint texid[10];
glGenTextures(10, texid);

 // setup textures for 10 pages

 for(int i = 0; i < 10; i ++) {
  glBindTexture(GL_TEXTURE_2D, texid[i]);
  glTexImage2D(...);
  glTexParameter(...);
  glTexEnv(...); }  

// draw pages

 for(int i = 0; i < 10; i ++) {
  glBindTexture(GL_TEXTURE_2D, texid[i]);
  glBegin(GL_QUADS);
  ...
  glEnd();} 

The pimage variable had all the textures I wanted to use. The sides variable was the one on the pages that I didn’t want. I found that to bind a texture succesfully you need to bind it before the glBegin. Thanks for your help though.

glBindTexture, as with many other commands, fails if it is called within a glBegin and glEnd loop.

As mentioned by RigidBody:

Within your loop, you’re doing this:

  glBindTexture GL_TEXTURE_2D, pimage[0] ; 

Shouldn’t that be:

  glBindTexture GL_TEXTURE_2D, pimage[x] ; 
  • since x seems to be the page index?