当我尝试打开时,网格根本不显示

grid not showing at all when I try to on it

我正在尝试制作一个选项弹出菜单,以便能够选择是否要打开或关闭网格作为添加到我尝试制作的游戏中的选项。我已经能够显示弹出菜单,其中有两个选项称为“网格打开”和“网格关闭”,但是当我单击它时,网格根本没有显示给我,我正在努力做到这一点。

void myGrid(GLint i) {
glEnable(GL_LINE_STIPPLE); //Activates the line-style feature

glLineStipple(1, 0xAAAA);  // Plots a dashed polyline

glColor3f(0.8, 0.8, 0.8);

glBegin(GL_LINES);
for (i = 2; i <= 9; i++)
{
    glVertex3f(i * 0.1 * w, 0.0, 0.0);
    glVertex3f(i * 0.1 * w, 0.9 * h, 0.0);
}

for (i = 1; i <= 9; i++)
{
    glVertex3f(0.1 * w, i * 0.1 * h, 0.0);
    glVertex3f(w, i * 0.1 * h, 0.0);
}
glEnd();
glDisable(GL_LINE_STIPPLE);
}

int main(int argc, char* argv[])//standard c entry signature
{
//cout << "Player Controls:\n Up Key - move forward\n Down Key - move backward\n Left/Right key - move left or right\n R/r - rotate";
/* window management code ... */
/* initialises GLUT and processes any command line arguments */
glutInit(&argc, argv);
/* use double-buffered window and RGBA colour model */
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA);
/* window width = 400 pixels, height = 400 pixels */
glutInitWindowSize(500, 500);
/* window upper left corner at (100, 100) */
glutInitWindowPosition(100, 100);
/* creates an OpenGL window and set its title bar*/
glutCreateWindow("Coursework 1");
init();

glutDisplayFunc(display);

//glutKeyboardFunc(keyboard);
//glutSpecialFunc(specialKeys);
//  glutSpecialUpFunc(keyGoneUp);

glutReshapeFunc(reshape);

//Create a grid turning it on and off
glutCreateMenu(myGrid);

glutAddMenuEntry("Grid on", 1);
glutAddMenuEntry("Grid off", 2);
glutAttachMenu(GLUT_RIGHT_BUTTON);
//  SetupRC();
glutIdleFunc(IdleFunc);
glutMainLoop();

return 0;
}
  1. 在菜单回调中切换全局(或 window 特定,由您决定)布尔值
  2. 在菜单回调
  3. 中发出glutPostRedisplay()
  4. 使用全局布尔值draw/don不在显示回调中绘制网格