Hi. I have problem. I try code change color by UI slider.
But when i have value of Color. It doesn’t update. I know I forget on some.
My code:
float CRedColor, CGreenColor, CBlueColor, CAlphaColor;
float RedColor()
{
if(CRedColor == NULL)
{
Log << "CRedColor is NULL" << std::endl;
if(!boost::filesystem::exists("NoggIt.conf"))
{
Log << "CRedColor is NULL + NoggIt.conf doesn't exists" << std::endl;
return 1.0f;
}
else
{
std::stringstream ss(ConfigFile("NoggIt.conf").read<float>("RedColor"));
Log << "CRedColor isn't NULL" << std::endl;
if(!ss)
{
Log << "CRedColor isn't NULL, but haven't mention about RedColor" << std::endl;
return 1.0f;
}
else
{
Log << "CRedColor isn't NULL and have mention about RedColor" << std::endl;
return ConfigFile("NoggIt.conf").read<float>("RedColor");
}
}
}
else
return CRedColor;
return 1.0f;
}
void LoadColor()
{
CRedColor = RedColor();
CGreenColor = GreenColor();
CBlueColor = BlueColor();
CAlphaColor = AlphaColor();
}
void renderDisk(float x1, float y1, float z1, float x2, float y2, float z2, float radius, int subdivisions, GLUquadricObj *quadric)
{
float vx = x2 - x1;
float vy = y2 - y1;
float vz = z2 - z1;
//handle the degenerate case of z1 == z2 with an approximation
if( vz == 0.0f )
vz = .0001f;
float v = sqrt( vx*vx + vy*vy + vz*vz );
float ax = 57.2957795f*acos( vz/v );
if(vz < 0.0f)
ax = -ax;
float rx = -vy * vz;
float ry = vx * vz;
LoadColor();
glPushMatrix();
glPushAttrib(GL_CURRENT_BIT);
//draw the quadric
glTranslatef(x1, y1, z1);
glRotatef(ax, rx, ry, 0.0f);
glRotatef(90.0f, 1.0f, 0.0f, 0.0f);
glColor4f(CRedColor, CGreenColor, CBlueColor, CAlphaColor);
gluQuadricOrientation(quadric, GLU_OUTSIDE);
gluDisk(quadric, radius - 0.25f, radius + 5.0f, subdivisions, 2);
//glColor4f(0.0f, 0.8f, 0.1f, 0.9f);
//gluDisk(quadric, (radius * 1.5) - 2, (radius * 1.5) + 2, 0, 1);
glPopAttrib();
glPopMatrix();
}
void renderDisk_convenient(float x, float y, float z, float radius, int subdivisions)
{
glDisable(GL_LIGHTING);
GLUquadricObj *quadric = gluNewQuadric();
gluQuadricDrawStyle(quadric, GLU_LINE);
gluQuadricNormals(quadric, GLU_SMOOTH);
renderDisk(x, y, z, x, y, z, radius, subdivisions, quadric);
gluDeleteQuadric(quadric);
glEnable(GL_LIGHTING);
}
I don’t give here code of GreenColor(), … it’s same.
How i work?
1)Check if float CRedColor have value, if not check if config exists, if yea load value from config, else return 1.0f, if CRedColor have value return RedColor;
2)float CRedColor = RedColor(); // its for get value from config or …
3)call LoadColor() in renderDisk
4)glColor4f(CRedColor, CGreenColor, CBlueColor, CAlphaColor);
5)I have now first color
6)Now User want change color of Disk so use Slider
7)User change Color, but he doesn’t see change.