Archived

This topic is now archived and is closed to further replies.

glBindTexture() inside of glBegin()

This topic is 5803 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

I've got a "GLuint texture[6]" globally declared and in my init function I've got a "AUX_RGBImageRec *TextureImage[6]" declared. I obviously want to load in 6 different textures and then later apply them to various quads. so I say
	for( i = 0; i < 6; i++ )
{
if( TextureImage[ i ] = LoadBMP( makeFilename( fgets( buffer, 80, file ) ) ) )
{
glGenTextures( 1, &texture[ i ] );
glBindTexture( GL_TEXTURE_2D, texture[ i ] );
glTexImage2D( GL_TEXTURE_2D, 0, 3, TextureImage[ i ]->sizeX, TextureImage[ i ]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[ i ]->data );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
}
if( TextureImage[ i ] )
{
if( TextureImage[ i ]->data )
{
free( TextureImage[0]->data );
}
free( TextureImage[ i ] );
}
}    
presuming this will load my 6 textures (from my text file) into texture[ i ], from 0 to 5. It appears to, because when I am in my display function and I say "glBindTexture( GL_TEXTURE_2D, texture[0] );" or any other texture[num] it displays the right texture, BUT only if the glBindTexture() function is outside of my glBegin() - glEnd() block. If I try to glBindTexture() inside of glBegin() it automatically uses the 6th texture, no matter what value I give it. I need to draw multiple quads, each with a different texture, in my glBegin() - glEnd() block, but it's not working... Help? Edited by - JodoKaast on March 3, 2002 9:44:31 PM

Share on other sites
From MSDN (and presumably the OpenGL 1.1 Man pages) under glBegin()/glEnd()

quote:

You can use only a subset of OpenGL functions between glBegin and glEnd. The functions you can use are:
glVertex
glColor
glIndex
glNormal
glTexCoord
glEvalCoord
glEvalPoint
glMaterial
glEdgeFlag

From the glBindTexture page in the error codes section:

GL_INVALID_OPERATION glBindTexture was called between a call to glBegin and the corresponding call to glEnd.

Perhaps you should try reading the manual in future

www.elf-stone.com

Share on other sites
Hi, you cant do that, limitaion of OpenGL, if you get the glBindTexture to return a value (ie. GLenum n=glBindTexture(...))
you''ll see its returning an error to the sounds of GL_ENUM_BLAH_BLAH, so, you get the last texture bind if ur new one fails. heres some sample code:

typedef struct
{
float p1[3], p2[3], p3[3], p4[3];
}face;
// face id "[6]" and xyz "[3]"
typedef struct {
face faces[6];
}cube = {...}; // put vert data here

for(int i=1;i<6;i++)
{
glBindTexture(GL_TEXTURE_2D,...);
glVertex3fv(&cube.faces.p1);
glVertex3fv(&cube.faces[i].p2);
glVertex3fv(&cube.faces[i].p3);
glVertex3fv(&cube.faces[i].p4);
glEnd();
}

that should work (all of the top of my head so might need debuging) you should probably download the OpenGL Platform SDK, or get it online at http://msdn.microsoft.com/library/
under Platform SDK -> Graphics -> OpenGL

if you need any more help e-mail me:silvermace007@hotmail.com
i couldn''t find any one to one help when i was learning so im helping others, dont hesitate to ask.

Danushka G[_a[)iAt()I2*
bye, hope this helps