I’m having trouble trying to use the multitexture extension.
I know my particular implementation supports multitextures with 2 textures.
What I don’t understand is what is the actual point of using multiple textures?
Basically, can I overlay more than one texture on top of each other on the same quad, so that the first texture is applied to each pixel, then the second texture is applied to each pixel of the first texture?
I just can’t seem to get a sensible result, I either get one texture showing up, or I get a blank quad. I’m trying to follow along with someone’s C code, and it seems I have done everything the way they did, from init to rendering, and it only seems to work when I apply just one texture.
Either texture works by itself, so the actual texture data is ok.
The first texture is a gradient is from blue at the bottom to red at the top, using RGB. The second texture is a checkerboard that contains two gray areas in the upper right and bottom left corners, the other two corners are black, using RGBA, with an alpha value of 128.
Any advice?
Here is the code:
Initialisation:
// ByteBuffer buff = 64 x 64 gradient texture
ByteBuffer byteBuffer = ByteBuffer.allocateDirect(64);
IntBuffer intBuffer = byteBuffer.asIntBuffer();
textureIDs = new int[2];
GL.glGenTextures(intBuffer);
textureIDs[0] = intBuffer.get(0);
GL.glBindTexture(GL11.GL_TEXTURE_2D, textureIDs[0]);
GL.glTexImage2D(
GL11.GL_TEXTURE_2D,
0, 3,
64, 64,
0,
GL11.GL_RGB,
GL11.GL_UNSIGNED_BYTE,
buff
);
GL.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST);
GL.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);
GL.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL11.GL_REPEAT);
GL.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL11.GL_REPEAT);
GL.glTexEnvf(GL11.GL_TEXTURE_ENV, GL11.GL_TEXTURE_ENV_MODE, GL11.GL_REPLACE);
// ByteBuffer buff = 64 x 64 checkerboard texture
GL.glGenTextures(intBuffer);
textureIDs[1] = intBuffer.get(0);
GL.glBindTexture(GL11.GL_TEXTURE_2D, textureIDs[1]);
GL.glTexImage2D(
GL11.GL_TEXTURE_2D,
0, 4,
64, 64,
0,
GL11.GL_RGBA,
GL11.GL_UNSIGNED_BYTE,
buff
);
GL.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR);
GL.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR);
GL.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL11.GL_CLAMP);
GL.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL11.GL_CLAMP);
GL.glTexEnvf(GL11.GL_TEXTURE_ENV, GL11.GL_TEXTURE_ENV_MODE, GL11.GL_MODULATE);
Rendering:
GL.glActiveTextureARB(GL13.GL_TEXTURE0);
GL.glEnable(GL11.GL_TEXTURE_2D);
GL.glMatrixMode(GL11.GL_TEXTURE);
GL.glLoadIdentity();
GL.glMatrixMode(GL11.GL_MODELVIEW);
GL.glActiveTextureARB(GL13.GL_TEXTURE1);
GL.glEnable(GL11.GL_TEXTURE_2D);
GL.glMatrixMode(GL11.GL_TEXTURE);
GL.glLoadIdentity();
GL.glMatrixMode(GL11.GL_MODELVIEW);
GL.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
GL.glEnable(GL11.GL_BLEND);
GL.glBegin(GL11.GL_QUADS);
GL.glColor4f(0.0f, 0.0f, 0.0f, 1.0f);
GL.glMultiTexCoord2fARB(GL13.GL_TEXTURE0, 0.0f, 0.0f);
GL.glMultiTexCoord2fARB(GL13.GL_TEXTURE1, 0.0f, 0.0f);
GL.glVertex2i(200, 200);
GL.glMultiTexCoord2fARB(GL13.GL_TEXTURE0, 0.0f, 1.0f);
GL.glMultiTexCoord2fARB(GL13.GL_TEXTURE1, 0.0f, 1.0f);
GL.glVertex2i(200, 263);
GL.glMultiTexCoord2fARB(GL13.GL_TEXTURE0, 1.0f, 1.0f);
GL.glMultiTexCoord2fARB(GL13.GL_TEXTURE1, 1.0f, 1.0f);
GL.glVertex2i(263, 263);
GL.glMultiTexCoord2fARB(GL13.GL_TEXTURE0, 1.0f, 0.0f);
GL.glMultiTexCoord2fARB(GL13.GL_TEXTURE1, 1.0f, 0.0f);
GL.glVertex2i(263, 200);
GL.glEnd();
// Use reverse order here
GL.glActiveTextureARB(GL13.GL_TEXTURE1);
GL.glDisable(GL11.GL_TEXTURE_2D);
GL.glActiveTextureARB(GL13.GL_TEXTURE0);
GL.glDisable(GL11.GL_TEXTURE_2D);