Multiple textures for objects


I have an object loaded into memory and the object has more than one texture for it. So some polygons have texture1 assign to it, and some polygons have texture2 assigned to it.

I have wrote up the code that draws the model and determines what polygon needs which texture but im having a problem.

At first, between my glBegin and glEnd, i looped through every polygon and drew it on screen, but it turns out i cant use glBindTexture between glBegin and glEnd to change the texture for the polygon.

The only way ive managed to get this working, is to put glBegin and glEnd just before and after a single polygon to be drawn, instead of the whole lot. Then i can glBindTexture to change the active texture to draw with.

Is that an effient way at doing that?
Is there any ther way i can do this?

Also, is it possible to put the object into a display list? with texture information for each polygon?


Just sort the polygons by texture. Then do this:

Bind the first texture.
Draw all polygons that need that texture.
Bind the second texture.
Draw the rest of the polygons.

Sorting geometry by GL state is a pretty common technique.