Multitexturing does not works

Hello.
I use multitexturing as described in tutorials:
At first, I declare function’s pointers as globals:

PFNGLACTIVETEXTUREARBPROC glActiveTextureARB;
PFNGLMULTITEXCOORD2FARBPROC glMultiTexCoord2f;

Then, I initialize them:

glActiveTextureARB = (PFNGLACTIVETEXTUREARBPROC)wglGetProcAddress ("glActiveTextureARB");
glMultiTexCoord2f = (PFNGLMULTITEXCOORD2FARBPROC) wglGetProcAddress("glMultiTexCoord2fARB");

Loading texture as GL_TEXTURE0_ARB

glGenTextures(1, &unTexture[0]);
glBindTexture(GL_TEXTURE_2D, unTexture[0]);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, imageWidth, imageHeight, 0, GL_RGB, GL_UNSIGNED_BYTE, ilGetData());

glActiveTextureARB(GL_TEXTURE0_ARB);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, unTexture[0]);

And mapping texture to polygon:

glActiveTextureARB(GL_TEXTURE0_ARB);
glBindTexture(GL_TEXTURE_2D, unTexture[0]);
glEnable(GL_TEXTURE_2D);
glBegin(GL_QUADS);
glMultiTexCoord2f(GL_TEXTURE0_ARB, 1, 1);
glTexCoord2f(1, 1);
glVertex3d(1, 1, 1);
glMultiTexCoord2f(GL_TEXTURE0_ARB, 1, 0);
glTexCoord2f(1, 0);
glVertex3d(1, 0, 1);
glMultiTexCoord2f(GL_TEXTURE0_ARB, 0, 0);
glTexCoord2f(0, 0);
glVertex3d(-1, 0, 1);
glMultiTexCoord2f(GL_TEXTURE0_ARB, 0, 1);
glTexCoord2f(0, 1);
glVertex3d(-1, 1, 1);
glEnd();
glDisable(GL_TEXTURE_2D);

I checked up returned by wglGetProcAddress() - they are not NULL.
But texture mapping does not works at all. But if replace "unTexture[0] by “0” (which is the default texture) it works, but, of course, only for one texture. It looks like my video card does not support multitexturing (but it does).
Tell me, please, what can be wrong?

Maybe I am wrong, but I did think it is possible to use glMultiTexCoord* and glTexCoord* at the same time. If I wanted to map 2 textures with 2 texture units 0 and 1.
Actually, what is the matter glTexCoord* calls in your code?

You should:

  • active TU0
    – bind texture
    – enable 2D texturing

  • active TU1
    – bind texture
    – enable 2D texturing

    • set texture coordinates for TU0 (glMultiTexCoord)
    • set texture coordinates for TU1 (glMultiTexCoord)
      – draw polygons
  • active TU0
    – disable 2D texturing

  • active TU1
    – disable 2D texturing

I do so:

void LoadTexture(char *imageName)
{
	ilLoadImage(imageName);
	int imageWidth = ilGetInteger(IL_IMAGE_WIDTH);
	int imageHeight = ilGetInteger(IL_IMAGE_HEIGHT);
	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, imageWidth, imageHeight, 0, GL_BGR, GL_UNSIGNED_BYTE, ilGetData());
	ilDeleteImage(0);
}

Loading texture:

LoadTexture("CatEye.bmp");
glActiveTextureARB(GL_TEXTURE0_ARB);
glBindTexture(GL_TEXTURE_2D, 0);
glEnable(GL_TEXTURE_2D);

And mapping texture:

glEnable(GL_TEXTURE_2D);
glBegin(GL_QUADS);
glMultiTexCoord2f(GL_TEXTURE0_ARB, 1, 1);
glVertex3d(1, 1, 1);
glMultiTexCoord2f(GL_TEXTURE0_ARB, 1, 0);
glVertex3d(1, 0, 1);
glMultiTexCoord2f(GL_TEXTURE0_ARB, 0, 0);
glVertex3d(-1, 0, 1);
glMultiTexCoord2f(GL_TEXTURE0_ARB, 0, 1);
glVertex3d(-1, 1, 1);
glEnd();
glDisable(GL_TEXTURE_2D);

It works only for GL_TEXTURE0_ARB. If replace it by some other value in loading and mapping, it will not work. And program always tries to use last loaded texture and it does not make a difference wich GL_TEXTUREX_ARB I use.
What’s wrong?
And it would be perfect to look at a working example.

If I assume you want to apply 2 textures on a polygon, what do you do with these textures? Do you blend, add, … them?
You can configure this with:
glTexEnv

Or use a shader.

At least, I want to map textures to a difference polygons which must be rendered in the scene at the same moment. My scene requires 3 textures and without multitexturing I must to load them every 1/45 seconds - that’s what I do now. But my video card supports 8 simultaneous 2048:2048 textures, what’s would be more preferably to use multitexturing. But I can’t!
What’s the problem? (Code is the same as above).

Post a small, compilable test program, and I bet someone will have time to take a look at it.

And it would be perfect to look at a working example.

The OpenGL red book probably has some. They’re all over the net as well:

Just google for OpenGL multitexturing.

Multitexturing isn’t that different from single texturing. You set up and bind your textures to texture units in the same way. You enable the right texture units, set how you want them to “combine” with each other, and render.

However, your last post suggests you don’t really want multitexturing (multiple textures applied to one polygon), but rather would just like to try and minimize texture binds by binding, say, the next 8, and then just render a bunch of polys, each of which uses only 1 of the 8 textures. Is this what you’re trying to do? If so, you need shaders.

Again, a small compilable test program would do wonders for clarity and understanding. Sample glGetError() after each call and make sure you’ve got GL_NO_ERROR. Then post it if you don’t figure it out.

glBindTexture(GL_TEXTURE_2D, 0)

So you unbind the texture here? Or is it a typo?

I don’t really know much about multitexturing or ARB combiners, as I never learned them (who would, if you have shaders), but AFAIK the multitexture is applied in layers. That is, you combine the results from texture 0 with texture 1, texture 2 etc. If you just enable texture 1 without enabling the 0, it probably won’t work (speculation!). Try using two textures.

What’s the shaders in a short words? Can it serve as equivalent of multitexturing?

Shaders are small programs that run on GPU and allow you do all sorts of things, for example, combine as much textures as you want in a way you want :slight_smile:

Mmm… Ok, anyway, is it preferably to use multitexturing or “Shaders” can substitute it?

shaders all the way.
The driver “emulates” multitexturing by composing a shader :slight_smile:

The classical multitexturing became obsolete years ago already. As Illian says, moders hardware is very flexible (=programmable), so the classic old stuff liek vertex lighting, multitexture, fog usw. is all emulated using driver-own GPU programms (=shaders)

Does it mean that it is possibly to use “shaders” and forget about so functions as “glActiveTextureARB”?

No, you still need to use texture units to bind more than one texture at once and you still need to specify texture coordinates per unit (if they are different).
But with a shader, you don’t have to enable/disable 2D texturing for each unit, you simply bind one texture to the TU you want.

In the shader code, you can very simply do all kind of texture blending or other operations per fragment.

For more information about glsl shaders read this good tutorial:

glsl lighthouse 3D tutorial

Then you will love shaders. :slight_smile:

Just draw polygon A with texture A bound. Then draw polygon B with texture B bound. I don’t think you need multitexturing or shaders to do as you describe.

  • Chris

But to draw a textured polygon it’s need to have the loaded texture. Problem is that loading texture works only if to load that as defalut texture (0). If I’ll try to load texture as glBindTexture(, not zero); it will not map :(.

Again, post a short test program.

And as everyone suggested, unless you have to use multitexturing, consider shaders. They’re much more flexible. OTOH, if you just want to multiply two textures in the fragment shader with your interpolated lighting color (or something equally simple and supported by multitexturing), you’re gonna get a coded solution faster with multitexturing.

Post your short test program and we’ll fix you up.

You can create multiple texture objects and only use one texture unit. No need to call glActiveTexture(). Using multiple textures is different from multitexturing.


  GLuint tex_ids[2];
  glGenTextures(2, tex_ids);
  // setup textures

  glBindTexture(GL_TEXTURE_2D, tex_ids[0]);
  // draw first polygon

  glBindTexture(GL_TEXTURE_2D, tex_ids[1]);
  // draw second polygon

I didn’t gather from your problem description that you were trying to combine two textures on one polygon, but just that you had separate textures for separate polygons.

  • Chris