void mouse(int button, int state, int x, int y)
{
switch(button)
{
case GLUT_LEFT_BUTTON:
if(state == GLUT_DOWN)
{
if(current_pt == true)
{
lines[current_line].p1.x = x;
lines[current_line].p1.y = screenHeight - y;
current_pt = false;
}
else if(current_pt == false)
{
lines[current_line].p2.x = x;
lines[current_line].p2.y = screenHeight - y;
current_pt = true;
slope = (lines[0].p2.y - lines[0].p1.y)/(lines[0].p2.x - lines[0].p1.x);
}
else
{
cout << "I messed up somewhere." << endl;
}
cout << slope;
cout << "(" << lines[0].p1.x << ", " << lines[0].p1.y << ") to ("
<< lines[0].p2.x << ", " << lines[0].p2.y << ")" << endl; //debugging
glutPostRedisplay();
}
break;
case GLUT_RIGHT_BUTTON:
if(state == GLUT_DOWN)
{
glutPostRedisplay();
}
break;
default:
break;
}
}
What is going on with this code? (glut)
I'm trying to debug and make sure I correct values, and I'm doing it with regular print statements. However, depending on whether or not I have a print statement, my other print statements won't actually print until the program has stopped. Take a look at this relevant section of code
Near the end of the case block, see the cout << slope; followed by a two-line cout statement? If I comment out the two-line cout statement, slope won't print until I exit the program. Slope is a global variable that is initialized to 999, so if I click on my screen, say, 3 times, after I terminate the program the output will THEN show-up as 999999999. If I leave the function as it is (with the cout statement NOT commented out), it works. What could be the problem?
Also, I have another program where I do the same thing, and it's similar block works perfectly, which is why I'm perplexed as to why this isn't working.
And I know the code is a mess... I'll fix the actual code after I can fix my debugging stuff (that's the whole point!) :) Thanks
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement