# OpenGL opengl multitexture help (dot3)

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

## Recommended Posts

Hi all, I'm trying to port an old game of mine to an openGL ES device. I'm new to multitexturing but I've found very good tutorials on the net, so I understand it well, but I lack the experience when I see "weird things" in some codes :) I'm trying to use a dot3, and I'm using the following code as a sample

PVRTVECTOR3 fLightVector;

/*
Set up the light vector and rotate it round the cube.
*/
fLightVector.x = PVRTSIN(f2vt(m_fAngle * (PVRTPIf / 180.0f)));
fLightVector.y = f2vt(0.0f);
fLightVector.z = PVRTCOS(f2vt(m_fAngle * (PVRTPIf / 180.0f)));

/* Half shifting to have a value between 0.0f and 1.0f */
fLightVector.x = VERTTYPEMUL(fLightVector.x, f2vt(0.5f)) + f2vt(0.5f);
fLightVector.y = VERTTYPEMUL(fLightVector.y, f2vt(0.5f)) + f2vt(0.5f);
fLightVector.z = VERTTYPEMUL(fLightVector.z, f2vt(0.5f)) + f2vt(0.5f);

/* Set light direction as a colour
* (the colour ordering depend on how the normal map has been computed)
* red=y, green=z, blue=x */
myglColor4(fLightVector.y, fLightVector.z, fLightVector.x, 0);

/*
Set up the First Texture (the normal map) and combine it with the texture
colour that we've set.
*/
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, m_ui32Stampnm);

myglTexEnv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
myglTexEnv(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_DOT3_RGBA);
myglTexEnv(GL_TEXTURE_ENV, GL_SOURCE0_RGB, GL_TEXTURE);
myglTexEnv(GL_TEXTURE_ENV, GL_SOURCE1_RGB, GL_PREVIOUS);

/* Set up the Second Texture and combine it with the result of the Dot3 combination*/
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, m_ui32Crate);

/* Set the texture environment mode for this texture to combine */
myglTexEnv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);

/* Set the method we're going to combine the two textures by. */
myglTexEnv(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_MODULATE);

/* Use the previous combine texture as source 0*/
myglTexEnv(GL_TEXTURE_ENV, GL_SOURCE0_RGB, GL_TEXTURE);

/* Use the current texture as source 1 */
myglTexEnv(GL_TEXTURE_ENV, GL_SOURCE1_RGB, GL_PREVIOUS);

/*
Set what we will operate on, in this case we are going to use
just the texture colours.
*/
myglTexEnv(GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_SRC_COLOR);
myglTexEnv(GL_TEXTURE_ENV, GL_OPERAND1_RGB, GL_SRC_COLOR);

/* Draw mesh */
glDrawElements(GL_TRIANGLES, 36, GL_UNSIGNED_SHORT, &m_sCube.ui16Faces[0]);

// Reset
myglColor4(f2vt(1.0),f2vt(1.0),f2vt(1.0),f2vt(1.0));


The code is taken from imgtec.com site, powerVR creators, exactly from the openGL ES SDK 1.1 which can be downloaded from the site. They're using macros to switch betweeen common and common-lite profiles, so myglTexEnv is glTexEnvf or glTexEnvx depending on the profile, and so on. There is a thing I can't understand, and it's the first time this line appears: myglTexEnv(GL_TEXTURE_ENV, GL_SOURCE1_RGB, GL_PREVIOUS); It's using the "previous" texture in the first stage. What does exactly mean this? There's no such texture (or it's just the background of the current scene?) I've been playing with the code and searching more examples in the net, and I've come with this version:
	glActiveTexture(GL_TEXTURE0);
glEnable (GL_TEXTURE_2D);
dot3texture.use();

glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
glTexEnvx(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_DOT3_RGB);
glTexEnvx(GL_TEXTURE_ENV, GL_SOURCE0_RGB, GL_TEXTURE);
glTexEnvx(GL_TEXTURE_ENV, GL_SOURCE1_RGB, GL_PRIMARY_COLOR);

// Set up the Second Texture and combine it with the result of the Dot3 combination
glActiveTexture(GL_TEXTURE1);
glEnable (GL_TEXTURE_2D);
mg-&gt;mat-&gt;tex.bind();

// Set the texture environment mode for this texture to combine
glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);

// Set the method we're going to combine the two textures by.

// Use the previous combine texture as source 0
glTexEnvx(GL_TEXTURE_ENV, GL_SOURCE0_RGB, GL_TEXTURE);

// Use the current texture as source 1
glTexEnvx(GL_TEXTURE_ENV, GL_SOURCE1_RGB, GL_PREVIOUS);

// Set what we will operate on, in this case we are going to use
// just the texture colours.
glTexEnvx(GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_SRC_COLOR);
glTexEnvx(GL_TEXTURE_ENV, GL_OPERAND1_RGB, GL_SRC_COLOR);
dot3Mode=1;
nTextures=2;


which I understand better (as no GL_PREVIOUS is used in the first stage), but I fail to know where the GL_PRIMARY_COLOR is taken from, because glColor4x value should be used for the normal, isn't it? (which anyways, I can't make it work but that's something I haven't had a deep look at it yet, so better a problem at a time) This last version does a nice work, it seems like dot3 is working, but I have an undesirable effect used in combination with lightning. The dark zones of the room are even darker with the dot3 active, and the lit zones of the room are "leaning towards saturation" despites they don't saturate, but they are getting an extra amount of white which I don't like (I don't know exactly how to say it , I'll try to post an image when I'm back at home) Is the light vector sent to the dot3 transformed by the modelview matrix? And last but not least, as you have far more experience than my 2-days self-teaching class on multitexture :) , which should be the best way (operations, operands, ...) to integrate a bumped object into a real environment with lightning? p.s. I only have a 2 layers multitexture, it's supposed to work on a x50v (with a 2700g, powerVR MBX) Thanks for reading :) Kak [Edited by - Kak2 on February 13, 2008 2:23:36 AM]

##### Share on other sites
well, I've been playing a bit more with the code, it seems that GL_ADD_SIGNED as operation works better (despite I'm not getting the effect I'd like to get), and I have no idea about the GL_PREVIOUS bit but source1 is in fact the vector which must be multiplied by the normal texture, so GL_PRIMARY_COLOR seems to be the correct choice.

Unfortunately I still have the problem that no matter how I change the normalized src1 vector, the result of the dot3 texture is always the same,
and lightning acts weird when multitexturing (i.e. it seems like glMaterial calls are completely ignored if I use multitexturing)

##### Share on other sites
Well, it seems I've reached a conclusion which I don't know if it's correct about dot3 light vector not working.

The documentation says that you must use glColor4x in order to specify the light vector used to compute the dot3 between light vector & texture. However, the dot3 uses as sources:

	glTexEnvx(GL_TEXTURE_ENV, GL_SOURCE0_RGB, GL_TEXTURE);	glTexEnvx(GL_TEXTURE_ENV, GL_SOURCE1_RGB, GL_PRIMARY_COLOR);

GL_PRIMARY_COLOR, being "the untextured fragment color from the primitive", means that he's taking the value passed by glColor4x, however if I turn on the lights, that fragment color stops being the glColor4x one and is the value of that fragment which is computed via the per-vertex openGL lightning model.

PowerVR samples that have a working dot3 code, but they fail if I turn on the lights.

Could somebody confirm that this is a correct deduction, please?

1. 1
2. 2
3. 3
Rutin
22
4. 4
5. 5

• 9
• 13
• 19
• 14
• 9
• ### Forum Statistics

• Total Topics
632940
• Total Posts
3009324
• ### Who's Online (See full list)

There are no registered users currently online

×