PDA

View Full Version : Progress Bar



CLoNA
02-15-2003, 06:50 AM
Hi,

How can I create a progress bar effect you know those that have a rectangle and another rectangle moving inside.

Orzech
02-15-2003, 08:50 AM
Hello. Well, that's rather simple problem.
You would like to draw a progress bar - so
1. first draw the background rectangle (let's say in white color) :

glColor3f(1,1,1);

glBegin(GL_QUADS);
glVertex2f(x,y);
glVertex2f(x + width, y);
glVertex2f(x + width, y + height);
glVertex2f(x. y + height);
glEnd();

where x, y - are starting coordinates of bottom left corner

width, height - size of the bar

2. draw current progress rectangle
now we draw second rectangle showing percent of our progress

progress = value / max_value;

As you can see progress is from 0 to 1.
Width of our progress rectangle would be now = progress * width (of previous rectangle)

so we draw

glColor3f(0,0,1);

glBegin(GL_QUADS);
glVertex2f(x,y)
glVertex2f(x+progress*width, y)
glVertex2f(x+progress*width, y+height)
glVertex2f(x, y+height)
glEnd();

And that would be all. There are of course many ways of doing such bar. Probably you would like to add a percent counter etc... But that's isn't also any problem...