Oh, and I'm not arguing that the OP's code is correct...
And that would be a good thing. But regardless of the actual efficiency it doesn't take a rocket scientist to figure out that it's not very efficient.
Shamino do me a favor and at least try this: I don't know GL so I'm taking some of your code hoping it works.
Code:
void DrawGrid(int cellsize,float left,float top,float right,float bottom)
{
if ((right-left)<=cellsize) return;
glVertex2d(left, top);
glVertex2d(right, top);
glVertex2d(right, top);
glVertex2d(right, bottom);
glVertex2d(right, bottom);
glVertex2d(left, bottom);
glVertex2d(left, bottom);
glVertex2d(left, top);
float midx=(left+right)*0.5f;
float midy=(top+bottom)*0.5f;
DrawGrid(cellsize,left,top,midx,midy);
DrawGrid(cellsize,midx,top,right,midy);
DrawGrid(cellsize,left,midy,midx,bottom);
DrawGrid(cellsize,midx,midy,right,bottom);
}
Put that in a render loop and in between your glBegin() and glEnd() function calls and see what happens. Just try it.
Code:
void Render(float timeDelta)
{
glBegin();
DrawGrid(GRID_CELLSIZE,0,0,GRID_WIDTH,GRID_HEIGHT);
glEnd();
}
Now just insert the correct values for cellsze, width, and height and watch. This function only works for grids starting at 0,0 - but you can modify it to create a grid anywhere on screen.
You can also stick these quads into a vertex buffer with some more code.
And I forgot about the multiplies you are incurring when you call glTranslatef() inside of your horrendous loops.