This is simple code for gridline.
There are 2 options that I will show here (I guess there are more options, for example with vector list or what's up your mind).
First, if you want similar distance for x and y (the distance from line to line will be similar to the height and width):
const float sizeL = 3.f;
const float grid = 1.f;
glPointSize(sizeL);
glBegin(GL_LINES);
for(float i=-10; i<10; i+=grid)
{
glVertex3f(-10.f, i, 0.f);
glVertex3f(10.f, i, 0.f);
glVertex3f(i, -10.f, 0.f);
glVertex3f(i, 10.f, 0.f);
}
glEnd();
Write
Second, if you want a different distance between x and y (the distance from line to line will be different, the height-distance will be diffrent from the width-distance).
const float sizeL = 3.f;
const float gridX = 1.f;
const float gridY = 1.f;
glPointSize(sizeL);
glBegin(GL_LINES);
for(float i=-10; i<10; i+=gridX)
{
glVertex2f(-10.f, i);
glVertex2f(10.f, i);
}
for(float i=-10; i<10; i+=gridY)
{
glVertex2f(-10.f, i);
glVertex2f(10.f, i);
}
glEnd();
You can change the numbers as you want.
I hope it helped someone.