Vertex transparency for textured quads

BlitzMax Forums/OpenGL Module/Vertex transparency for textured quads

Bagels(Posted 2007) [#1]
I'm a bit new to OpenGL, so please bear with me. I'm trying to create a smooth transition from one texture to another on a simple heightmapped terrain. To do this, I'm currently rendering the baseline texture (a simple sand texture) and then trying to blend the second texture in over the top of it with varying alpha values at the four vertices on the edge. Unfortunately, I can't seem to make the glColor() function's alpha values do much of anything on anything but unlit, untextured polygons. Any way to get this working?

The code I've got currently looks like so:

		Alpha1 = Clamp(TerrainMap[x, y].Height + 3.5, 0.0, 1.0)
		Alpha2 = Clamp(TerrainMap[x + 1, y].Height + 3.5, 0.0, 1.0)
		Alpha3 = Clamp(TerrainMap[x + 1, y + 1].Height + 3.5, 0.0, 1.0)
		Alpha4 = Clamp(TerrainMap[x, y + 1].Height + 3.5, 0.0, 1.0)

glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_BLEND)
		glEnable(GL_BLEND)
		glBegin(GL_QUADS)
		
		glTexCoord2f(0.0, 0.0);
		glColor4f(0.0, 0.0, 0.0, Alpha1)
		glVertex3f(x, y, TerrainMap[x, y].height)
		glTexCoord2f(1.0, 0.0);
		glColor4f(0.0, 0.0, 0.0, Alpha2)
		glVertex3f(x + 1, y, TerrainMap[x + 1, y].height)
		glTexCoord2f(1.0, 1.0);
		glColor4f(1.0, 1.0, 1.0, Alpha3)
		glVertex3f(x + 1, y + 1, TerrainMap[x + 1, y + 1].height)
		glTexCoord2f(0.0, 1.0);
		glColor4f(0.0, 0.0, 0.0, Alpha4)
		glVertex3f(x, y + 1, TerrainMap[x, y + 1].height)
		glEnd()


Doesn't do much, presently. Anything I can do to make this work? Are there any possible alternative methods?

EDIT: Looks like I should probably handle this through multitexturing... not yet quite sure how to code it so that it blends the two textures according to the alpha values I've got calculated above, though.


Bagels(Posted 2007) [#2]
The method shown here:

http://lists.apple.com/archives/Mac-opengl/2003/Jan/msg00089.html

looks like it ought to work. Still doesn't quite do it, though.

Guess I'll sleep on it.

EDIT: Couldn't sleep. Finally worked it out - I was missing this line:

glEnable ( GL_COLOR_MATERIAL ) ;


ImaginaryHuman(Posted 2007) [#3]
Not sure that you'd need color material. But maybe you are missing glShadeModel(GL_SMOOTH) so that the values are interpolated across the polygon.