سؤال

I followed this tutorial in order to try and achieve multitexturing in LWJGL. But whenever I run my code, the second texture does not show up, or the first texture takes its place. Here is how I bind the textures:

ARBMultitexture.glActiveTextureARB(ARBMultitexture.GL_TEXTURE0_ARB);
bindTexture(myTex);
glEnable(GL_TEXTURE_2D);
glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, EXTTextureEnvCombine.GL_COMBINE_EXT);
glTexEnvf (GL_TEXTURE_ENV,EXTTextureEnvCombine.GL_COMBINE_RGB_EXT, GL_REPLACE);
ARBMultitexture.glActiveTextureARB(ARBMultitexture.GL_TEXTURE1_ARB);
bindTexture(myTex2);
glEnable(GL_TEXTURE_2D);
glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, EXTTextureEnvCombine.GL_COMBINE_EXT);
glTexEnvf (GL_TEXTURE_ENV, EXTTextureEnvCombine.GL_COMBINE_RGB_EXT, GL_INCR);

drawStuff();

myTex and myTex2 both Textures, drawStuff() is my function where I draw everything. I use slick for loading the textures and such, here is my bindTexture function:

void bindTexture(Texture t) {
    glBindTexture(GL_TEXTURE_2D, t.getTextureID());
}

In drawStuff() I have a custom "Face" class, and here is where I draw everything in there:

glBegin(GL_TRIANGLES);
    glNormal3f(getNormal().x, getNormal().y, getNormal().z);
    glNormal3f(norm1.x, norm1.y, norm1.z);
    ARBMultitexture.glMultiTexCoord2fARB(ARBMultitexture.GL_TEXTURE0_ARB, t1.x, t1.y);
    ARBMultitexture.glMultiTexCoord2fARB(ARBMultitexture.GL_TEXTURE1_ARB, t1.x, t1.y);
    glVertex3f(p1.x, p1.y, p1.z);
    glNormal3f(norm2.x, norm2.y, norm2.z);
    ARBMultitexture.glMultiTexCoord2fARB(ARBMultitexture.GL_TEXTURE0_ARB, t2.x, t2.y);
    ARBMultitexture.glMultiTexCoord2fARB(ARBMultitexture.GL_TEXTURE1_ARB, t2.x, t2.y);
    glVertex3f(p2.x, p2.y, p2.z);
    glNormal3f(norm3.x, norm3.y, norm3.z);
    ARBMultitexture.glMultiTexCoord2fARB(ARBMultitexture.GL_TEXTURE0_ARB, t3.x, t3.y);
    ARBMultitexture.glMultiTexCoord2fARB(ARBMultitexture.GL_TEXTURE1_ARB, t3.x, t3.y);
    glVertex3f(p3.x, p3.y, p3.z);
glEnd();

Where t1, t2, t3, norm1, norm2, norm3, p1, p2, p3 are all instances of a 3D vector class I made (I just keep a 0 in the z component of t1, t2, and t3). The vertex and fragment shader source is exactly the same as in the aforementioned tutorial. All the code was working just fine with plain old textures. Any ideas on how I could make this work? Or possibly a better tutorial that is easy to follow when using LWJGL?

هل كانت مفيدة؟

المحلول

I strongly recommend you to learn from these tutorials how to use modern OpenGL with LWJGL .?If you take a look at the examples in afore mentioned link you will find your ways.I don't know how it works in fixed pipeline but using modern one it's just a matter of plugging several textures into texture targets in fragment shaders and sample those blending texels as you wish.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top