NeHe 08: works, but changing current color alpha has no effect on transarency

Well, the title pretty much sums it up: the code seems correct in my program but altering the alpha value of the current color does nothing toward setting transparency of the textures. Any ideas? Surely its something simple, but I’ve spent several hours and can’t find it.

Thanks,

Keith

Well if u spent hours debuging,then consider how many it would take any1 here without code :wink:

I didn’t post any code because I figured this was a common and known problem. It seemed like a bit much to just throw this up here, but I suppose it may be the only way to get the help needed. As mentioned, the two quads draw fine, and show transparency, but the transparency is not influenced by the values of GL_COLOR4f() as the tutorial describes. A possibly related problem is that some random texel from the bound texture is becoming the current color, so any text ends up that color as does any quad NOT textured. I had to remove a good deal of code for this to fit in the post, so many unrelated methods are simply missing and quite a bit of seemingly unrelated code was removed from inside of the methods that ARE shown. If it turns out that no answer is available from this, I will be happy to put the whole thing up.

Any help appreciated!

public class GL_Game_Core extends JFrame implements GLEventListener
{
public void init(GLAutoDrawable drawable)
{
// Get current GL and GLU
GL gl = drawable.getGL();

	// Create the GLUT object
	glut = new GLUT();
	glu  = new GLU();

	// Get TextureManager instance
	textureManager = TextureManager.getInstance(gl, glu);

	// Enable basic OpenGL functions
	gl.glEnable(GL.GL_LIGHTING);
	gl.glEnable(GL.GL_DEPTH_TEST);
	gl.glEnable(GL.GL_CULL_FACE);

	// Set state variables
	gl.glHint(GL.GL_PERSPECTIVE_CORRECTION_HINT, GL.GL_NICEST);
	gl.glClearColor(0.0f, 0.0f, 0.0f, 0.5f);
	gl.glClearDepth(1.0f);
	gl.glDepthFunc(GL.GL_LEQUAL);
	gl.glShadeModel(GL.GL_SMOOTH);
	gl.glCullFace(GL.GL_BACK);
}

public void display(GLAutoDrawable drawable)
{
	// Get current GL and GLU
	GL gl = drawable.getGL();

	// Clear drawing surface and the z buffer
	gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);

	// Clear the modelview matrix giving all transformations a fresh start
	gl.glMatrixMode(GL.GL_MODELVIEW);
	gl.glLoadIdentity();

	// Force all remaining operations through the pipeline.
	gl.glFlush();
}

private void initGameSpecificCode(GL gl, GLU glu)
{		
	// Create textures
	try
	{
		textureManager.createManagedTexture("translucentTexture",
		                                    "green.png",
		                                    GL.GL_TEXTURE_2D,
		                                    GL.GL_RGB,
		                                    GL.GL_RGB,
		                                    GL.GL_LINEAR,
		                                    GL.GL_LINEAR,
		                                    false,
		                                    true);
	}
	catch(IOException ioe)
	{	

	}
}

// Extending class places additional 3D drawing code here
private void draw3D(GL gl, GLU glu)
{	
	gl.glEnable(GL.GL_TEXTURE_2D);
	textureManager.bindTexture("translucentTexture");
	
	// Draw translucent objects
	gl.glEnable(GL.GL_BLEND);
	gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE);
	gl.glDepthMask(false);
	gl.glColor4f(1f, 1f, 1f, .8f);
	
	gl.glBegin(GL.GL_QUADS);
			
		gl.glNormal3f( 0f,  1f, 0f);
		gl.glTexCoord2f(0f, 1f); gl.glVertex3f(-1f,  1f, 1f);
		gl.glTexCoord2f(0f, 0f); gl.glVertex3f(-1f, -1f, 1f);
		gl.glTexCoord2f(1f, 0f); gl.glVertex3f( 1f, -1f, 1f);
		gl.glTexCoord2f(1f, 1f); gl.glVertex3f( 1f,  1f, 1f);
		
		
		gl.glNormal3f( 0f,  1f, 0f);
		gl.glTexCoord2f(0f, 1f); gl.glVertex3f(-1f,  1f, 2f);
		gl.glTexCoord2f(0f, 0f); gl.glVertex3f(-1f, -1f, 2f);
		gl.glTexCoord2f(1f, 0f); gl.glVertex3f( 1f, -1f, 2f);
		gl.glTexCoord2f(1f, 1f); gl.glVertex3f( 1f,  1f, 2f);
			
	gl.glEnd();
	
	gl.glDisable(GL.GL_TEXTURE_2D);
	gl.glDepthMask(true);
	gl.glDisable(GL.GL_BLEND);
}

}

Vertex colours have no effect if lighting is enabled, instead material colours are used instead. You can use colour material to have the vertex colours specify the material colours instead. IIRC you need something like:


glEnable(GL_COLOR_MATERIAL);
glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);

Thanks much Orangy Tang. This works perfectly now thanks to your suggestion and changing the blend func from the one on NeHe08 to the one shown here. I’m still getting the texel color becoming the polygon color though on untextured polys and text. My guess was that after the applied fix the color of those polys would have been light gray. Just for information sake, the only texture in the little demo is solid green with a black arrow for orientation, and the non-textured polygons are the same color green (sans the arrow of course). Again, thanks much for the good advice.

Keith

	// Draw translucent objects
	gl.glEnable(GL.GL_BLEND);
	gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
	gl.glEnable(GL.GL_COLOR_MATERIAL);
	gl.glColorMaterial(GL.GL_FRONT_AND_BACK, GL.GL_AMBIENT_AND_DIFFUSE);
	gl.glColor4f(1f, 1f, 1f, .9f);
	gl.glDepthMask(false);
	
	gl.glBegin(GL.GL_QUADS);