Normally this would be something like:
glutAddMenuEntry("-", <opid>);
But it doesn't work. After looking it up on Google I couldn't find much information about this, maybe it's not possible using GLUT? I found a couple of examples like:
glutAddMenuEntry("-", 0);
or
glutAddMenuEntry("-", -1);
But neither worked...
#include <math.h>
#include <GL/glut.h>
#define WINDOW_WIDTH 640
#define WINDOW_HEIGHT 480
void changeSize(int w, int h) {
if(h == 0) h = 1;
float ratio = 1.0 * w / h;
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glViewport(0, 0, w, h);
gluPerspective(45.0f, ratio, 1.0f, 1000.0f);
glMatrixMode(GL_MODELVIEW);
}
void renderScene(void) {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
gluLookAt(
0.0, 0.0, 5.0,
0.0, 0.0, 0.0,
0.0f, 1.0f, 0.0f
);
glutWireTeapot(1.0);
glutSwapBuffers();
}
void processMenuEvents(int option) {
}
void main(int argc, char **argv) {
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
glutInitWindowPosition(
(glutGet(GLUT_SCREEN_WIDTH) - WINDOW_WIDTH) / 2,
(glutGet(GLUT_SCREEN_HEIGHT) - WINDOW_HEIGHT) / 2
);
glutInitWindowSize(WINDOW_WIDTH, WINDOW_HEIGHT);
glutCreateWindow("Camera Demo");
glutDisplayFunc(renderScene);
glutReshapeFunc(changeSize);
glutCreateMenu(processMenuEvents);
glutAddMenuEntry("OPTION 1", 1);
glutAddMenuEntry("-", -1);
glutAddMenuEntry("OPTION 2", 2);
glutAttachMenu(GLUT_RIGHT_BUTTON);
glEnable(GL_DEPTH_TEST);
glEnable(GL_CULL_FACE);
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glutMainLoop();
}
I don't see separator like Windows does for other items, instead I see the menu item label 开发者_如何学运维as a dash.
I just triple checked all my documentation of and about GLUT: GLUT does not support menu separators! The best you can do is use some string "----" or similar as separator and ignore selection of this menu entry.
精彩评论