Archived

This topic is now archived and is closed to further replies.

The Bag

Mulipass texturing help

Recommended Posts

The Bag    114
I''ve spent hours hitting my head against this problem for hours & I''ve searched here & google - but I cannot seem to find a solution. I''m sure it''s something really obvious, but I''m stuck. I''m trying to multipass texture a piece of terrain, two passes at the moment, but my terrain is turning fully transparent. The code, at the moment the second texture is just blended at a single alpha value across the entire terrain. glPushMatrix(); glTranslatef(-0.5*TERR_WIDTH, 0, -0.5*TERR_DEPTH); glEnable(GL_BLEND); glEnable(GL_DEPTH_TEST); glBindTexture(GL_TEXTURE_2D, texture[0]); glBlendFunc(GL_ONE, GL_ONE); glBegin(GL_QUADS); z= TERR_DEPTH-1; while (z-- > 0) { x= TERR_WIDTH-1; while (x-- > 0) { glColor4f(1.0f, 1.0f , 1.0f, 0.0f); glTexCoord2f(0.0f, 0.0f); glNormal3fv((GLfloat*)&(pTB->n[x][z])); glVertex3f(x, pTB->h.s[x][z], z); glTexCoord2f(0.0f, 1.0f); glNormal3fv((GLfloat*)&(pTB->n[x][z+1])); glVertex3f(x, pTB->h.s[x][z+1], z+1); glTexCoord2f(1.0f, 1.0f); glNormal3fv((GLfloat*)&(pTB->n[x+1][z+1])); glVertex3f(x+1, pTB->h.s[x+1][z+1], z+1); glTexCoord2f(1.0f, 0.0f); glNormal3fv((GLfloat*)&(pTB->n[x+1][z])); glVertex3f(x+1, pTB->h.s[x+1][z], z); } } glEnd(); glDepthFunc(GL_LEQUAL); glTexCoord2f( (float)x / (float)TERR_WIDTH, - (float)z / (float)TERR_DEPTH ); glBindTexture(GL_TEXTURE_2D, texture[1]); glBlendFunc(GL_DST_COLOR, GL_ZERO); glBegin(GL_QUADS); z= TERR_DEPTH-1; while (z-- > 0) { x= TERR_WIDTH-1; while (x-- > 0) { glColor4f(1.0f, 1.0f , 1.0f, 0.8f/*alphaMap[x][z]*/); glTexCoord2f(0.0f, 0.0f); glNormal3fv((GLfloat*)&(pTB->n[x][z])); glVertex3f(x, pTB->h.s[x][z], z); glTexCoord2f(0.0f, 1.0f); glNormal3fv((GLfloat*)&(pTB->n[x][z+1])); glVertex3f(x, pTB->h.s[x][z+1], z+1); glTexCoord2f(1.0f, 1.0f); glNormal3fv((GLfloat*)&(pTB->n[x+1][z+1])); glVertex3f(x+1, pTB->h.s[x+1][z+1], z+1); glTexCoord2f(1.0f, 0.0f); glNormal3fv((GLfloat*)&(pTB->n[x+1][z])); glVertex3f(x+1, pTB->h.s[x+1][z], z); } } glEnd(); glPopMatrix(); Any ideas?

Share this post


Link to post
Share on other sites
cowsarenotevil    3002
I haven''t had time to look too closely at your code, but I''m assuming that you''re unintentionally blending both textures against the black background.


"Gay marriage will encourage people to be gay, in the same way that hanging around tall people will make you tall." - Grizwald

Share this post


Link to post
Share on other sites
rick_appleton    864
A quick reply. I''m not very versed in multi-texturing myself, but what Cowsarenotevil said seems to be right:

First pass:

glEnable(GL_BLEND);
glEnable(GL_DEPTH_TEST);
glBindTexture(GL_TEXTURE_2D, texture[0]);
glBlendFunc(GL_ONE, GL_ONE);


Second pass:

glBindTexture(GL_TEXTURE_2D, texture[1]);
glBlendFunc(GL_DST_COLOR, GL_ZERO);


What you''re doing here is blending the first pass 50-50 against the background.
The second pass I''m not sure about, but it''s definately a wrong blendmode.

Try disabling the blend before the first pass, and enabling it before the second pass.

Share this post


Link to post
Share on other sites
The Bag    114
Right, after playing with different blending params I''ve got it working:

First pass

glEnable(GL_BLEND);
glEnable(GL_DEPTH_TEST);
glBindTexture(GL_TEXTURE_2D, texture[0]);
glBlendFunc(GL_ONE, GL_ZERO);


Second Pass

glDepthFunc(GL_LEQUAL);
glBindTexture(GL_TEXTURE_2D, texture[1]);
glBlendFunc(GL_ONE_MINUS_SRC_ALPHA, GL_SRC_ALPHA);

Share this post


Link to post
Share on other sites
krez    443
i am no expert, but i believe:

(1) you have the second glBlendFunc() parameters swapped. it should be
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 


(2) you could just disable blending for the first pass, and enable it for the second. blending with (GL_ONE, GL_ZERO) is the same as no blending.

Share this post


Link to post
Share on other sites