PDA

View Full Version : Multi-texture combining problem (glTexEnv)



Tiedye
10-20-2013, 06:20 PM
I'm am trying to combine 3 textures using the glTexEnv method. Like it is done on the opengl wiki (google: Opengl texture combiners, first link) except with 3 texture instead of 2 textures and a constant.



glActiveTexture(GL_TEXTURE0);

glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);

glActiveTexture(GL_TEXTURE1);

glMatrixMode(GL_TEXTURE); // |- This allows me to access the texture via SHORT coordinates, you can ignore it
glLoadIdentity(); // |
float var3 = 0.00390625F; // |
glScalef(var3, var3, var3); // |
glTranslatef(8.0F, 8.0F, 8.0F); // |
glMatrixMode(GL_MODELVIEW); // |

glBindTexture(GL11.GL_TEXTURE_2D, textureOne);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);

glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
glEnable(GL_TEXTURE_2D);

glActiveTexture(GL_TEXTURE2);

glMatrixMode(GL_TEXTURE);
glLoadIdentity();
var3 = 0.00390625F;
glScalef(var3, var3, var3);
glTranslatef(8.0F, 8.0F, 8.0F);
glMatrixMode(GL_MODELVIEW);

glBindTexture(GL11.GL_TEXTURE_2D, textureTwo);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);

glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_ADD);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB, GL_PREVIOUS);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB, GL_TEXTURE);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_SRC_COLOR);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB, GL_SRC_COLOR);

glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_ADD);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA, GL_PREVIOUS);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_ALPHA, GL_TEXTURE);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA, GL_SRC_ALPHA);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_ALPHA, GL_SRC_ALPHA);
glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
glEnable(GL_TEXTURE_2D);

glActiveTexture(GL_TEXTURE3);
int tex; // This I'm not sure about. How does one crate a "dummy" texture like on the wiki page (see last example)
tex = glGenTextures();
glBindTexture(GL_TEXTURE_2D, tex);

glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_REPLACE);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB, OpenGlHelper.defaultTexUnit);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB, OpenGlHelper.lightmapTexUnitBlock);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_SRC_COLOR);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB, GL_SRC_COLOR);

glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_REPLACE);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA, OpenGlHelper.defaultTexUnit);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_ALPHA, OpenGlHelper.lightmapTexUnitBlock);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA, GL_SRC_ALPHA);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_ALPHA, GL_SRC_ALPHA);
glEnable(GL_TEXTURE_2D);

glActiveTexture(GL_TEXTURE0);

If you must know what I'm trying to do, I'm making a mod for minecraft that makes it use two lighmaps instead of one, and eventually four.

What I excpect to happen:
1. TEXTURE0 is set to the texture (bound elsewhere) multiplied by the colour value, that why GL_MODULATE and not GL_REPLACE
2. TEXTURE1 is set to textureOne
3. TEXTURE2 is set to textureTwo + TEXTURE1
4. TEXTURE3 is set to TEXTURE0 * TEXTURE2
5. TEXTURE3 should be the final texture that is rendered

What happens:
TEXTURE2 ends up being rendered and TEXTURE3 is ignored thus TEXTURE0 also is not displayed.

When I remove all but TEXTURE0, TEXTURE0 renders as it should, so all the textures are there, but I still don't know if I'm doing the dummy texture thing right.

I'm very new and there's bound to be some stupid mistake(s) in this. If you need more information just ask! By the way I'm using Java not C++ (the lwjgl library, I removed the GL11. and GL13. bits to make it more legible).

EDIT: Also if anyone can offer any help about how to go about this with legacy shaders it would also be appreciated!