i am writing an openGL program. my code is here:
GLint Steps = 4;
GLint RaysPerStep = 8;
void randcolor()
{
GLint a,b,c;
a = rand()%101;
b = rand()%101;
c = rand()%101;
X[0] = (GLfloat)a/100.0;
X[1] = (GLfloat)b/100.0;
X[2] = (GLfloat)c/100.0;
}
void colours(int id)
{
flag = id;
if (flag == 1)
randcolor();
glutPostRedisplay();
}
void flow(int id)
{
RaysPerStep = id;
glutPostRedisplay();
}
void level(int id)
{
Steps = id;
glutPostRedisplay();
}
int main(int argc, char **argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize(1324,750);
glutInitWindowPosition(0,0);
glutCreateWindow("Flowing Fountain");
glEnable(GL_DEPTH_TEST);
glClearColor(0,0,100,1.0);
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_LINE_SMOOTH);
glEnable(GL_BLEND);
glLineWidth(2.0);
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
InitFountain();
CreateList();
glutDisplayFunc(Dis);
glutReshapeFunc(Reshape);
glutKeyboardFunc(NormalKey);
int sub_menu = glutCreateMenu(colours);
glutAddMenuEntry("RANDOM",1);
glutAddMenuEntry("GREEN",2);
glutAddMenuEntry("BLUE",3);
int sub_menu2 = glutCreateMenu(flow);
glutAddMenuEntry("LOW",8);
glutAddMenuEntry("MEDIUM",10);
glutAddMenuEntry("HIGH",20);
int sub_menu3 = glutCreateMenu(level);
glutAddMenuEntry("3 LEVELS",3);
glutAddMenuEntry("4 LEVELS",4);
glutAddMenuEntry("5 LEVELS",5);
}
there is no problem when the first and second menus are running. but as soon as i add the third menu, i get the error
"Unhandled exception at 0x10031fa6 in openGL2.exe: 0xC0000005: Access violation writing location 0x00000140" in "glut_std.h"
file once defining "glutCreateMenu":
"static int FGAPIENTRY FGUNUSED glutCreateMenu_ATEXIT_HACK(void (* func)(int)) {
return __glutCreateMenuWithExit(func, exit); }".
how can i fix it? (if i can reduce the code, there is no problem. So i have to give all codes.)