# Grid Drawing

This topic is 5059 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Wow, im at a complete loss and pretty embarassed about it lol
void	DrawGrid(float Spacing, UINT Num, float R, float G, float B)
{
float TotalSize = Num * Spacing;
float hTotalSize = (1/2) * TotalSize;
float nhTotalSize = hTotalSize * -1.0f;

float Pos;
Pos = nhTotalSize;

glBegin(GL_LINES);
glColor3f(R, G, B);
for (UINT x = 0; x < Num; ++x)
{
glVertex3f(Pos, 0.0f, nhTotalSize);
glVertex3f(Pos, 0.0f, hTotalSize);
Pos += Spacing;
}
Pos = nhTotalSize;
for (UINT y = 0; y < Num; ++y)
{
glVertex3f(nhTotalSize, 0.0f, Pos);
glVertex3f(hTotalSize, 0.0f, Pos);
Pos += Spacing;
}
glEnd();
}


texturing is disabled, so is lighting, im passing to it 1.0f for the cellspacing and 10 for the count, and 0, 1, 0 for the color, and in fact, i draw a line right outside of this function and it works... so im just at a loss... probably something dumb, ive been a bit sleep deprived lately lol thanks a ton -Dan

##### Share on other sites
It would be more helpful if you actually specified what the error is with that, kinda hard to take a guess at what could be wrong. Knowing the error there are probably only a few lines to look at.

##### Share on other sites
One thing that rings alarm bells is the (1/2) in line 4 (integer math), which would give you 0, try:

float hTotalSize = 0.5 * TotalSize;

##### Share on other sites
lucid ion: AHH!!!!! evil integer division!!! hahah thanks, im sure thats it

[EDIT:] yep, that was the problem, thanks again, i knew itd be something braindead and easy :-D
-Dan

[Edited by - Ademan555 on January 6, 2005 8:49:01 PM]

1. 1
2. 2
Rutin
19
3. 3
4. 4
5. 5

• 9
• 9
• 9
• 14
• 12
• ### Forum Statistics

• Total Topics
633299
• Total Posts
3011259
• ### Who's Online (See full list)

There are no registered users currently online

×