I can't get multiple Textures to work

Can someone tell me why I can’t get textures to work? I have loaded two textures into OpenGL, they both load fine, no errors, and return different ID’s.

The problem is, that only the first texture bound actually renders, when I bind the second, nothing happens.

Have you tried using both of them alone, so you know the second texture is working?

Anyways, you need to enable texturing for every texture unit you intend to use.

glActiveTextureARB(GL_TEXTURE0_ARB);
glBindTexture(GL_TEXTURE_2D, tex1);
glEnable(GL_TEXTURE_2D);
glActiveTextureARB(GL_TEXTURE1_ARB);
glBindTexture(GL_TEXTURE_2D, tex2);
glEnable(GL_TEXTURE_2D);

is the code I use to enable two textures for multitexturing. tex1 and tex2 is my texture id’s unless you didn’t figured that out

You also need to specify texture coordinates for each texture unit for each vertex.

glMultiTexCoord2fARB(GL_TEXTURE0_ARB,0,0);
glMultiTexCoord2fARB(GL_TEXTURE1_ARB,s,t);

In this piece of code, i set the two coordinates. The first one is static coordinates, and the other one is variable coordinates (it’s from a testprogram I made to try multitexturing).

And don’t forget to disablt the texture unit you don’t use when you are done, because they can give you some hard-to-find problem if they are left turned on by accident.

[This message has been edited by Bob (edited 09-22-2000).]

Hi there, glActiveTextureARB doesn’t seem to be in my OpenGL method list. I am using a plugin for REALbasic, which is a bit like VisualBasic. If its in the Mac OpenGL lib files I could access it via the toolbox however.

Also, if you take away the glActiveTextureARB methods, then you end up with code very similar to what I was using. I am not sure exactly whats going wrong here, maybe its something in my complicated object oriented OpenGL classes I’ve been writing. Or maybe I just sent some odd command somewhere in the initialisation thats only letting me use one texture? Before I was sending an invalid enum to glDepthFunc, and I was getting all sorts of wierd behaviour when trying to enable and disable GL_DEPTH_TEST

I guess you can get the picture that I am a GL Newbie (

Thanks for the help!

glActiveTextureARB and glMultiTexCoord2fARB are extension functions (unless you are using OpenGL 1.2, then you can remove the ARB-part and there should be no probmels). You need to obtain these in one way or another. Dunno how this works in BASIC environment. But honestly, if you are a newbie, I relly think you should wait with multitexturing untill you know how OpenGL works on a slightly deeper level. No offense, but starting as deep as multitexturing at newbielevel is a bit too mush.

Just a thought, BoyTheo, are you having trouble putting more than one texture on a single polygon, or just having trouble putting different textures(multitexturing) on different polygons(using multiple textures)?

First, thanks to the person who told me to wait. I am finding OpenGL pretty deep and tricky to work out, so much to learn.

Also, to BwB, I am trying to put one texture onto one quad, and a different texture onto a different quad. I haven’t ever tried to put two textures onto the same quad.

Aha, two different quads with it’s own texture. Sorry, but I thought you wanted two textures on the same primitive

Then there should be no problems. You just have to bind each texture before drawing a new quad.

// bind first texture and start a new quad
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, tex1);
glBegin(GL_QUADS);
// pass four vertices with texture coordinates
glTexCoord(…);
glVertex(…);

glEnd();

glBindTexture(tex2);
glBegin(GL_QUADS);
// a new quad with other coordinates
glTexCoord(…);
glVertex(…);
glEnd();

With proper modelview matrix and projection matrix, this should do. One mistake you might do can be that you bind a new texture between a glBegin/glEnd pair, which is forbidden.

How does one use Multitexture with Vertex Arrays? Do we still use “glTexCoordPointer()” or something?

Yes, you can. The texture unit that is activaded when calling glTexCoordPointer is the texture using that will use the specified texture pointer.

So calling

glActiveTextureARB(GL_TEXTURE0_ARB);
glTExCoordPointer(…, tc0,…);
glActiveTextureARB(GL_TEXTURE1_ARB);
glTExCoordPointer(…, tc1,…);

will cause texture unit 0 to use tc0 as texture pointer, and unit 1 will use tc1 as pointer.

Same thing wth texture coordinate generation. You have to enable generation for each texture unit you want to use. Usefull if you got a metallic sphere. Pass your own texture coordinates to one unit, and generate sphere mapping on the other one for example.