PDA

View Full Version : Change Color problem



glararan
12-16-2011, 11:17 AM
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.

The Little Body
12-16-2011, 06:53 PM
Why this CredColor == NULL test ???

You cannot directly modify the values of C[Red,Green,Blue,Alpha]Color with a slider or something like this ???

glararan
12-17-2011, 01:05 AM
I can modify value of C[Red,Green,Blue,Alpha].

Why CRedColor == NULL test?
Easy.. Because when have NULL value or empty, RedColor load value from config or return 1.0f.

So now have CRedColor value 1.0f if config doesnt exists.

I can modify value of CRedColors, ...

But problem is: I havent coded some repainting or some like that.And i don't know how do it.

glararan
12-17-2011, 08:05 AM
revive

Again....I can modify value of CRedColor, CGReenColor, ...
But program it dont re-rendering

mobeen
12-17-2011, 09:05 AM
Are you forcing a repaint when the value changes? in glut, u call glutPostRedisplay() to force a repaint. I dont know which library you are using but i suppose there will be a repaint function you can call.

glararan
12-17-2011, 10:32 AM
boosts, glew32, sdl, glu32, opengl32 and advapi32

I don't using glut. So is any next alternative solution?

mobeen
12-17-2011, 11:10 AM
SDL has SDL_UpdateRect function to force repaint see the SDL reference for details.

glararan
12-17-2011, 11:50 AM
glu.h or gl.h haven't? I'm not great coder in SDL :p

glararan
12-18-2011, 02:29 AM
revive