Freeglut error: ERROR: there is no display callback registered for window 1 when the window is destroyed and a new window is created

I want to create an opengGL context using freeglut. First, I determine in what context, checking the supporting version, using glew and some other parameters. I know that to work it needs to work, it needs an opengl context. Therefore, I first create the context using glutCreateWindow, then check the supported version and then install the version required with glutInitContextVersion (), and destroy the previous window with glutDestroyWindow and recreate the new window with glutCreateWindow. I get this error Freeglut error: ERROR: The display callback is not registered for window 1 (I checked 1 - this is the ID for my previous window that I destroyed) . Below is my code

glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
glutInitWindowPosition(100, 100);
glutInitWindowSize(900, 600);

int winID = glutCreateWindow("Rotating Cube"); //winID is 1 here

glewExperimental = GL_TRUE;
glewInit();

//I decide the context on some other parameters also except the supported version reported by glew. 
//I have tested this with opengl 3.2 core profile as well. 
//This is not working even if I forcefully set the opengl version to 2.0
if (glewIsSupported("GL_VERSION_3_1"))
{
    glutInitContextVersion (3, 1);
    glutInitContextFlags (GLUT_FORWARD_COMPATIBLE);

    //glutInitContextVersion (3, 2);             
    //glutInitContextFlags (GLUT_CORE_PROFILE);
}
else if (glewIsSupported("GL_VERSION_2_0"))
{
    glutInitContextVersion (2, 0);
}

glutDestroyWindow(winID);
winID = glutCreateWindow("Rotating Cube"); //winID is 2 here

glutSetWindow(winID);

glutDisplayFunc(RenderScene);
glutIdleFunc(RenderScene);
glutReshapeFunc(ChangeSize);
glutKeyboardFunc(ProcessNormalKeys);
glutSpecialFunc(ProcessSpecialKeys);

glutMainLoop();

, , openGL glew. ( , ), . , glutMainLoop. ,

raashimoto destroy

if (g_winID>=0)
{
    glutDestroyWindow(g_winID);
    g_winID = -1;
}

destroy

ERROR:  No display callback registered for window 1

destroy

ERROR:  Function <glutSwapBuffers> called with no current window defined.

Display, , . -

, - , ? , - , . glutCloseFunc, , , , glutDestroyWindow

+4
1

, , FreeGLUT, , . , glutDestroyWindow() GLUT .

glutDestroyWindow() , , ( destroy). , - โ€‹โ€‹ glutDestroyWindow().

Windows . , . , , GLUT .

, , glutDestroyWindow() GLUT. , . , , .

+1

All Articles