View Full Version : glutsolidsphere transparency
jacksmash
02-27-2009, 10:41 AM
Is it possible to make a glutSolidSphere transparent? I've fooled around with GL_BLEND, etc., but have not had much luck.
dletozeun
02-27-2009, 03:02 PM
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);
jacksmash
02-28-2009, 05:22 AM
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(...);
dletozeun
02-28-2009, 07:53 AM
hmm, it is hard to say, screenshots and relevant code might be helpful.
jacksmash
03-02-2009, 08:21 AM
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.
jacksmash
03-02-2009, 10:33 AM
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?
jacksmash
03-02-2009, 10:38 AM
Ok, I think the problem was that I should have used the following:
glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
Powered by vBulletin® Version 4.2.0 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.