# How To Draw a straight line with variables

for example,In the following code, in the function “glVertex3f”, a constant between 1 and-1 is used to represent a point

``````glBegin(GL_LINES);
{
glColor3ub(255, 0, 0);
glVertex3f(-1,0,0);glVertex3f(1,0,0);
}
``````

But most of the time, we use ‘variables’ more often.
Suppose the width of the window is 450, and half of it is 225.
The parameter input range is between 0 and 225, and when we enter an integer according to this interval, I expect to get a proportional decimal value and use this decimal value to draw a straight line.

``````void DrawLine(GLint ix, GLint iy,GLint ia,GLint ib)
{
GLfloat width = 225;
GLfloat x, y, z;
GLfloat a, b, c;
x = (GLfloat)(ix / width);
y = (GLfloat)(iy / width);
z = 0.2;
a = (GLfloat)(ia / width);
b = (GLfloat)(ib / width);
c = 0.2;

glBegin(GL_LINES);
{
glColor3ub(255, 0, 0);
glVertex3f(x, y, z); glVertex3f(a, b, c);
}
glEnd();
}
``````

The above program doesn’t work at all. Please tell me what the problem is.

like in “I don’t see anything”?
Try change z-value to a negative value and see if that makes a difference.