glutsolidsphere transparency

Is it possible to make a glutSolidSphere transparent? I’ve fooled around with GL_BLEND, etc., but have not had much luck.

Everything can be transparent. Use something like this before drawing your sphere:


// enable blending.
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

// set color and alpha
// draw your sphere

// disable blending
glDisable(GL_BLEND);

Yes, I’ve tried exactly that, and it doesn’t seem to work. My drawing code is as follows:

glColor4f(red, blue, green, 0.5f);
glutSolidSphere(…);

hmm, it is hard to say, screenshots and relevant code might be helpful.

Ok, here is the code in my drawing function:


glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

glColor4f(0.0f, 0.0f, 1.0f, 0.5f);
glutSolidSphere(0.10, 50, 50);
	
glDisable(GL_BLEND);

And, here is my initialization code


glEnable(GL_DEPTH_TEST);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glColorMaterial(GL_FRONT_AND_BACK, GL_EMISSION);
glEnable(GL_COLOR_MATERIAL);
	
// set viewing projection
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
	
// compute aspect ratio
float aspect;
	
if (w<=h)
{
	aspect = (float)h / (float)w;
	glOrtho(-VIEW, VIEW, -VIEW*aspect, VIEW*aspect, -5.0, 5.0);
}
else
{
	aspect = (float)w / (float)h;
	glOrtho(-VIEW*aspect, VIEW*aspect, -VIEW, VIEW, -5.0, 5.0);
}
	
glClearColor(1.0, 1.0, 1.0, 0.0);
	
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

Hopefully this helps. I’m at a loss here.

Ok, so I’ve determined that my problem is likely due to the fact that I have lighting enabled as well. I’ll read up on how to have lighting and transparency at the same time… is it possible?

Ok, I think the problem was that I should have used the following:

glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);